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 pad(num, n) { | |
return Array(num>n?(n-(''+num).length+1):n).join(0)+num; | |
} |
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 dailyTask(time, task) { | |
var gap = (new Date("1970-1-1 " + time)).getTime() - (Date.now()) % (24 * 36e5); | |
if (gap < 0) { | |
gap += 24 * 36e5; | |
} | |
setTimeout(function() { | |
task(); | |
setInterval(task, 24 * 36e5); | |
}, gap); | |
} |
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
export function addParam(url, key, value) { | |
url = url.replace(new RegExp(`[?&]${key}=[^&]*&?`, 'g'), str => (str[str.length - 1] === "&" ? str[0] : "")); | |
const hashReg = /#[\w-]+$/; | |
let hash = url.match(hashReg) || []; | |
hash = hash[0] || ""; | |
url = url.replace(hashReg, ""); | |
let linkSymbol = "&"; | |
if (url.indexOf("?") === -1) { | |
linkSymbol = "?"; | |
} |
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
alias gls='git status' | |
alias gdf='git diff' | |
alias glg='git log' | |
alias gam='git commit -am' | |
alias gaa='git add -A :/' | |
alias np='npm publish' | |
alias op='xdg-open' |
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 A { | |
componentWillMount() { // base first | |
console.warn("A1"); | |
} | |
componentDidMount() { | |
console.warn("A2"); | |
} | |
componentWillUnmount() { | |
console.warn("A3"); | |
} |
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
const treeify = require('file-tree-sync'); | |
const fs=require('fs'); | |
const linearData = []; | |
const ret = []; | |
const childKey = "files"; | |
function getLinearData(arr, position) { | |
arr.forEach(function (obj, index) { |
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 getDataGradually(data, childKey, gap, count, updateCb, finishCb) { | |
const lastPositon = []; | |
const linearData = []; | |
const ret = []; | |
function getLinearData(arr, position) { | |
arr.forEach(function (obj, index) { | |
const pos = position.concat([index]); | |
if (obj[childKey] && obj[childKey].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
var test = ` | |
import a from b; | |
import {a,b} from c; | |
import a,b,{c,d},{e,f} from c; | |
import a,{ | |
b, | |
c,} from d; | |
alert("hi!"); | |
`; |
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 preloadImage(src) { | |
const $dom = $("<img />", { | |
src | |
}); | |
if ($dom[0].naturalWidth) { | |
return Promise.resolve($dom); | |
} | |
$dom.css({ | |
opacity: 0.01, |
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 cbUid = 0; | |
const cbMap = {}; | |
ipcRenderer.send = function(event, ...args) { | |
const last = args[args.length - 1]; | |
if (typeof last === "function") { //callback | |
cbMap[cbUid] = last; | |
args[args.length - 1] = "callback-" + cbUid; | |
cbUid++; | |
} | |
return preSend.call(ipcRenderer, event, ...args); |
OlderNewer