This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!process.env.NODE_PATH) { | |
console.log(); | |
if (process.env.SHELL === '/bin/zsh') { | |
console.log(' Please set environment variable NODE_PATH in ~/.zshrc:'); | |
} else if (process.env.SHELL === '/bin/bash') { | |
console.log(' Please set environment variable NODE_PATH in ~/.bashrc:'); | |
} else { | |
console.log(' Please set environment variable NODE_PATH:'); | |
} | |
console.log(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ex> | |
npm install [email protected] --ignore-scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function makeBall(cb){ | |
var arr = []; | |
for(var i=1; i<=100; i++){ | |
// if(!_.includes([1, 2, 3], i)) If any number is to be excluded ( _ by lodash ) | |
arr.push(i); | |
} | |
cb(arr) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomIntFromInterval(min,max) | |
{ | |
return Math.floor(Math.random()*(max-min+1)+min); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function zerofill(number, length) { | |
// Setup | |
var result = number.toString(); | |
var pad = length - result.length; | |
while(pad > 0) { | |
result = '0' + result; | |
pad--; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var obj = { year: 2017 }; // year is user input | |
function journey(a, cb){ | |
a.country = "go usa"; | |
cb(a); | |
} | |
function journey2(a, cb){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dec2bin(dec){ | |
return (dec >>> 0).toString(2); // >>> zero fill right shift due to signed bit | |
} | |
function bin2exclamation(bin){ | |
var arr = []; | |
for(var i=0; i< bin.length; i++){ | |
arr.push(parseInt(bin.substr(i, 1)) === 1 ? 0 : 1); | |
} | |
return arr.join(''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// conf set | |
"myredis" : "redis://myredis.com:6379" | |
// process grep ex | |
ps aux | grep redis-server | |
kill -9 22292 | |
ps -ef | grep -i 'redis-server' | |
kill -9 PID owned by redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl'] | |
const count = names => | |
names.reduce((a, b) => | |
Object.assign(a, {[b]: (a[b] || 0) + 1}), {}) | |
const duplicates = dict => | |
Object.keys(dict).filter((a) => dict[a] > 1) | |
console.log(count(names)) // { Mike: 1, Matt: 1, Nancy: 2, Adam: 1, Jenny: 1, Carl: 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [ | |
{ count: '12', year: '1956' }, | |
{ count: '1', year: '1971' }, | |
{ count: '33', year: '1989' }, | |
{ count: '33', year: '1988' } | |
]; | |
data.sort(function (x, y) { return x.count - y.count || x.year - y.year; }); | |
console.log(data); |
NewerOlder