如何-
在shell中重复n次?我已阅读并试过这个,但这不起作用-
.它抛出错误invalid option
.以下是我使用的确切命令:
printf '-%.0s' {1..100}
Run Code Online (Sandbox Code Playgroud)
原贴线: printf '-%0.s' {1..100}
我也试过逃避-
,\
但在这种情况下,它重复\-
n次.
在MyComponent
,我试图从事件处理程序发出另一个事件.(父组件将使用此新事件执行一些操作).我创建了一个事件发射器作为其成员MyComponent
,但事件处理程序方法无法访问事件发射器.它抛出ERROR TypeError: Cannot read property 'emit' of undefined
.我在StackOverflow上发现了一些相关的问题,但由于是新手而无法理解Angular2
.
import { Component, Input, Output, OnChanges, SimpleChanges, OnInit, EventEmitter } from '@angular/core';
import YouTubePlayer from 'youtube-player';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnChanges, OnInit {
@Input()
videoURL = '';
player : any;
videoId : any;
@Output()
myEmitter: EventEmitter<number> = new EventEmitter();
ngOnInit(): void {
this.player = YouTubePlayer('video-player', {
videoId: this.videoId,
width: "100%"
});
this.registerEvents();
}
private registerEvents() { …
Run Code Online (Sandbox Code Playgroud) 我正在开展一个小项目,涉及查找图表的社区结构和绘图.我正在使用label.propagation.community算法进行社区检测,并使用以下代码行进行绘图:
plot(community_1, graph_1)
Run Code Online (Sandbox Code Playgroud)
问题是图表显示了使得图表看起来更拥挤的顶点标签.有什么办法可以摆脱剧情中的这些标签吗?我不想修改图表和社区中的任何内容; 只是想告诉情节不要打印标签.
我有几个进程使用相同的名称但不同的命令行参数运行。
$ ps -ef | grep process_name
myusername 19276 6408 0 18:12 pts/22 00.00.00 process_name 4010 127.0.0.1
myusername 23242 6369 0 18:32 pts/11 00.00.00 process_name 4010 127.0.0.2
Run Code Online (Sandbox Code Playgroud)
如何根据进程的全名获取进程 ID,例如process_name 4010 127.0.0.1
?
我尝试使用pgrep
,但看起来这并没有考虑参数。
$ pid=$(pgrep process_name)
19276 23242
$ pid=$(pgrep process_name 4010 127.0.0.1) #error
$ pid=$(pgrep "process_name 4010 127.0.0.1") #blank
$ pid=$(pgrep "process_name\s4010\s127.0.0.1") #blank
$ pid=$(pgrep "process_name[[:space:]]4010[[:space:]]127.0.0.1") #blank
Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Windows 10 VNC 到 Ununtu 16.04。我得到一个带十字光标的带纹理的灰色屏幕。
下面是我的日志文件:
Xvnc Free Edition 4.1.1 - built Feb 25 2015 23:02:21
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Underlying X server release 40300000, The XFree86 Project, Inc
Wed Aug 17 14:42:46 2016
vncext: VNC extension running!
vncext: Listening for VNC connections on port 5902
vncext: created VNC server for screen 0
error opening security policy file /etc/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not …
Run Code Online (Sandbox Code Playgroud) 我正在使用C++中的庞大代码库.作者使用0==i
语法来检查相等性.我已经用C++编写了很多年了; 我一直使用i==0
语法.
前者比后者有什么优势吗?或者只是个人偏好?
如何为 R 中的变量设置上限?
假设我有一个包含“a”和“b”列的 data.frame。“b”的值范围为 1:100。我想让所有大于 50 的值都等于 50。
我可以编写一个循环并完成此任务,但我需要一个函数。
我有一个 C 程序,比如说hello_world
。main 函数返回一个int
. 我可以在 shell 脚本中访问和使用这个返回值吗?
这是C代码。我编写了一个非常简化的程序版本。实际代码是 1.2K 行。
/*hello_world.c*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i = 0;
if (argc == 2) {
i = atoi(argv[1]);
printf("Hello World - %d\n", i);
return 0;
}
else return -1;
}
Run Code Online (Sandbox Code Playgroud)
这是运行上述代码编译后生成的可执行文件的bash脚本。我正在使用 GCC 4.1.2 并使用编译gcc -o hello_world hello_world.c
#!/bin/bash
ret=hello_world 31 # this gives a `command not found` error
if [ ret -eq 0 ]; then
echo "success"
fi
Run Code Online (Sandbox Code Playgroud)
有什么方法可以访问脚本的返回值吗?
我是多线程编程的新手,我正在学习本教程。在本教程中,有一个简单的示例展示了如何使用pthread_create()
和pthread_join()
。我的问题:为什么我们不能放入pthread_join()
与 相同的循环中pthread_create()
?
参考代码:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NUM_THREADS 2
/* create thread argument struct for thr_func() */
typedef struct _thread_data_t {
int tid;
double stuff;
} thread_data_t;
/* thread function */
void *thr_func(void *arg) {
thread_data_t *data = (thread_data_t *)arg;
printf("hello from thr_func, thread id: %d\n", data->tid);
pthread_exit(NULL);
}
int main(int argc, char **argv) {
pthread_t thr[NUM_THREADS];
int i, rc;
/* create a thread_data_t argument …
Run Code Online (Sandbox Code Playgroud) bash ×3
r ×3
shell ×3
c++ ×2
angular ×1
emit ×1
ggplot2 ×1
grep ×1
igraph ×1
linux ×1
plot ×1
posix ×1
process ×1
pthread-join ×1
pthreads ×1
repeat ×1
tightvnc ×1
typescript ×1
vnc-server ×1
youtube-api ×1