小编I'm*_*gon的帖子

寻找一种简单的方法来复制上面的单词并将其粘贴到 Vim 中的当前光标位置

我想知道是否有命令可以直接复制光标上方的字符或单词并将其粘贴到当前位置?

例子:

sig1   : in   std_logic;
sig2   : in   std_logic;
sig3   : ^
Run Code Online (Sandbox Code Playgroud)

考虑上面的情况,我的光标在^位置,我想复制in std_logic;并粘贴到当前位置。我所知道的一种可行的方法是:

1. Move cursor up
2. Go into visual mode and highlight
3. Yank
4. Move cursor down
5. Paste
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法来做到这一点?或者我只能选择在 vimrc 中编写一个映射来为我执行整个序列?

编辑:我在互联网上找到了一个映射:

imap <F1> @<Esc>kyWjPA<BS>
nmap <F1> @<Esc>kyWjPA<BS>
imap <F2> @<Esc>kvyjPA<BS>
nmap <F2> @<Esc>kvyjPA<BS>
Run Code Online (Sandbox Code Playgroud)

但似乎格雷格的解决方案更容易!

vim

6
推荐指数
2
解决办法
667
查看次数

在Typescript中实现没有名称的函数

我正在尝试实现一个没有这样名字的函数:

interface I {
    (name: string): void;    
}

class C implements I {
    (name: string):void { }
}
Run Code Online (Sandbox Code Playgroud)

我想像这样使用C,但它不起作用:

C("test");
Run Code Online (Sandbox Code Playgroud)

我可以用javascript编写它并使用接口声明:I("test");

但我想在Typescript中做同样的事情.

typescript typescript1.5

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

即使是匹配的数据结构,也会解组json错误

我开始使用Google go语言,我正在尝试编写一个简单的程序,从Facebook的图形API中获取Json对象并解组它.

根据文档http://golang.org/doc/articles/json_and_go.html,我应该提供匹配的数据结构,例如,如果json对象是:

{
    Name: "Alice"
    Body: "Hello",
    Time: 1294706395881547000,
}
Run Code Online (Sandbox Code Playgroud)

数据结构如下所示:

type Message struct {
    Name string
    Body string
    Time int64
}
Run Code Online (Sandbox Code Playgroud)

就我而言,我的json看起来像这样:

{
  "id": "350685531728",
   "name": "Facebook for Android",
   "description": "Keep up with friends, wherever you are.",
   "category": "Utilities",
   "subcategory": "Communication",
   "link": "http://www.facebook.com/apps/application.php?id=350685531728",
   "namespace": "fbandroid",
   "icon_url": "http://static.ak.fbcdn.net/rsrc.php/v2/yo/r/OKB7Z2hkREe.png",
   "logo_url": "http://photos-b.ak.fbcdn.net/photos-ak-snc7/v43/207/227200684078827/app_115_227200684078827_474764570.png",
   "company": "Facebook"
}
Run Code Online (Sandbox Code Playgroud)

所以我提供了一个匹配的数据结构:

