小编Lon*_*ner的帖子

如何避免手动滚动Vim脚本的长输出以自动执行脚本?

我想从http://www.vim.org/scripts/script.php?script_id=4582自动安装Conque GDB .

所以我写了这两个命令.

wget "http://www.vim.org/scripts/download_script.php?src_id=22163" -O conque_gdb.vmb
vim +"so % | q" conque_gdb.vmb
Run Code Online (Sandbox Code Playgroud)

第一个命令下载conbque_gdb.vmb.第二个命令执行作者在上面的链接中推荐的两个命令,即执行:so %:q.

但是,有一个问题.由于执行so %导致的输出很大,它导致Vim窗口显示一个巨大的输出,-- More --最后我必须通过按Enter键滚动,然后Vim才能执行q命令并退出.

"conque_gdb.vmb" 8489L, 292519C
Vimball Archive
extracted <autoload/conque_gdb.vim>: 561 lines
wrote /root/.vim/autoload/conque_gdb.vim
extracted <autoload/conque_term.vim>: 1674 lines
wrote /root/.vim/autoload/conque_term.vim
extracted <autoload/conque_gdb/conque_gdb.py>: 294 lines
wrote /root/.vim/autoload/conque_gdb/conque_gdb.py
extracted <autoload/conque_gdb/conque_gdb_gdb.py>: 17 lines
wrote /root/.vim/autoload/conque_gdb/conque_gdb_gdb.py
extracted <autoload/conque_gdb/conque_sole_gdb.py>: 82 lines
wrote /root/.vim/autoload/conque_gdb/conque_sole_gdb.py
extracted <autoload/conque_gdb/gdbinit_confirm.gdb>: 24 lines
wrote /root/.vim/autoload/conque_gdb/gdbinit_confirm.gdb
extracted <autoload/conque_gdb/gdbinit_no_confirm.gdb>: 20 lines
wrote /root/.vim/autoload/conque_gdb/gdbinit_no_confirm.gdb
extracted …
Run Code Online (Sandbox Code Playgroud)

vim shell

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

为什么使用gnu90和c90标准编译时strerror_r的行为会有所不同?

这是我的计划.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
        char errbuf[256];

        errno = 0;
        strtoul("99999999999999999999999999999999999999999999", NULL, 0);
        strerror_r(errno, errbuf, sizeof errbuf);
        printf("strerror_r: %s\n", errbuf);

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

当我用-std=gnu90or 编译它时-std=gnu99,我得到了预期的输出.

susam@nifty:~/lab/linux$ rm -f a.out && gcc -std=gnu90 -Wall -Wextra -pedantic foo.c && ./a.out 
strerror_r: Numerical result out of range
susam@nifty:~/lab/linux$ rm -f a.out && gcc -std=gnu99 -Wall -Wextra -pedantic foo.c && ./a.out 
strerror_r: Numerical result out of range
Run Code Online (Sandbox Code Playgroud)

但是当我用-std=c90or 编译它时-std=c99,我得到一个警告,我没有看到 …

c gcc gnu c89

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

即使`this`是'undefined`,如何在严格模式下的函数中定义`alert`?

我认为我们可以使用alert('foo')而不是window.alert('foo')因为在浏览器上下文中,this = window默认情况下,所以alert('foo')会自动表示this.alert('foo')哪个等价window.alert('foo').

所以,我没想到的alert功能,在一个函数中定义严格模式,因为当启用了严格模式,thisundefined在功能.

这是代表我的困惑的代码.

function foo() {
  console.log('----- foo -----')
  console.log('this: ' + this);
  console.log('window: ' + window);
  console.log('alert: ' + alert)
  console.log('window.alert: ' + window.alert)
  console.log('this.alert: ' + this.alert)
}

