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 leftTrim(str){ | |
return str.replace(/^[\s\t]+/g, ''); | |
} | |
function rightTrim(str){ | |
return str.replace(/[\s\t]+$/g, ''); | |
} | |
function trim(str){ | |
return str.replace(/(^[\s\t]+)|([\s\t]+$)/g, ''); |
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 fetchMetas() { | |
var metas = [].slice.call(document.getElementsByTagName('meta')).map(function(e) { | |
var data = {} | |
var key = '' | |
var value = '' | |
if(e.getAttribute('name')){ | |
data.name = e.getAttribute('name') | |
data.content = e.getAttribute('content') | |
return data |
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' | |
const Promise = require('bluebird'); | |
const fs = Promise.promisifyAll(require('fs')); | |
const path = require('path'); | |
/* | |
* Bom headers are 3 Bytes binary | |
*/ | |
const removeBom = filePath => { |
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
/* | |
* Add pre zero to number which is less than 10, and then return the final string | |
* @ num Number 0 | |
*/ | |
function addPreZero(num) { | |
if(arguments.length == 0) num = 0; | |
if(num < 10){ | |
return '0' + num; | |
} | |
return '' + num; |
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
/* | |
* Disable text selection when double click or drag cursor | |
* @dom html element | |
*/ | |
function disableTextSelection(dom){ | |
if(dom.addEventListener){ | |
dom.addEventListener('mousedown', function(event){ | |
event.stopPropagation(); | |
event.preventDefault(); | |
}) |
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 spawn = require('child_process').spawn; | |
const locales = spawn('systeminfo.exe', []); | |
const localeReg = /([a-z]+-[a-z]+);/ig; | |
let result = ""; | |
locales.stdout.on('data', (data) => { | |
if(data && data.length > 0){ | |
result += data; |
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
/** | |
* Lib Q | |
* For easliy manage event listener | |
* v0.0.2 | |
*/ | |
(function(w){ | |
function Q(){ | |
var elements = []; |
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
/** | |
* @param jsonObj {Object} Sample: { name: 'wangpin', job: 'engineer' } | |
* @return params {String} Sample: name=wangpin&job=engineer | |
*/ | |
function stringifyParams(jsonObj) { | |
if(typeof jsonObj !== 'object' || !(jsonObj instanceof Object)){ | |
throw new Error('Not a valid json object'); | |
} | |
var result = []; |
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 java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.UnsupportedEncodingException; | |
import java.net.InetSocketAddress; | |
import java.net.Proxy; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.net.URLEncoder; | |
import java.util.HashMap; |
OlderNewer