小编Bit*_*nce的帖子

告知左侧故障管道的右侧?

我喜欢在shell脚本中的函数之间使用类似生成器的模式.像这样的东西:

parse_commands /da/cmd/file | process_commands
Run Code Online (Sandbox Code Playgroud)

但是,这种模式的基本问题是,如果parse_command遇到错误,我发现通知process_command失败的唯一方法是通过显式告知它(例如echo"FILE_NOT_FOUND").这意味着必须对parse_command中的每个可能的错误操作进行隔离.

难道没有办法使用非零退出代码检测左侧是否退出?

bash pipeline pipe

23
推荐指数
3
解决办法
7646
查看次数

如何让Flask /保持Ajax HTTP连接活着?

我有一个jQuery Ajax调用,如下所示:

    $("#tags").keyup(function(event) {
      $.ajax({url: "/terms",
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({"prefix": $("#tags").val() }),
        dataType: "json",
        success: function(response) { display_terms(response.terms); },
      });
Run Code Online (Sandbox Code Playgroud)

我有一个像这样的Flask方法:

@app.route("/terms", methods=["POST"])
def terms_by_prefix():
    req = flask.request.json
    tlist = terms.find_by_prefix(req["prefix"])
    return flask.jsonify({'terms': tlist})
Run Code Online (Sandbox Code Playgroud)

tcpdump显示HTTP对话框:

POST /terms HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://127.0.0.1:5000/
Content-Length: 27
Pragma: no-cache
Cache-Control: no-cache

{"prefix":"foo"}
Run Code Online (Sandbox Code Playgroud)

但是,Flask回复没有keep-alive.

HTTP/1.0 200 OK …
Run Code Online (Sandbox Code Playgroud)

ajax keep-alive werkzeug flask

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

多处理.Manager().dict().setdefault()坏了吗?

其后期和非常可能是愚蠢的部门提出:

>>> import multiprocessing
>>> mgr = multiprocessing.Manager()
>>> d = mgr.dict()
>>> d.setdefault('foo', []).append({'bar': 'baz'})
>>> print d.items()
[('foo', [])]         <-- Where did the dict go?
Run Code Online (Sandbox Code Playgroud)

鉴于:

>>> e = mgr.dict()
>>> e['foo'] = [{'bar': 'baz'}]
>>> print e.items()
[('foo', [{'bar': 'baz'}])]
Run Code Online (Sandbox Code Playgroud)

版:

>>> sys.version
'2.7.2+ (default, Jan 20 2012, 23:05:38) \n[GCC 4.6.2]'
Run Code Online (Sandbox Code Playgroud)

虫子还是玩意儿?

编辑:更多相同,在python 3.2:

>>> sys.version
'3.2.2rc1 (default, Aug 14 2011, 21:09:07) \n[GCC 4.6.1]'

>>> e['foo'] = [{'bar': 'baz'}]
>>> print(e.items())
[('foo', [{'bar': 'baz'}])]

>>> id(type(e['foo']))
137341152 …
Run Code Online (Sandbox Code Playgroud)

python multiprocessing

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

gdb不会从外部架构中读取核心文件

我正在尝试在我的Linux桌面上读取ARM核心文件,但似乎无法弄清楚我的核心文件.有什么方法可以指示gdb我的核心文件是什么类型的?

$ file ~/daemon
./daemon: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
$ file ~/core
./core: ELF 32-bit LSB core file ARM, version 1 (SYSV), SVR4-style, from './daemon -v -v -v -v -e 10 -t foo'
$ gdb-multiarch ~/daemon ~/core
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and …
Run Code Online (Sandbox Code Playgroud)

gdb arm core-file

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

Maven RPM插件中的可选映射部分?

我有一个Maven RPM插件映射:

<mapping>
  <directory>/etc/myconfig</directory>
  <configuration>true</configuration>
  <sources>
    <source>
      <location>${project.build.directory}</location>
      <includes>
        <include>*.conf</include>
      </includes>
    </source>
  </sources>
</mapping>
Run Code Online (Sandbox Code Playgroud)

但是,根据打包过程,可能会有零.conf文件放入/ etc.发生这种情况时,RPM插件会说:

[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.2:rpm (default) on project clients: 
Unable to copy files for packaging: You must set at least one file. -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

有没有办法让一个映射部分满意包含零文件?

maven rpm-maven-plugin

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

在不完整的父级上追踪Dagger .plus()

考虑一个Dagger模块:

@Module(library = true, complete = false)
public static class Module {
    @Provides
    public Contextualized providesContextualized(Context ctx) {
        return new Contextualized(ctx.getUsername());
    }
    // ... and many more such provides.
}
Run Code Online (Sandbox Code Playgroud)

Context是一个对象可能连接到例如在启动时无法知道的HTTP会话,当一个人通常会创建一个图形时:

@Module(library = true, complete = false)
public static class ContextModule {
    private final String username;
    public ContextModule(String username) { this.username = username; }

    @Provides
    public Context providesContext() {
        return new Context() {
            public String getUsername() { return username; }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

鉴于Module足够长,首先为Module创建一个图表似乎是有意义的:

ObjectGraph baseline = ObjectGraph.create(new Module());
Run Code Online (Sandbox Code Playgroud)

然后,在处理特定请求时,创建一个使图形完整的唯一图形: …

java dependency-injection dagger

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

奇怪的bash范围规则使我望而却步

考虑:

t=0 ; for i in 1 2 3 4 5 6 7 8 9 10 ; do t=$((t+i)) ; done ; echo $t
Run Code Online (Sandbox Code Playgroud)

打印55.

但:

totsize=0
find /home/user -type f -mmin -4860 -a -mmin +3420 | xargs du | \
while read size rest ; do
    totsize=$((totsize+size))
    echo "$totsize"
done
echo "Sum: $totsize kb"
Run Code Online (Sandbox Code Playgroud)

即使临时打印语句打印一个合理的总和,也打印"Sum:0 kb".

我知道我之前遇到过这个问题,但从未理解过.有什么区别?

bash sum

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

nom 解析器借用检查器问题

我有这个使用 nom 4.2.2 的 Rust 程序。(我冒昧地扩展了 nom 解析器功能。)

extern crate failure;
extern crate nom;

use failure::Error;
use std::fs::File;
use std::io::Read;

fn nom_parser(i: &[u8]) -> ::nom::IResult<&[u8], String, u32> {
    { ::nom::lib::std::result::Result::Ok((i, ("foo".to_owned()))) }
}

fn my_parser(buf: &[u8]) -> Result<(&[u8], String), Error> {
  Ok((buf, "foo".to_owned()))
}

fn main() -> Result<(), Error> {
  let handler = |mut entries: String| { entries.clear() };
  loop {
    let mut buf = Vec::new();
    File::open("/etc/hosts")?.read_to_end(&mut buf)?;
    let res = nom_parser(&buf)?.1;
    // let res = my_parser(&buf)?.1;
    handler(res);
  }
} …
Run Code Online (Sandbox Code Playgroud)

rust borrow-checker nom

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

为什么mysql决定这个子查询依赖?

在MySQL 5.1.34服务器上,我有以下令人困惑的情况:

mysql> explain select * FROM master.ObjectValue WHERE id IN ( SELECT id FROM backup.ObjectValue ) AND timestamp < '2008-04-26 11:21:59';
+----+--------------------+-------------+-----------------+-------------------------------------------------------------+------------------------------------+---------+------+--------+-------------+
| id | select_type        | table       | type            | possible_keys                                               | key                                | key_len | ref  | rows   | Extra       |
+----+--------------------+-------------+-----------------+-------------------------------------------------------------+------------------------------------+---------+------+--------+-------------+
|  1 | PRIMARY            | ObjectValue | range           | IX_ObjectValue_Timestamp,IX_ObjectValue_Timestamp_EventName | IX_ObjectValue_Timestamp_EventName | 9       | NULL | 541944 | Using where | 
|  2 | DEPENDENT SUBQUERY | ObjectValue | unique_subquery | PRIMARY                                                     | PRIMARY …
Run Code Online (Sandbox Code Playgroud)

mysql performance subquery

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