我有一个测试脚本,通过各种输入反复运行一个小应用程序:
# test_script.sh
for input1 in $some_range; do
    for input2 in $some_other_range; do
        if ! ./my_app $input1 $input2 2>/dev/null; then
            echo "ERROR: app failed with inputs: $input1 $input2"
        fi
    done
done
这一切都很好,除非它失败了,我得到两条消息,我想要的"错误"消息,然后另一条消息(显然来自bash?)提醒我我的应用程序已中止:
test_script.sh: line 10:   641 Aborted           ./my_app $input1 $input2
ERROR: app failed with inputs: XXX YYY
如何防止"中止"消息?
另请注意:应用程序可能在标准C库'assert'语句上失败.
我有一些Perl代码:
{
  key => [@{$myArray}]
}
我想重构一遍:
{
  key => $myArray
}
如果我没有改变指向的值,那两个语义是否等价key?
我正在玩TypeScript,我有一些功能混合,Eventable而且Settable我想混合到一个Model类(假装它像Backbone.js模型):
function asSettable() {
  this.get = function(key: string) {
    return this[key];
  };
  this.set = function(key: string, value) {
    this[key] = value;
    return this;
  };
}
function asEventable() {
  this.on = function(name: string, callback) {
    this._events = this._events || {};
    this._events[name] = callback;
  };
  this.trigger = function(name: string) {
    this._events[name].call(this);
  }
}
class Model {
  constructor (properties = {}) {
  };
}
asSettable.call(Model.prototype);
asEventable.call(Model.prototype);
上面的代码工作正常,但如果我尝试使用其中一个混合方法,则无法编译(new Model()).set('foo', 'bar').
我可以解决这个问题
interfacemixins的声明 …我正在遍历列表,逐步建立状态,偶尔遇到某个哨兵时,我会返回结果。如果我是在Python中执行此操作,则我会懒惰地返回yield结果,并在执行时跟踪函数本地范围内的状态:
# this is simplified for illustration
def yielder(input_list):
    state = 0
    for item in input_list:
        if item = 'SENTINEL':
            yield state * 2
            state = 0
        else:
            state += item
yielder([1, 5, 2, 5, 'SENTINEL', 4, 6, 7]) # [26, 34]
我的第一个实现使用reduce,但这并不如yield:
iterate 可以用来减轻后者,但我实际上并不希望为每个输入项都返回一些东西,因此需要更多的调整。
Clojure中的惯用方式是什么?
如何在Python中获得最大有符号短整数(即C的limits.h中的SHRT_MAX)?
我想从*.wav文件的单个通道中标准化样本,所以我想要一堆介于1和-1之间的一堆浮点数,而不是一堆16位有符号整数.这是我得到的(相关代码在normalized_samples()函数中):
def samples(clip, chan_no = 0):
    # *.wav files generally come in 8-bit unsigned ints or 16-bit signed ints
    # python's wave module gives sample width in bytes, so STRUCT_FMT
    # basically converts the wave.samplewidth into a struct fmt string
    STRUCT_FMT = {  1 : 'B',
                    2 : 'h' }
    for i in range(clip.getnframes()):
        yield struct.unpack(STRUCT_FMT[clip.getsampwidth()] * clip.getnchannels(), 
                clip.readframes(1))[chan_no]
def normalized_samples(clip, chan_no = 0):
    for sample in samples(clip, chan_no):
        yield float(sample) / float(32767) …当我从我的bashshell 运行以下内容时:
bash -c '(export abc=123 && echo $abc)'
输出为"123".但是当我把它运行时ssh:
ssh remote-host "bash -c '(export abc=123 && echo $abc)'"
没有输出.为什么是这样?有没有解决的办法?也就是说,有没有办法为我运行的命令设置环境变量ssh?
注意:当我替换echo $abc标准之类echo $USER的ssh命令时,命令会按预期打印出远程计算机上的用户名,因为它已经设置好了.
我正在使用OpenSSH 4.3运行RHEL 5 Linux
我正在使用带有CoffeScript的Node.js和以下函数迭代文件中的行:
each_line_in = (stream, func) ->
    fs.stat stream.path, (err, stats) ->
        previous = []
        stream.on 'data', (d) ->
            start = cur = 0
            for c in d
                cur++
                if c == 10
                    previous.push(d.slice(start, cur))
                    func previous.join('')
                    previous = []
                    start = cur
            previous.push(d.slice(start, cur)) if start != cur
如果没有将整个文件读入内存,有没有更好的方法呢? 并且通过"更好",我的意思是更简洁,内置到Node.js,更快,或更正确.如果我正在编写Python,我会做这样的事情:
def each_line_in(file_obj, func):
    [ func(l) for l in file_obj ]
我看到这个问题 使用了Peteris Krumin的"懒惰"模块,但我想完成这个,而不添加外部依赖.
我正在编写我的第一个iPhone应用程序,我一直在探索Cocoa Touch和Objective-C中的设计模式.我来自客户端Web开发的背景,所以我试图围绕代表们.
具体来说,我不明白为什么需要委托对象而不是事件处理程序.例如,当用户按下按钮时,会使用event(UITouchUpInside)处理它,但是当用户完成对文本框的输入并使用"完成"按钮将其关闭时,通过调用文本上的方法来处理该操作box的委托(textFieldShouldReturn).
为什么使用委托方法而不是事件?我也在视图控制器中注意到了这个viewDidLoad方法.为什么不直接使用活动?
我有一个小脚本,可将 Markdown 文件编译为 html,并将其与一些样式表和 javascript 一起插入到模板的主体中。我有一个 GNU makefile 来完成这个:
output.html: content.md compile.py style.css script.js
    python compile.py < $< > $@
当我运行它时,我收到错误:
make: *无规则生成目标
style.css', needed byoutput.html'。停止。
如果我删除compile.py、style.css和script.js,目标将运行,但它不再依赖于文件,因此我可以在 中进行更改style.css,并且不会重新运行目标。
所有这些文件都在同一目录中:
my_project_directory/
    content.md
    compile.py
    style.css
    script.js
如何在不导致错误的情况下将所有这些文件声明为依赖项?
我需要从
选择中有效地计算下一个长度的排列.维基百科列出了一个很好的算法 
,可以根据选择计算下一个长度排列.knnn
我能想到的最好的事情是使用该算法(或Steinhaus-Johnson-Trotter算法),然后只考虑k列表的第一项,并在变化全部高于该位置时再次迭代.
约束:
k的排列n(这是其他算法失败的地方)非约束:
bash ×2
algorithm ×1
clojure ×1
cocoa-touch ×1
coffeescript ×1
gnu-make ×1
ios ×1
iphone ×1
makefile ×1
mixins ×1
node.js ×1
objective-c ×1
perl ×1
permutation ×1
python ×1
shell ×1
ssh ×1
struct ×1
typescript ×1
uikit ×1