Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Chunlin-Li / 11181118.md
Last active June 22, 2016 02:29
ubuntu linux manual set resolution. 手动添加分辨率

$ cvt 2048 1152 60.0
获取对应分辨率和刷新率的信息

# 2048x1152 @ 60.00 Hz (GTF) hsync: 71.52 kHz; pclk: 197.97 MHz Modeline "2048x1152_60.00" 197.00 2048 2184 2400 2752 1152 1155 1160 1195 -hsync +vsync

$ xrandr --newmode "2048x1152_60.00" 197.00 2048 2184 2400 2752 1152 1155 1160 1195 -hsync +vsync
使用第一步获得的信息, 创建新的 mode.

AWK

awk 语句

awk '{ code for each line }'

awk '{ code for each line } END { code for end }'

awk '/regex for each line/ { code for each line } END { code for end }'

@Chunlin-Li
Chunlin-Li / 11212222.md
Created November 21, 2015 14:25
tcpdump linux 下抓包工具 的使用.
tcpdump -q src port 8080    
获取已本机 8080 端口作为源的数据传输包简要信息.
-q 是 quiet, 显示简要信息.
src 指定源, 可以换成 dst 指定目的地.
port 指定端口, 如果是指定特定主机, 可以换成 host

@Chunlin-Li
Chunlin-Li / 11251850.md
Last active June 22, 2020 12:02
node js / javascript performance: buffer vs string

performance comparison:

section1 :

push string to array, generate string by join all data with comma.

section2 :

write int(16bit) to buffer, generate string by buffer.toString('base64').

background :

batch collect data, and send them to another server or process, with high speed and large quantity.

@Chunlin-Li
Chunlin-Li / 11261223.md
Created November 26, 2015 04:33
node / javascript performance:

Performance Comparison:

node version : v4.1.2 platform: Intel I7, 16G DDR3, Ubuntu x64

Section 1

use '+' to concatenate string and variables

Section 2

@Chunlin-Li
Chunlin-Li / 11261409.md
Created November 26, 2015 06:20
node / javascript performance: string concat operator (+) vs array.join()

Performance Comprison:

Section 1 :

string concatenate operator, for short string but large times.

Section 2 :

array join(), for short string but large times.

@Chunlin-Li
Chunlin-Li / 12021015.md
Created December 2, 2015 02:27
node / javascript performance : Set vs Object and Map vs Object

Set vs Object

node version : v4.1.2
platform: Intel I7, 16G DDR3, Ubuntu x64

var theSet = new Set();
start = process.hrtime();
/***********************************/
for(let i = 0 ; i < N; i++ ) {
@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;

编辑相关

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

编码问题 encode

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

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

@Chunlin-Li
Chunlin-Li / 5e6b4b0d325.md
Created January 7, 2016 11:23
shell 中字符串的操作

str -> shell 变量

获取字符串长度

${#str}  
expr length $str

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