小编Chr*_*911的帖子

请求和连接在节点4.1.2上加倍

我们目前正在从节点0.10更新到节点4.1.2,我们看到了一些奇怪的模式.我们的postgres数据库的连接数加倍1,我们看到与外部服务2的请求相同的模式.我们正在运行运行本机群集API的群集应用程序,并且两个版本的工作者数量相同.

我无法理解为什么升级运行时语言显然会通过将请求加倍到外部服务来改变应用程序行为.

Postgres连接 外部请求

node.js

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

使用Promises的"带超时间隔"的好模式是什么

我正在写一些代码来每N ms进行一次资源轮询,这会在M秒后超时.我希望尽可能多地使用Bluebird做出承诺.到目前为止,我提出的解决方案使用节点的间隔,可取消的蓝鸟承诺和蓝鸟的超时功能.

我想知道是否有更好的方法来实现蓝鸟和一般承诺的间隔时间?主要是通过确保间隔在该点停止并且永远不会无限期地继续.

var Promise = require('bluebird');

function poll() {
  var interval;

  return new Promise(function(resolve, reject) {
    // This interval never resolves. Actual implementation could resolve. 
    interval = setInterval(function() {
      console.log('Polling...')
    }, 1000).unref();
  })
    .cancellable()
    .catch(function(e) {
      console.log('poll error:', e.name);
      clearInterval(interval);
      // Bubble up error
      throw e;
    });
}

function pollOrTimeout() {
  return poll()
    .then(function() {
      return Promise.resolve('finished');
    })
    .timeout(5000)
    .catch(Promise.TimeoutError, function(e) {
      return Promise.resolve('timed out');
    })
    .catch(function(e) {
      console.log('Got some other error');
      throw e;
    });
}

return pollOrTimeout()
  .then(function(result) …
Run Code Online (Sandbox Code Playgroud)

node.js bluebird

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

过滤Android ListView - 空间角色

我想过滤我listView使用一个EditText盒子并使用适配器getFilter()功能.它工作得很好,直到我在文本框中放置一个空格字符.

编辑:这是一个SimpleAdapter而不是ArrayAdapter

如果我的列表中包含以下单词:{"Apple","Banana","Red Apple"}如果我输入"apple",它将返回包含苹果字样的所有项目(Apple和Red Apple).如果我输入"apple",它将不会返回任何内容.

有任何想法吗?这是代码:

searchBox = (EditText) findViewById(R.id.searchBox);

searchBox.addTextChangedListener(filterTextWatcher);
Run Code Online (Sandbox Code Playgroud)

private TextWatcher filterTextWatcher = new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before, int count) {
    // TODO Auto-generated method stub          
}

public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
    // TODO Auto-generated method stub          
}

public void afterTextChanged(Editable s) {
    // TODO Auto-generated method stub
    myAdapter.getFilter().filter(s.toString());
}
};
Run Code Online (Sandbox Code Playgroud)

java android listview filter adapter

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

HTTP POST(未知协议)上的SSL错误

尝试通过SSL连接到Imgur API会给我一个错误.这是代码和错误:

  API_URI = URI.parse('https://api.imgur.com')
  API_PUBLIC_KEY = 'Client-ID --'

  ENDPOINTS = {
    :image   => '/3/image',
    :gallery => '/3/gallery'
  }

  # Public: Upload an image
  #
  # args    - The image path for the image to upload
  # 
  def upload(image_path)
    http = Net::HTTP.new(API_URI.host)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE

    params   = {'image' => File.open(image_path)}
    request  = Net::HTTP::Post.new(API_URI.request_uri)
    request.set_form_data(params)
    request.add_field('Authorization', API_PUBLIC_KEY)

    response = http.request(request)
    puts response.body
  end
Run Code Online (Sandbox Code Playgroud)

而错误:

`connect': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol (OpenSSL::SSL::SSLError)
Run Code Online (Sandbox Code Playgroud)

我知道VERIFY_NODE不是很好的做法,但我现在只想测试连接.

Ruby版本:1.9.2

ruby api ssl https

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

具有多个值的命令行参数

我正在做一个 perl 脚本,我需要从命令行获取多个值。例子:

perl script.pl --arg1 op1 op2 op3
Run Code Online (Sandbox Code Playgroud)

我正在使用 Getopt::Long 并且可以让它工作:

perl script.pl --arg1 op1 --arg1 op2 --arg1 op3
Run Code Online (Sandbox Code Playgroud)

但我真的需要(想要)第一个选择。

我检查了他们的文档,这应该是我想要的:

GetOptions('arg1=s{3}' => \@myArray);
Run Code Online (Sandbox Code Playgroud)

http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm#Options_with_multiple_values

但我收到这个错误:

选项规范错误:“arg1=f{3}”

有什么想法/解决方案吗?

perl command-line arguments

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

在批处理脚本变量中转义引号

如何在变量中转义引号以与另一个变量进行比较.

示例:脚本输出"test.exe"的输出"正常"(没有周围的引号)

在批处理脚本中,我将输出保存在我的批处理脚本中的变量中,然后想要与保存的变量进行比较.

set ouputTest1 = "The output of "test.exe" is OK"

test.exe -p 75 > temp.txt
set /p TESTOUTPUT=< temp.txt
if %TESTOUTPUT% == %ouputTest1%
Run Code Online (Sandbox Code Playgroud)

问题在于outputTest1变量和字符串中的引号.我尝试使用这样的双引号:

set ouputTest1 = "The output of ""test.exe"" is OK"
Run Code Online (Sandbox Code Playgroud)

但没有运气.

有任何想法吗?

windows escaping batch-file

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