Skip to content

Instantly share code, notes, and snippets.

@benben77
benben77 / js-function-utils
Created May 11, 2015 09:48
JS Function Utils: debounce, throttle, curry, memorize
window.FunctionHelpers = {
debounce: function(fn, threshold, execASAP) {
var timeout = null;
threshold = threshold || 100;
return function() {
var self = this;
var args = arguments;
var delayed = function() {
if (!execASAP) {
fn.apply(self, args);
@benben77
benben77 / js-countdown
Created May 11, 2015 09:52
JS util for generate countdown string
(function(define) {
var SECONDS = {
second: 1,
minute: 60
};
SECONDS.hour = SECONDS.minute * 60;
SECONDS.day = SECONDS.hour * 24;
SECONDS.week = SECONDS.day * 7;
var TIME_ARR = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'],
TIME_ARR2 = TIME_ARR.slice(2);
@benben77
benben77 / js-micro-template
Created May 11, 2015 10:03
JS Micro Template
// http://ejohn.org/blog/javascript-micro-templating/ by John Resig
(function(w){
var cache = {};
w.tmpl = function tmpl(str){
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +