小编Sec*_*mon的帖子

使用循环处理列表,每次获取100个元素,并在列表末尾自动少于100个元素

有没有办法使用一个循环,它取一个大列表中的前100项,与它们做一些事情,然后下一个100等,但当它接近结束时,它会自动缩短"100"步骤到剩余的项目.

目前我必须使用两个if循环:

for (int i = 0; i < listLength; i = i + 100)
{
    if (i + 100 < listLength)
    {
        //Does its thing with a bigList.GetRange(i, 100)
    }
    else
    {
        //Does the same thing with bigList.GetRange(i, listLength - i)
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法呢?如果不是,我将至少使"事物"成为一个函数,因此代码不必被复制两次.

c# loops list range

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

如何通过mongoose和ssh隧道连接

我按如下方式设置了我的mongod.conf,因此它只允许localhost连接.

storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
  bindIp: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

然后我希望我的网站ssh到mongodb,所以端口必须转换为localhost.

但是,如何将其与mongoose的连接功能集成?

mongoose.connect(configDB.url, function(err){
  if (err){
    console.log('Error connecting to mongodb: ' + err)
  }
});
Run Code Online (Sandbox Code Playgroud)

我找到了以下命令,但我不确定这是否是我需要的:

ssh -L 4321:localhost:27017 -i ~/.ssh/ssh_key user@ip-adress
Run Code Online (Sandbox Code Playgroud)

这应该通过端口4321 ssh我到localhost吧?所以我想我在nodejs mongoose的connect函数中需要这样的东西.我试图在mongodb安全教程上阅读这个,但我根本无法将他们的指令链接到nodejs.有经验的人吗?

ssh mongoose mongodb node.js

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

列出列表中每个列表中的特定位置(python)

有没有办法在矩阵中选择每个第二个或第三个(例如)项目?

例如:

f = [["1", "5", "8", "9"], ["2", "6", "9", "10"], ["3", "7", "11", "12"]]
Run Code Online (Sandbox Code Playgroud)

我想知道是否有一个直接的功能来选择每个列表中的每个第二个数字(最好也将这些数字放在一个列表中).从而导致:

["5", "6", "7"]
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用循环实现这一点,但我想知道我是否可以直接实现这一点.

python position list matrix python-3.x

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

标签 统计

list ×2

c# ×1

loops ×1

matrix ×1

mongodb ×1

mongoose ×1

node.js ×1

position ×1

python ×1

python-3.x ×1

range ×1

ssh ×1