type Graph struct {
    id string
    name string
    description string
    category string
    subcategory string
    link string
    namespace string
    icon_url string
    logo_url string
    company …
Run Code Online (Sandbox Code Playgroud)

json go unmarshalling

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

为什么仅在添加cout线后输出无法显示变量的内容?

#include <iostream>

using namespace std;

class Marks
{
public:
    char* name();
};

char* Marks::name()
{
    char temp[30];
    cout<<"Enter a name:"<<endl;
    cin.getline(temp,30);
    return temp;
}

int main ()
{
    char *name;
    Marks test1;
    name=test1.name();

    //cout<<"name:"; //uncomment this line to see the problem
    cout<<name<<endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

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

当HEAD版本在该行没有内容时,为什么git会显示合并冲突

我正试图git merge master从另一个分支做一个,然后我遇到了这个冲突:

<<<<<<< HEAD
=======
    t.text     "label_en"
    t.text     "help_text_en"
    t.text     "options_en"
>>>>>>> master
Run Code Online (Sandbox Code Playgroud)

我知道如何解决冲突,但我很好奇为什么git首先认为这是冲突,因为HEAD版本在特定行上没有内容.

<<<<<<< HEAD
=======
Run Code Online (Sandbox Code Playgroud)

git只是从master中添加3行并合并它不是一个简单的例子吗?


更新:

@Marcin是对的.基于答案,我做了一个测试,假设我有一个如下所示的git树:

 A ---- B  (master)
      \
        C  (another branch)
Run Code Online (Sandbox Code Playgroud)

的内容temp.txtcommit A:

    t.text    "LALALA"
Run Code Online (Sandbox Code Playgroud)

的内容temp.txtcommit B:

    t.text    "label_en"
    t.text    "help_text_en"
    t.text    "options_en"
Run Code Online (Sandbox Code Playgroud)

temp.txtin的内容commit C是空的.


在这一点上,如果我这样做:

git checkout another_branch
git merge master
Run Code Online (Sandbox Code Playgroud)

然后我会得到以下内容:

<<<<<<< HEAD
=======
    t.text     "label_en"
    t.text     "help_text_en"
    t.text     "options_en"
>>>>>>> master
Run Code Online (Sandbox Code Playgroud)

git tree-conflict git-merge merge-conflict-resolution

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

额外的memset()导致系统调用open()失败

/dev按照这里的教程(chardev.c)创建了一个节点,我尝试/dev/chardev使用以下代码访问我创建的设备:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h> //perror(), errno
#include <string.h>
#define RSIZE 50 

int main()
{
    int fd,err_save;
    char receive_buff[RSIZE];

    //open device and check for error msg
    fd = open("/dev/chardev", "rw");
    err_save = errno;
    if (fd < 0)
        {
        perror("open perror");
        printf("error opening device, fd = %d, err_save = %d \n", fd,err_save);
        }
    else
        {printf("Device opened\n");}

    //read device and check for error msg
    //memset(receive_buff, 0, sizeof(receive_buff)); //<--- strange
    read(fd, …
Run Code Online (Sandbox Code Playgroud)

c linux kernel system-calls memset

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

在不同的线程rxJava上运行PublishSubject

我正在运行RxJava并创建一个使用onNext()方法来生成数据的主题.我正在使用Spring.

这是我的设置:

@Component
public class SubjectObserver {
    private SerializedSubject<SomeObj, SomeObj> safeSource;
    public SubjectObserver() {
       safeSource = PublishSubject.<SomeObj>create().toSerialized();
       **safeSource.subscribeOn(<my taskthreadExecutor>);**
       **safeSource.observeOn(<my taskthreadExecutor>);** 
       safeSource.subscribe(new Subscriber<AsyncRemoteRequest>() {
          @Override
          public void onNext(AsyncRemoteRequest asyncRemoteRequest) {
            LOGGER.debug("{} invoked.", Thread.currentThread().getName());
            doSomething();
          }
      }
    }
    public void publish(SomeObj myObj) {
        safeSource.onNext(myObj);
    }
}
Run Code Online (Sandbox Code Playgroud)

在RxJava流上生成新数据的方式是通过@Autowire private SubjectObserver subjectObserver 然后调用subjectObserver.publish(newDataObjGenerated)

无论我为subscribeOn()&指定什么observeOn():

  • Schedulers.io()
  • Schedulers.computation()
  • 我的主题
  • Schedulers.newThread

其中onNext()的实际工作是在实际调用onNext()主题以生成/生成数据的同一线程上完成的.

它是否正确?如果是这样,我错过了什么?我期待在doSomething()不同的线程上完成.

更新

在我的调用类中,如果我改变了调用publish方法的方式,那么当然会为订阅者分配一个新线程来运行.

taskExecutor.execute(() -> subjectObserver.publish(newlyGeneratedObj)); …
Run Code Online (Sandbox Code Playgroud)

spring subject-observer rx-java

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