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 parseAttrs (str) { | |
str = str.replace('(', '') | |
str = str.replace(')', '') | |
let parts = str.split(':') | |
let tmp = {} | |
if (parts[0] && parts[1]) { | |
let v = parts[1].trim() | |
v = v.replace(/\'/g, '') | |
if (!isNaN(v)) { | |
v = parseFloat(v) |
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 Bus () { | |
this.events = {} | |
this.on = async (eventName, handler) => { | |
if (!this.events[eventName]) { | |
this.events[eventName] = [] | |
} | |
let targetHandler = handler | |
let before = [] | |
if (typeof handler === 'function') { | |
position = this.events[eventName].length |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Echarts</title> | |
<style type="text/css"> | |
@keyframes loading-spinner { | |
0% {transform: rotate(0deg);} | |
20% {transform: rotate(120deg);} | |
40% {transform: rotate(240deg);} | |
50% {transform: rotate(270deg);} |
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
// import json array file to elasticsearch | |
const fs = require('fs') | |
const shelljs = require('shelljs') | |
let endpoint = process.argv[2] | |
let jsonFile = process.argv[3] | |
if (!endpoint || !jsonFile || endpoint.search('_bulk') === -1) { | |
console.log('sample: node jsonArrayToES.js localhost:9200/bank/customer/_bulk customer.json') | |
process.exit() | |
} |
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 Promise = require('bluebird'); | |
function getP (t) { | |
return new Promise((resolve, reject) => { | |
console.time(t); | |
setTimeout(() => { | |
console.log('\none Promise', t); | |
console.timeEnd(t); | |
return resolve(); | |
}, t); |
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 list = [-1, 3, 15, 133, -3, 2] | |
function sleepSort(arr) { | |
var ordered = [] | |
var q = [] | |
function afterWhile (x, resolve) { | |
ordered.push(x) | |
return resolve() | |
} | |
arr.forEach(n => { |
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 getPrevWorkDay (t) { | |
if(!t) t = new Date(); | |
if( !(t instanceof Date) ) t = new Date(t); | |
var prevDay = new Date( t.getTime()); | |
do { | |
prevDay = new Date( prevDay.getTime() - 86400000 ); | |
} while( -1 !== [0, 6].indexOf(prevDay.getDay()) ); | |
return prevDay; | |
} |
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 os = require('os'); | |
//get all public ips | |
var getMyPublicIp = function(){ | |
var nics = os.networkInterfaces(); | |
var ips = []; | |
for(var i in nics) { | |
nics[i].forEach(function(cfg){ | |
if(!cfg.internal) { | |
ips.push(cfg.address); | |
} |
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 contact = [ | |
{ nickname: 'coco', mobile: '13151185930', gender: '女' }, | |
{ nickname: 'F**k', mobile: '18651941714', gender: '女' } | |
]; | |
var price = [ | |
{ mobile: '13151185930', price: 1024 }, | |
{ mobile: '18651941714', price: 1722 } | |
]; | |
contact.forEach(function(c){ |
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 ksort(obj){ | |
var keys = Object.keys(obj).sort() | |
, sortedObj = {}; | |
for(var i in keys) { | |
sortedObj[keys[i]] = obj[keys[i]]; | |
} | |
return sortedObj; | |
} |