Skip to content

Instantly share code, notes, and snippets.

View xexi's full-sized avatar

Hyper xexi

  • DMC
View GitHub Profile
@xexi
xexi / nodepath.js
Created May 10, 2019 02:11 — forked from lepture/nodepath.js
check NODE_PATH
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();
@xexi
xexi / npm install ignore-scripts
Created October 10, 2017 09:07
npm install ignore-scripts
ex>
npm install [email protected] --ignore-scripts
@xexi
xexi / js arr random
Created September 1, 2017 08:20
js arr random
"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)
}
@xexi
xexi / js random (positive)
Created September 1, 2017 07:23
js random (positive)
function randomIntFromInterval(min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
@xexi
xexi / js zerofill (positive)
Created September 1, 2017 06:37
js zerofill (positive)
function zerofill(number, length) {
// Setup
var result = number.toString();
var pad = length - result.length;
while(pad > 0) {
result = '0' + result;
pad--;
}
@xexi
xexi / Would it be better if i change it to prototype style?
Last active August 31, 2017 07:58
Would it be better if i change it to prototype style?
'use strict';
var obj = { year: 2017 }; // year is user input
function journey(a, cb){
a.country = "go usa";
cb(a);
}
function journey2(a, cb){
@xexi
xexi / js dec2bin playground
Created August 21, 2017 08:26
js dec2bin playground
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('');
@xexi
xexi / redis conf process
Created August 1, 2017 09:05
redis conf/process
// 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
@xexi
xexi / find duplicates word in array
Created July 31, 2017 08:22
find duplicates word in array
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 }
@xexi
xexi / sort by two values prioritizing
Created July 31, 2017 08:02
sort by two values prioritizing
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);