Skip to content

Instantly share code, notes, and snippets.

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

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 / 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.

@Chunlin-Li
Chunlin-Li / 11111959.md
Last active November 18, 2015 03:00
javascript eval

eval(code) 直接使用时, code 中的Scope是 caller 的 scope.

如果要让 code 无法获取调用者的 scope, 需要使用间接调用( indirect call ). 注意 eval 还是能够获取 global, 并可以对其进行修改.

间接调用的常见方式:

  • (1, eval)(code)
  • var e = eval; e(code);
  • (function(e){e(code)})(eval);
  • eval.call(this, code);
  • eval('eval')(code);
@Chunlin-Li
Chunlin-Li / 1151538.md
Last active December 18, 2020 03:03
Linux soft raid, mdadm md disk 软 RAID

Linux soft RAID

使用 mdadm 工具. apt-get install mdadm

用于做 RAID 的磁盘, 可以是分区并格式化之后的, 比如 sda1 sdb1 等.

所用的磁盘需要 umount 掉.

# RAID0
@Chunlin-Li
Chunlin-Li / 1141141.md
Last active November 4, 2015 06:35
Linux 压缩 compress 7z 7za gizp bzip bzip2 使用 example
# 7z
# compress
7za a -t7z compressed.txt.7z origin.txt
#decompress
7za x compressed.txt.7z

# gzip  (replace origin file)
# compress
gzip origin.txt