小编pfn*_*sel的帖子

在BASH shell中混洗数组元素的简单方法?

我可以在PHP中执行此操作,但我尝试在BASH shell中工作.我需要一个数组,然后随机洗牌内容并将其转储到somefile.txt.

因此给定数组Heresmyarray,a;b;c;d;e;f;它将产生一个输出文件,output.txt它将包含元素f;c;b;a;e;d;

元素需要保留分号分隔符.我已经看过很多bash shell数组操作,但似乎没有什么比这个简单的概念更接近.感谢您的任何帮助或建议!

bash shell shuffle

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

初始化列表与向量

在C++ 11中,可以使用初始化列表来初始化函数中的参数.它的目的是什么?使用const向量不能做同样的事情吗?以下两个程序有什么区别?

使用初始化列表:

#include <iostream>

using namespace std;

int sumL(initializer_list<int> l){
    int sum = 0;
    for (const auto i: l){
        sum += i;
    }
    return sum;
}

int main(){

    cout << sumL({1, 2, 3}) << "\n";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用const向量:

#include <iostream>
#include <vector>

using namespace std;

int sumV(const vector<int> l){
    int sum = 0;
    for (const auto i: l){
        sum += i;
    }
    return sum;
}

int main(){

    cout << sumV({1, 2, 3}) << "\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ initialization vector initializer-list c++11

10
推荐指数
4
解决办法
4939
查看次数

输出流中的非单调 DTS 先前当前更改为这可能会导致输出文件中的时间戳不正确

我有一个带有相当接近的片段的 file.txt

file 'input.mp4'
inpoint 1.5402465510368346
outpoint 2.722609395980835
file 'input.mp4'
inpoint 3.192511146068573
outpoint 7.074568028450012
file 'input.mp4'
inpoint 7.851800565719604
outpoint 9.023683423995971
file 'input.mp4'
inpoint 10.054571752548219
outpoint 12.008032734394073
file 'input.mp4'
inpoint 18.70977670431137
outpoint 21.20993923664093
file 'input.mp4'
inpoint 24.51183382153511
outpoint 26.465287650823594
...
Run Code Online (Sandbox Code Playgroud)

我把它们连接起来

ffmpeg -safe 0 -f concat -i file.txt out.mp4
Run Code Online (Sandbox Code Playgroud)

我试过

ffmpeg -use_wallclock_as_timestamps 1 -safe 0 -f concat -i file.txt out.mp4
Run Code Online (Sandbox Code Playgroud)

然而我得到

[mp4 @ 00000178c514cc00] Non-monotonous DTS in output stream 0:1; previous: 2069, current: 2067; changing to 2070. This may result in …
Run Code Online (Sandbox Code Playgroud)

ffmpeg

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

Vim无法在iTerm2中滚动

即使set mouse=a已添加到.vimrc文件中,我的vim也无法在iTerm2中滚动.

但是,在tmux中,vim的滚动功能正常工作.

我的vim出了什么问题?

vim iterm2

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

将现有的android studio项目添加到gitlab存储库

我在android studio中有一个项目,我想提交一个gitlab存储库.我有这个存储库的链接.我需要做什么,一步一步,将此项目添加到所述存储库?

git android gitlab

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

如何解决'collect2:ld返回1退出状态'?

当我在linux中构建我的源代码时,我得到了一个错误

qstring.cpp:(.text+0x2c01): undefined reference to `terminate(void)'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题呢?

linux hyperlink

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

Vim:用n + 1替换n

如何替换n与某个模式匹配的每个数字n+1?例如,我想用值+ 1替换括号中的行中的所有数字.

1 2 <3> 4 <5> 6 7 <8> <9> <10> 11 12
Run Code Online (Sandbox Code Playgroud)

应该成为

1 2 <4> 4 <6> 6 7 <9> <10> <11> 11 12
Run Code Online (Sandbox Code Playgroud)

vim replace

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

无效的路径规则魔法

当我尝试在git中部分暂存文件时,我收到以下错误消息.

git add -p mass_scan.py

fatal: Invalid pathspec magic 'prefix:8' in ':(prefix:8)mass_scan.py'
No changes.
Run Code Online (Sandbox Code Playgroud)

这是什么意思?如何部分暂存文件?

我用的是git版本

git version 2.6.2.450.g259b5e6
Run Code Online (Sandbox Code Playgroud)

直接从源安装(没有包管理器).我仍然可以部分添加文件tig.

git

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

仅在找到匹配项的行中替换

,如何仅在匹配字符串的特定行上替换单词?例如,我有

replace here: foo
but not here: foo
replace again here: foo
Run Code Online (Sandbox Code Playgroud)

我想,以取代foobar在那里的字符串的所有行replace被发现,即输出应该是

replace here: bar
but not here: foo
replace again here: bar
Run Code Online (Sandbox Code Playgroud)

受到搜索和替换的类似启发,我曾期待

:/replace/s/foo/bar/
Run Code Online (Sandbox Code Playgroud)

工作,但它只在匹配的第一行进行替换replace.如何将其扩展到整个文档?

regex vim

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

如何使用Python中的日志记录打印列表项+整数/字符串

我想用项目索引打印列表项,如

0: [('idx', 10), ('degree', 0)]
1: [('idx', 20), ('degree', 0)]
Run Code Online (Sandbox Code Playgroud)

根据下面的代码,如何将'0:'附加为整数+字符串+列表项?

import logging

class Node(object):
    __slots__= "idx", "degree"

    def __init__(self, idx, degree):
        self.idx = idx
        self.degree = 0


    def items(self):
        "dict style items"
        return [
            (field_name, getattr(self, field_name))
            for field_name in self.__slots__]

def funcA():

    a = []
    a.append(Node(10, 0))
    a.append(Node(20, 0))

    for i in range(0, len(a)):
        logging.debug(a[i].items())

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)  
    funcA()
Run Code Online (Sandbox Code Playgroud)

目前,结果是

DEBUG:root:[('idx', 10), ('degree', 0)]
DEBUG:root:[('idx', 20), ('degree', 0)]
Run Code Online (Sandbox Code Playgroud)

期待

DEBUG:root:0:[('idx', 10), ('degree', 0)]
DEBUG:root:1:[('idx', 20), …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

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