小编Son*_*hra的帖子

如何在shell中重复破折号(连字符)

如何-在shell中重复n次?我已阅读并试过这个,但这不起作用-.它抛出错误invalid option.以下是我使用的确切命令:

printf '-%.0s' {1..100}
Run Code Online (Sandbox Code Playgroud)

原贴线: printf '-%0.s' {1..100}

我也试过逃避-,\但在这种情况下,它重复\-n次.

linux bash shell repeat

12
推荐指数
2
解决办法
3461
查看次数

抛出ERROR TypeError:无法读取未定义的属性'emit'

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)

event-handling youtube-api emit typescript angular

9
推荐指数
1
解决办法
2万
查看次数

去掉R中图形图中的顶点标签

我正在开展一个小项目,涉及查找图表的社区结构和绘图.我正在使用label.propagation.community算法进行社区检测,并使用以下代码行进行绘图:

plot(community_1, graph_1)
Run Code Online (Sandbox Code Playgroud)

它正如预期的那样工作,给出了以下情节.在此输入图像描述.

问题是图表显示了使得图表看起来更拥挤的顶点标签.有什么办法可以摆脱剧情中的这些标签吗?我不想修改图表和社区中的任何内容; 只是想告诉情节不要打印标签.

plot r igraph

8
推荐指数
1
解决办法
6983
查看次数

如何在 bash 中的 pgrep 中指定命令行参数?

我有几个进程使用相同的名称但不同的命令行参数运行。

$ 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)

bash shell grep process

5
推荐指数
1
解决办法
2825
查看次数

TightVNC 中带有十字光标的灰色屏幕

我正在尝试从 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)

vnc-server tightvnc

5
推荐指数
0
解决办法
3664
查看次数

在C++中检查相等性的两种方式的差异是i == 0 vs 0 == i

我正在使用C++中的庞大代码库.作者使用0==i语法来检查相等性.我已经用C++编写了很多年了; 我一直使用i==0语法.

前者比后者有什么优势吗?或者只是个人偏好?

c++

4
推荐指数
2
解决办法
161
查看次数

减少ggplot2图例中的填充

我试图使用ggplot2获取图表.问题是我无法减少图例边框和文本之间的空白区域.例如:样本传奇,

在这里,我想减少顶部的空白,我用一些卷曲的线条标记.

我搜索了很多,但在大多数地方,答案建议减少key.heightkey.width,但这不是我想要的; 我很满意.我只是想摆脱顶部的空白区域.

r ggplot2

4
推荐指数
2
解决办法
2471
查看次数

为 R 中的变量值设置上限

如何为 R 中的变量设置上限?

假设我有一个包含“a”和“b”列的 data.frame。“b”的值范围为 1:100。我想让所有大于 50 的值都等于 50。

我可以编写一个循环并完成此任务,但我需要一个函数。

r

2
推荐指数
1
解决办法
1万
查看次数

在shell脚本中获取进程的返回值

我有一个 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)

有什么方法可以访问脚本的返回值吗?

bash shell

2
推荐指数
1
解决办法
2948
查看次数

在同一个循环中集成 pthread_create() 和 pthread_join()

我是多线程编程的新手,我正在学习本教程。在本教程中,有一个简单的示例展示了如何使用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)

c++ multithreading posix pthreads pthread-join

1
推荐指数
1
解决办法
3329
查看次数