Skip to content

Instantly share code, notes, and snippets.

使用 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 / 882377893243.md
Created February 17, 2016 06:37
chrome v8
@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 / 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
@Chunlin-Li
Chunlin-Li / cd98f00b204e.md
Last active May 18, 2016 11:58
linux / bash shell 中的命令

sort

排序

split

文件分割程序.

@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 / 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 / 5e6b4b0d325.md
Created January 7, 2016 11:23
shell 中字符串的操作

str -> shell 变量

获取字符串长度

${#str}  
expr length $str

某个字符在 str 的 index (从1开始)

编辑相关

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

编码问题 encode

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

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

@Chunlin-Li
Chunlin-Li / 171157.md
Last active January 7, 2016 05:48
nginx 使用 htpasswd 添加用户验证功能

参考文档

  1. 安装 htpasswd: sudo apt-get install apache2-utils
  2. 创建用户和密码并创建验证信息文件 : sudo htpasswd -c /etc/nginx/.htpasswd John /etc/nginx/.htpasswd 是保存用户验证信息的文件路径.
  3. 继续添加用户 : sudo htpasswd -n Tom 在 STDOUT 会输出user:password 格式的信息, 将其追加到上一步生成的配置文件中即可. 注意不要反复使用 -c 参数反复创建文件.
  4. 编辑 ngixn 配置文件, 在需要的 Block 范围中(比如 location 或 server 等)添加验证配置:
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;