Table of Contents generated with DocToc
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
// pre-ES6 | |
function _ary(fn, arity) { | |
arity = arity || 1; | |
return function() { | |
// could use Array.from(arguments).slice(0, arity) ? | |
var args = Array.prototype.slice.call(arguments, 0, arity); | |
return fn.apply(null, args); | |
}; | |
} |
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
/** | |
* @license MIT | |
* @requires AngularJs 1.x | |
* @author github.com/tincho | |
* Tiny helper for listener deregistration on scope destroy | |
* You'll have to wrap it up in a module/provider/whatever | |
* (that's out of my focus) | |
*/ | |
function LDisposer(scope) { | |
var _list = []; |
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
// first iteration | |
// v0.1 | |
(function(globalObject, document) { | |
function randomItem(collection) { | |
var index = Math.floor(Math.random() * collection.length); | |
return collection[index]; | |
} |
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
// var logHello = _partial(console.log, "hello "); | |
// logHello("world"); | |
// accepts _partial (fn reference) as placeholder just like underscore accepts _ | |
// var partialApplied = _partial(originalFn, _partial, "second", _partial, "fifth"); | |
// partialApplied("first", "third") will call originalFn("first", "second", "third", "fifth") | |
function _partial() { | |
var args = Array.prototype.slice.call(arguments); | |
var method = args.shift(); | |
var self = this; |
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
var form = document.getElementById("dlFile"); | |
form.onsubmit = function(e) { | |
e.preventDefault(); | |
var user = form.user.value; // "mayoristas"; | |
var pass = form.pass.value; | |
requestFile(user, pass); | |
return false; | |
} |
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
// requires jQuery! | |
const noop = () => {}; | |
const constant = v => () => v; | |
const beTrue = constant(true); // () => true; | |
function $Ajaxify(form, ...callbacks) { | |
if (typeof callbacks[0] === 'object') { | |
var { | |
onSuccess = noop, onError = noop, beforeSend = beTrue |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
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
// both answers copied from challange posted at e-mail list of my former job | |
// not-so oneliner | |
var compose = function () { | |
var composableFunctions = Array.prototype.slice.call(arguments).reverse(); | |
return (x) => composableFunctions.reduce((result, composable) => composable(result), x); | |
/* | |
ES5: | |
return function(x) { | |
return composableFunctions.reduce(function(result, composable) { |
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 getData(uri, done, evt) { | |
var request = new XMLHttpRequest(); | |
request.open('GET', uri); | |
request.onreadystatechange = function() { | |
if(! (request.readyState == 4 && request.status === 200)) { | |
return; | |
} | |
return done(request); |