Skip to content

Instantly share code, notes, and snippets.

View huang-x-h's full-sized avatar
💭
I may be slow to respond.

huang.xinghui huang-x-h

💭
I may be slow to respond.
View GitHub Profile
@huang-x-h
huang-x-h / argumentNames.js
Last active August 29, 2015 14:07
get function arguments name
// 摘自Secrets of the JavaScript Ninja
function argumentNames(fn) {
var found = /^[\s\(]*function[^(]*\(\s*([^)]*?)\s*\)/.exec(fn.toString());
return found && found[1] ? found[1].split(/,\s*/) : [];
}
argumentNames(function(x){})[0] === "x"
@huang-x-h
huang-x-h / unix-crontab.md
Created April 20, 2016 01:58
Unix Crontab

Unix Crontab

Introduction

cron is a utility that you can use to schedule and automate tasks. By defining items in the cron table, called crontab, you can schedule any script or program to run on almost any sort of schedule. For example, Research [Flagship Merchant Services][1] on Thursday at 6:30pm.

For example, run a [program][2] each day 5 minutes after midnight on mondays, wednesdays and fridays. Or schedule something to run every five minutes, or once a month.

Basics

@huang-x-h
huang-x-h / promise.js
Created September 1, 2016 14:47
Promise.eachLimit
function createArrayIterator(coll) {
var i = -1;
var len = coll.length;
return function next() {
return ++i < len ? {value: coll[i], key: i} : null;
}
}
function eachLimit(coll, limit, iteratee) {
if (limit <= 0 || !coll) return Promise.resolve();
@huang-x-h
huang-x-h / asyncMemoize.js
Last active March 29, 2018 02:21
Memoize an async function by storing its results
function defaultHasher() {
return JSON.stringify(arguments);
}
function asyncMemoize(fn, hasher=defaultHasher) {
async function memozie() {
let cache = memozie.cache;
const key = hasher(arguments);
if (!cache.hasOwnProperty(key)) {