Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Chunlin-Li / 164716112.md
Created January 16, 2016 08:53
xargs usage

xargs 默认是单线程执行,如果要使用多线程并行执行, 需要 -P N 参数, 其中N是期望使用的线程数.

xargs -n 指定有标准输入传递进来的最大参数数量. 通常使用 -n 1

xargs -I {} 输入的参数的替代字符串, 可以用于指定输入参数在目标执行命令中的位置. 如 cat words.txt | xargs -n1 -I{} grep {} file.txt

@Chunlin-Li
Chunlin-Li / 476102bb288234c4.md
Created January 16, 2016 09:05
shell 脚本中 按行读取文件
while read aline;
do 
  echo $aline
  some code....
done < targetFile.log

read 是系统自带的文件读取操作.

@Chunlin-Li
Chunlin-Li / 4b0d3255b.md
Last active January 30, 2016 03:13
ubuntu/debian apt package install (gstreamer0.10-ffmpeg)

在 ubuntu 上安装 package 时的依赖

使用 clementine 播放 ape 格式 (ffmpeg parsed ape)音乐时 遇到一个问题: Your GStreamer installation is missing a plug-in.

一篇文章看到安装 ffmpeg plugin 的方法:

sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install gstreamer0.10-ffmpeg

编辑相关

自动缩进 set autoindent
缩进宽度 set tabstop=2

编码问题 encode

vim 中通常不修改 encoding 参数, 即使出现乱码, 通常也保持该值为 utf-8

文件被打开后, 就已经被 vim 从文件自身的编码转为 utf-8 编码了, 并且将 fileencoding 设置为文件自身编码, 当保存修改时, vim 会将文件编码为 fileencoding 表示的编码方式并保存, 因此如果修改了该参数并保存文件, 相当于对文件进行了转码. vim 命令例如: set fileencoding=gbk

@Chunlin-Li
Chunlin-Li / b0d3255bfef956.md
Last active February 4, 2016 15:23
npm package management ( publish update .... )

发布

  1. 需要 npm 帐号, 如果没有先去官网申请一个, 然后在本地 npm adduser 的时候输入已经注册的用户名和密码即可通过验证.
  2. 在要上传的模块路径下, 检查 package.json 文件, 尽量完善一下其中的信息. 以便更多的人看到.
  3. 使用 npm publish 即可完成发布. 注意命名不要冲突了.

依赖

dependencies are installed on both:
npm install from a directory that contains package.json npm install $package on any other directory

@Chunlin-Li
Chunlin-Li / 882377893243.md
Created February 17, 2016 06:37
chrome v8

使用 sed 将一行中的特定部分切出来. extract substring by pattern. regex

cat xxxxx |grep xxxx | sed -n 's/REGEX_FULLLINE/\1/p'

例:

echo "regular expression - extract part of string using sed" |sed -n 's/.*- extract \(.*\) using.*/\1/p'
@Chunlin-Li
Chunlin-Li / client.js
Created March 5, 2016 08:39
reduplicate node-inspetor network agent bug: injection of network agent cause EventEmitter memory leak.
'use strict';
// use node-debug to run client.js and observe the memory useage.
var http = require('http');
var keepAliveAgent = new http.Agent({keepAlive: true, maxSockets: 500});
var list = [];
for (var i = 0; i < 500; i++) {
list.push("hello world");
}
@Chunlin-Li
Chunlin-Li / 838h328e89892.md
Last active March 9, 2016 07:21
用 awk 判断文件2中的行是否在文件1中都存在.
{
  if(FNR==NR) { # first file
        map[$1]=1
  } else {  # second file
        if ($1 in map) {
        } else {
            print $1
        }
 }
@Chunlin-Li
Chunlin-Li / 1460732511810.js
Created April 15, 2016 15:02
javascript nodejs Object create proto
function Person(){
this.name = 'anonymous'
}
Person.prototype.toJSON = function toJSON(){
return 'Person ' + this.name;
};
Person.prototype.pro01 = 'yes';