This file contains hidden or 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 leftTrimTstr(str) { | |
let strArr = str.split('\n'), | |
noStartSpace = strArr.filter(str => /^[^-\s].*/.test(str) && str !== '').length > 0; | |
if (strArr.length === 1 || noStartSpace) { | |
// 单行字符串,或存在顶格行的多行字符串不作处理 | |
return str; | |
} | |
else { | |
let spaceArr = strArr.map(str => str.match(/^\s+/)).filter(v => v).map(arr => arr[0]); | |
let shortestSpaceLen = Math.min.apply(null, spaceArr.map(space => space.length)); |
This file contains hidden or 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 getAllCountriesCode() { | |
var table = document.getElementsByClassName("v-table-table")[0] | |
, trArr = table.firstChild.children | |
, codeArr = Array.from(trArr).map(tr=>tr.children[3].firstChild.innerText); | |
return codeArr; | |
} | |
function code2url(code) { | |
return `http://biogeo.ucdavis.edu/data/gadm2.8/shp/${code}_adm_shp.zip` | |
} |
This file contains hidden or 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
// parseInt(string, radix); | |
parseInt('000050',16) | |
// numObj.toString([radix]) | |
parseInt(44112).toString(16) |
This file contains hidden or 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
/** 定时任务,每隔一定时间,从任务队列取任务,送给执行函数处理。 | |
* @param {Array} taskQueue 任务队列 | |
* @param {Function} execFn 任务处理函数 | |
* @param {Number} subQueuLen 每次处理的任务数 | |
* @param {Number} duration 每次处理任务的时间 | |
*/ | |
function taskTimer(taskQueue, execFn, subQueueLen, duration) { | |
let numOfSubQueue = Math.ceil(taskQueue.length / subQueueLen), i = 0, timmer, paused = false; | |
if(!isArgsValid()){return false} | |
function isArgsValid() { |
This file contains hidden or 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
let app = require('express')(), | |
session = require('express-session'), | |
cookieParser = require('cookie-parser'), | |
http = require('http'), | |
io = require('socket.io'), | |
store = new session.MemoryStore(); | |
// 添加 session 支持 | |
app.use(session({ | |
secret: 'test', |
This file contains hidden or 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
// 生成 zjhou's logo | |
(function(opt) { | |
let OPTION = Object.assign({ | |
canvasWd: 512, | |
canvasHt: 512, | |
logoXpos: '', | |
logoYpos: '', | |
logoSize: 4, | |
color: '#000', | |
$wrapper: document.querySelector('body') |
This file contains hidden or 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
class EventObserver { | |
constructor() { | |
this.observers = []; | |
} | |
subscribe(fn) { | |
this.observers.push(fn); | |
} | |
unsubscribe(fn) { | |
this.observers = this.observers.filter(subscribe => subscribe !== fn); | |
} |
This file contains hidden or 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
// 1. 拿页面 | |
var Get = function(url) { | |
const promise = new Promise(function(resolve, reject){ | |
const handler = function() { | |
if (this.readyState !== 4) { | |
return; | |
} | |
if (this.status === 200) { | |
resolve(this.response); | |
} else { |
NewerOlder