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 / 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 / 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 / versionStringCompare.java
Created June 17, 2015 10:32
版本字符串的比较
/**
* 比较两个版本。 0 :两个版本相等; 1 : version1 > version2; -1 : version1 < version2
* 仅适用于由数字和 "." 符号构成的版本号字符串。 对应正则规则 \d+(\.\d+)+
* 如果 version1 和 version 2 均为 empty 返回0 , 否则 empty 恒小于任意字符串。
*/
private static int compareVersionString(String version1, String version2) {
if(StringUtils.isEmpty(version1)) {
if(StringUtils.isEmpty(version2)){
return 0;
} else {
@Chunlin-Li
Chunlin-Li / 20180529.md
Last active June 21, 2018 02:19
MarketManagmentAPI

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 / runService.sh
Created July 24, 2017 06:25
项目启动脚本 (10.8.8.8 使用)
#!/usr/bin/env bash
ProjectName="sundries" # 项目名称
Port=3030 # 服务监听端口 , 通过设置 NODE_PORT 环境变量实现
CleanNodeModules=true # 是否每次都清除 node_modules
NodeVersion=8.1.2 # node 版本, 需确保 nvm 有该版本
Restart=true # 是否每次都重启服务
if [[ -e $1 ]]; then
@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 / index.js
Last active April 28, 2017 09:32
test
/**
* SMS services.
*/
"use strict";
const http = require("http");
const URL = require("url");
@Chunlin-Li
Chunlin-Li / index.js
Created March 20, 2017 12:08
co-body v5.0.3 reproduce
'use strict';
var koa = require('koa');
var bodyParse = require('koa-bodyparser');
var app = new koa();
app.use(function *(next) {
let bodyData = [];
this.req.on('data', (chunk) => {