function bar() {
  'use strict'
  console.log('----- bar -----')
  console.log('this: ' + this); // this is undefined
  console.log('window: ' + window);
  console.log('alert: ' + alert) // how is alert defined when …
Run Code Online (Sandbox Code Playgroud)

html javascript

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

如何在定义列的同一行中定义外键?

我正在学习使用Oracle 12.1.

下面的外键定义有什么问题?

set echo on
drop table city;
drop table emp;

create table city (
    id number primary key,
    name varchar2(20)
);

create table emp (
    id number,
    cityid number foreign key references city(id)
);
Run Code Online (Sandbox Code Playgroud)

当我执行它时,我收到以下错误.

$ sqlplus / as sysdba @foo.sql
...
...
SQL>
SQL> create table city (
  2      id number primary key,
  3      name varchar2(20)
  4  );

Table created.

SQL>
SQL> create table emp (
  2      id number,
  3      cityid number foreign key references city(id)
  4 …
Run Code Online (Sandbox Code Playgroud)

sql oracle syntax foreign-keys oracle12c

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

为什么浏览器不遵循呈现的 GitHub README.md 上图像资源的 HTTP 302 重定向?

这个问题似乎是关于 GitHub 的,但实际上是关于 HTTP 和浏览器的。不幸的是,我只能用 GitHub 重现这个问题,所以我没有比我在下面提供的例子更简单的例子。

该问题可以通过访问https://github.com/lonelearner/img-load-issue来观察。未在呈现的自述文件中加载的图像是问题所在。

这是 README.md 中的 Markdown 代码。

Foo

<img src="https://github.com/lonelearner/img-load-issue/releases/download/v1.0.0/ulam.png" alt="Image of Ulam spiral">

Bar
Run Code Online (Sandbox Code Playgroud)

当我在浏览器 (Firefox) 上单击查看源代码时,我看到上面的降价已呈现为以下 HTML 代码。

<article class="markdown-body entry-content" itemprop="text">
<p>Foo</p>
<p><a href="https://github.com/lonelearner/img-load-issue/releases/download/v1.0.0/ulam.png" target="_blank"><img src="https://github.com/lonelearner/img-load-issue/releases/download/v1.0.0/ulam.png" alt="Image of Ulam spiral" style="max-width:100%;"></a></p>
<p>Bar</p>
</article>
Run Code Online (Sandbox Code Playgroud)

您可以通过转到https://github.com/lonelearner/img-load-issue/releases并单击ulam.png来验证图像是否确实存在。生成的 HTML 代码看起来也不错。为什么浏览器无法加载图像呢?

如果我在 jsfiddle 中插入相同的 HTML 代码,图像似乎加载正常。示例:https : //jsfiddle.net/qxybjwf1/

为什么这个图像在 jsfiddle.net 上加载得很好,但在 GitHub 上?

我在 Firefox 检查器的网络选项卡中检查了请求和响应标头。对 ulam.png 的 GET 请求返回

302 Found
Location: https://github-cloud.s3.amazonaws.com/releases/64644360/7e448240-57e5-11e6-8bda-58e154461718.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20160801%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20160801T072537Z&X-Amz-Expires=300&X-Amz-Signature=fb0e8423517a09b80624b3512f8ebeffc54cfb976e409379c532b4625b179095&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dulam.png&response-content-type=application%2Foctet-stream
Run Code Online (Sandbox Code Playgroud)

在网络选项卡中,我没有看到 Firefox 发出另一个请求来检索 amazonaws.com URL。为什么? …

browser http github http-status-code-302

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

为什么gcc不会抱怨htons()但是在使用-std = c99编译时抱怨getaddrinfo()?

即使编译时,以下程序编译并运行正常-std=c99.

#include <stdio.h>
#include <arpa/inet.h>

int main()
{
    printf("%d\n", htons(1));
}
Run Code Online (Sandbox Code Playgroud)

这是输出.

$ gcc -std=c99 foo.c && ./a.out
256
Run Code Online (Sandbox Code Playgroud)

但是以下程序会导致警告和错误.

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main()
{
    struct addrinfo *res;
    getaddrinfo("localhost", NULL, NULL, &res);
    printf("%d\n", res->ai_flags);
}
Run Code Online (Sandbox Code Playgroud)

这是警告和错误.

$ gcc -std=c99 bar.c
bar.c: In function ‘main’:
bar.c:9:5: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]
     getaddrinfo("localhost", NULL, NULL, &res);
     ^
bar.c:10:23: error: dereferencing pointer to incomplete type
     printf("%d\n", res->ai_flags);
Run Code Online (Sandbox Code Playgroud)

为什么编译器不会抱怨htons()但是getaddrinfo()在编译时会抱怨-std=c99 …

c posix c99

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

为什么getaddrinfo为HTTP返回端口号20480?

这是我的代码.

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main()
{
    struct addrinfo *ai, *p;

    if (getaddrinfo("localhost", "http", NULL, &ai) != 0) {
        printf("error\n");
        return EXIT_FAILURE;
    }

    for (p = ai; p != NULL; p = p->ai_next)
    {
        if (p->ai_family == AF_INET) {
            struct sockaddr_in *addr = (struct sockaddr_in *) p->ai_addr;
            printf("IPv4 port: %d\n", addr->sin_port);
        } else if (p->ai_family == AF_INET6) {
            struct sockaddr_in6 *addr = (struct sockaddr_in6 *) p->ai_addr;
            printf("IPv6 port: %d\n", addr->sin6_port);
        } …
Run Code Online (Sandbox Code Playgroud)

c sockets

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

类型断言后如何使用指针接收器调用方法?

我正在学习带有指针接收器的接口、类型转换和方法。指针接收器方法背后的规则和术语让我感到困惑。让我用一个程序来证明我的困惑。

这是我的围棋程序。

package main

import "fmt"

type Employee struct {
    Name string
}

func (e Employee) Hi() {
    fmt.Printf("Hi! I am %s.\n", e.Name)
}

func (e *Employee) Hello() {
    fmt.Printf("Hello! I am %s.\n", e.Name)
}

func main() {
    var a Employee = Employee{"Alice"}
    a.Hi()
    a.Hello()

    var b interface{} = Employee{"Bob"}
    b.(Employee).Hi()
    // b.(Employee).Hello()
}
Run Code Online (Sandbox Code Playgroud)

这是输出。

Hi! I am Alice.
Hello! I am Alice.
Hi! I am Bob.
Run Code Online (Sandbox Code Playgroud)

如果删除最后注释掉的行,则会出现此错误。

# command-line-arguments
./foo.go:24: cannot call pointer method on b.(Employee)
./foo.go:24: cannot take …
Run Code Online (Sandbox Code Playgroud)

pointers interface type-conversion go

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

为什么带有 0 超时或 10 秒超时的 SO_LINGER 选项不会立即或在 10 秒后删除套接字?

我已阅读何时需要 TCP 选项 SO_LINGER (0)?以及其他几个相关的问题和答案,但我无法重现SO_LINGER这些帖子中解释的任何行为。我将在这里分享我的众多实验之一。

我正在以下环境中执行此实验。

$ lsb_release -d
Description:    Debian GNU/Linux 9.0 (stretch)
$ gcc -dumpversion
6.3.0
Run Code Online (Sandbox Code Playgroud)

这是一个行为不端的客户端连接到服务器,但在 90 秒内未收到任何数据的示例。

/* client.c */
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>

int main()
{
    int sockfd;
    int ret;
    struct addrinfo hints, *ai;
    char buffer[256];
    ssize_t bytes;

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;

    if ((ret = getaddrinfo(NULL, "8000", &hints, &ai)) == -1) {
        fprintf(stderr, "client: getaddrinfo: %s\n", gai_strerror(ret)); …
Run Code Online (Sandbox Code Playgroud)

c sockets networking network-programming so-linger

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

C++错误:调用'print_size'没有匹配函数

我有这个代码:

#include <iostream>
#include <vector>

template<typename T>
void print_size(std::vector<T> a)
{
    std::cout << a.size() << '\n';
}

int main()
{
    std::vector<int> v {1, 2, 3};
    print_size(v);

    auto w = {1, 2, 3};
    // print_size(w); // error: no matching function for call to 'print_size'
                      // candidate template ignored: could not match 'vector' against 'initializer_list'
}
Run Code Online (Sandbox Code Playgroud)

...编译和运行没有任何问题.但是,如果我启用注释掉的行,则会产生错误no matching function for call to 'print_size'.

我想知道在C++ 11及更高版本中编写此代码的正确方法是什么.

c++ initializer-list auto c++11

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