Skip to content

Instantly share code, notes, and snippets.

@Chunlin-Li
Chunlin-Li / 1462879258898.md
Created May 10, 2016 11:25
node js arguments

Node js 中通过 arguments 对象修改/增加参数的方法

function foo() {
    console.log(arguments);
    console.log(arguments['extra']);
}

foo.apply({}, {'0':'arg_1', '1':'arg_2', length: 2});
@Chunlin-Li
Chunlin-Li / 1462861535.md
Last active May 10, 2016 08:10
dropbox command and proxy setting

官方文檔

Proxy 的設置

proxy

dropbox proxy MODE [TYPE] [HOST] [PORT] [USERNAME] [PASSWORD] Manually sets proxy settings for Dropbox.

function sendToES(topic, list, noRetry) {
let _list = list.splice(0);
reqHelper.post('/_bulk', new Buffer(_list.concat('').join(LF)), (resp, code) => {
/** 错误处理*/
if (code !== 200) {
console.log('HTTP FAILED CODE:', code);
dumpDisk(_list);
} else if (resp.indexOf('"errors":true,') !== -1) {
let errorInfo = []; // errorInfo structure: [{i:index, t: error_type, s: status},{} ...]
'use strict';
const http = require('http');
const originalString = 'Today we see a good accelerator: http://alchemistaccelerator.com, you can found some thing in the wikipedia, https://en.wikipedia.org/wiki/The_Alchemist_Accelerator. or google it by : https://www.google.com.hk/search?es_sm=91&q=alchemist+accelerator&oq=alchemist+a&gs_l=serp.3.2.0l10.233056.233264.0.235425.2.2.0.0.0.0.134.267.0j2.2.0....0...1c.1j4.64.serp..0.2.265.J6dlgO9eRVI';
function fn(inputString, callback) {
// not a strict url match pattern
var regex = /https?:\/\/[\d\w\.\/_\-\?&=+#@]+\/?/g;
const newContent = [];
var orginalData = [{name:'jch', age:30, score:90, sex: 1, lesson: 'math'},{ name:'oh', age:31, score: 80, sex:1, lesson: 'math'}, {name:'jia', age:27, score: 70, sex:0, lesson: 'math'}, {name:'jch', age: 30, score: 80, sex: 1, lesson: 'english'}];
const fn_01 = (data, specifiedAge) => data.filter(item => item.age > specifiedAge);
const fn_02 = (data, specifiedAge) => data.reduce((prev, curr) => {
if (curr.age > specifiedAge) {
prev.name.push(curr.name);
prev.lesson.push(curr.lesson);
}
return prev;

link

Adding --output-24bit to the TiMidity options in Solfege fixes sound problems for me

I am currently trying out GNU Solfege for ear and rhythm training. Solfege uses TiMidity for playback. On my machine, the sound output always started with an annoying crackling for each exercise. Some googling brought up this solution. While that link has nothing to do with Solfege, following its advice helped in my case, too. To remove the crackling in Solfege, I did the following:

In Solfege, open the File > Preferences Menu Choose External Programs Under Audio File Players - MIDI it should say /usr/bin/timidity (or something similar) add --output-24bit to the options for that entry (my complete options for timidity are --output-24bit -idqq %s)

@Chunlin-Li
Chunlin-Li / 1460732686335.md
Created April 15, 2016 15:05
linux bash parallel sed

cat $Filetemp | parallel --pipe 'sed -e "s/[[:space:]]+/ /g"' > standard.txt

@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';
@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 / 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");
}