小编sta*_*tic的帖子

模糊语法和PEG.js的问题(未找到示例)

我想用以下内容的行解析文件:

simple word abbr -8. (012) word, simple phrase, one another phrase - (simply dummy text of the printing; Lorem Ipsum : "Lorem" - has been the industry's standard dummy text, ever since the 1500s!; "It is a long established!"; "Sometimes by accident, sometimes on purpose (injected humour and the like)"; "sometimes on purpose") This is the end of the line
Run Code Online (Sandbox Code Playgroud)

所以现在解释部分(不是所有空格都被描述,因为这里有标记):

  • simple word 是由空格分隔的一个或多个单词(短语)
  • abbr - 是字符串的固定部分(永远不会改变)
  • 8 - 可选号码
  • . - 总是包括在内
  • word, simple phrase, one another phrase …

regex parsing ambiguity peg

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

awk print vs printf函数

awk有两个输出功能:printprintf.

  • 它们的实现是否awk完全不同?
  • 关于性能/速度有什么区别(如果可能的话 - 理论上,不仅仅是time命令行上的" ")?
  • 他们使用相同的系统调用吗?

io awk printf

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

为什么单击FireFox中的按钮会打开文件打开对话框两次

我有一个file <input> field和一个<span>装饰输入字段:

<span class="span5 btn btn-primary btn-file" id="chose_files_btn" onclick="filechose_button.click()">chose files
    <input id="filechose_button" type="file" name="fileData" size="1" style="display: none"/>
</span>
Run Code Online (Sandbox Code Playgroud)

虽然我认为这在ChromeSafari中的行为,FireFox会在点击时打开两个 .file input dialogsbutton(span)

为什么会这样呢?

我假设,该文件输入字段是不可见的,只有通过具有按钮行为的跨度才能访问它.

更新:

如果我把它的<input>外部<span>表现正常.

 <span class="span5 btn btn-primary btn-file" id="chose_files_btn" onclick="filechose_button.click()">chose files</span>
 <input id="filechose_button" type="file" name="fileData" size="1" style="display: none"/>
Run Code Online (Sandbox Code Playgroud)

的jsfiddle

但为什么inside position不呢?

javascript firefox file-upload html-input input-field

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

如何在mongoid/rails中收集一个字段?

我有一个模特

class MyClass
  include Mongoid::Document
  include Mongoid::Timestamps

  field :a, type: String
  field :b, type: String
  field :c, type: String
end
Run Code Online (Sandbox Code Playgroud)

那么如何从MyClass集合中的所有对象获取所有a-s,b-s或c-s作为列表/数组?Rails/Ruby/Mongoid有没有任何语法糖?

我知道,有可能这样做:

all_a = []

MyClass.desc(:created_at).each do |my_object|
  all_a.push(my_object.a)
end
Run Code Online (Sandbox Code Playgroud)

但我想到了:

MyClass.get(:fields => :a)
MyClass.get(:fields => :a,:b)
Run Code Online (Sandbox Code Playgroud)

更新:

我发现了一些东西

MyClass.create(a: "my_a_string")
MyClass.create(a: "my_another_a_string")
Run Code Online (Sandbox Code Playgroud)

现在:

MyClass.only(:a)
Run Code Online (Sandbox Code Playgroud)

应该工作,但我得到:

 => #<Mongoid::Criteria
  selector: {}
  options:  {:fields=>{"a"=>1}}
  class:    MyClass
  embedded: false>
Run Code Online (Sandbox Code Playgroud)

什么时候 MyClass.only(:a).to_a

 => [#<MyClass _id: 525f3b9e766465194b000000, created_at: nil, updated_at: nil, a: "my_a_string", b: nil, c: nil>, #<MyClass _id: …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails mongodb mongoid

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

awk 在脚本中更改工作目录

我想在 awk 脚本中更改工作目录:

  ...
  path="./some/path"
  system("pwd") ; \
  current_dir=system("pwd") ; \
  pushd_cmd="pushd " path ; \    # a "cd" doesn't work too
  print pushd_cmd ; \
  system(pushd_cmd) ; \
  system("pwd"); \               # the same directory as before
  type="xml"
  ls_cmd = "ls *." type;         # so I can't find the files. Specifying with "./some/path/*.xml" doesn't work too (without trying to change the working directory)
  ...
Run Code Online (Sandbox Code Playgroud)

有人知道为什么系统在我的情况下不起作用吗?

unix bash awk system pwd

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

如何使用jQuery选择最接近的元素(不能是这个的父元素)?

假设一个html文档:

<html>
  <head>
  </head>
  <body>
    <li id="eee">
      <li>aaa</li>
      <span>bbb</span>
        ...
          <div>
            <button id="ccc">ddd</button>
          </div>
        ...
    </li>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用$('#ccc').closest('li')jQuery将选择<li id="eee">...</li>- 最近的祖先<button id="ccc">.是否有可能选择<li>aaa</li>"真正"最接近的<li>元素<button id="ccc">(因此,它不一定是祖先,但足以成为其中一个祖先兄弟)?

更新:

有效的HTML(特别为@PSL家伙,已经删除了他的评论):

<html>
  <head>
  </head>
  <body>
    <div id="eee">
      <div>aaa</div>
      <span>bbb</span>
      <ul>
        <li>fff</li>
        <li>
          <button id="ccc">ddd</button>
        </li>
      </ul>
    </li>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

如何获得<div>aaa</div>不使用该parent()函数,但使用smth.喜欢trueClosest('div')考虑祖先的兄弟姐妹,祖先和兄弟姐妹?

我只是想知道,如果jQuery有这样的功能吗?

jquery parent closest dom-traversal jquery-traversing

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

为什么node.js异步模块在第一步之后使用async.eachLimit(数组,限制,函数,回调)停止?

如果我使用此代码:

async.eachLimit(body.photos.photo, 10, function(photo) {

         var flickr_getphoto_path = ".....";

         request.get({url: flickr_host_url + flickr_getphoto_path, json: true}, function(error, response, body) {
           if (!error && response.statusCode == 200) {

             console.log("SIZES LENGTH: " + body.sizes.size.length);
             var source_url = body.sizes.size[body.sizes.size.length - 1].source;
             request(source_url).pipe(fs.createWriteStream(path_for_downloads + path.basename(source_url)));
           }
         });

}
Run Code Online (Sandbox Code Playgroud)

处理在10个请求之后(即在第一个循环之后)停止.应该有10个周期.

有人知道它为什么不能正常工作?

concurrency asynchronous node.js

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

如何使用slim语法转义HTML内容中的方括号?

我需要使用slim语法打印以下内容:

tr 
  td "[Send] Value"
Run Code Online (Sandbox Code Playgroud)

要么

tr 
  td [Send] Value
Run Code Online (Sandbox Code Playgroud)

所以方括号是不可见的(所以解释得有些不同):我只得到 Value

怎么逃避--> [Send] <--

更新:

一些解决方法:

tr
  th = "[Send] Value"
Run Code Online (Sandbox Code Playgroud)

但我希望有一种更" 干净 "的方式来逃避方括号,而不是使用ruby解释器来逃避它们

html haml templates ruby-on-rails slim-lang

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

Rails:“权限被拒绝 - /tmp/cache/assets/development/sprockets/...”?

当我运行 Rails 应用程序并使用浏览器导航到它们时,我收到以下错误rails

Permission denied - /path/to/my_rails_app/tmp/cache/assets/development/sprockets/37b5a12047376b10a57191a10d3af30a rails error
Run Code Online (Sandbox Code Playgroud)

而且我在./tmp/. 问题是什么?

permissions error-handling ruby-on-rails

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

在node.js中获取上传的文件名/路径

如何获取上传的文件名/路径的名称以在node.js中操作它?我想将文件从临时文件夹移动到客户文件夹.

file-upload file node.js

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

如何从“空”和“未定义”值中过滤嵌套数组?

如果我有一个 JSON 数组:

arrays = 
   [
      [
         undefined,
         ",",
         " ",
         "simple"
      ],
      [
         undefined,
         null,
         " ",
         "phrase"
      ],
      [
         undefined,
         ",",
         " ",
         "one"
      ],
      [
         undefined,
         null,
         " ",
         "another"
      ],
      [
         undefined,
         null,
         " ",
         "phrase"
      ]
   ]
Run Code Online (Sandbox Code Playgroud)

我想从中过滤undefinednull值:

arrays.forEach(function(array){array.filter(function(n){return !!n})});
Run Code Online (Sandbox Code Playgroud)

或者

arrays.forEach(function(array){array = array.filter(function(n){return !!n})});
Run Code Online (Sandbox Code Playgroud)

但它返回相同的数组而没有任何更改。

否则,如果我直接使用内部数组,它会起作用:

rest_words[0].filter(function(n){return !!n});
=> [",", " ", "simple"]
Run Code Online (Sandbox Code Playgroud)

为什么forEach()不允许修改数组?它是否仅按值迭代?通过迭代修改数组的最佳解决方案是什么?

我希望有更多的东西然后只是通过迭代 for(i=0, i<arrays.length, i++){arrays[i] = arrays[i].filter(...)}

javascript arrays for-loop filter

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