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
// 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
// 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
/** | |
* @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
// 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
function getHeader(url, header) { | |
return new Promise(function(resolve, reject) { | |
var http = new XMLHttpRequest(); | |
http.open('HEAD', url); | |
http.onreadystatechange = function() { | |
if (this.readyState !== this.DONE) return; | |
if (this.status != 200) { | |
reject(this.status); | |
} else { |
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
// make a data uri encoded image from a <video> element using canvas | |
// (thank you stackoverflow people) | |
function videoElementToImage(videoElement, width, height) { | |
width = width || 360; | |
height = height || 240; | |
var canvas = document.createElement('canvas'); | |
canvas.width = width; | |
canvas.height = height; | |
var context = canvas.getContext('2d'); | |
context.drawImage(videoElement, 0, 0, canvas.width, canvas.height); |
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
// iteration 0 | |
// adding deep diving for key paths | |
// based on getProperty() | |
// try on tddbin.com | |
function copyFrom(obj) { | |
const values = (...keys) => keys.map(k => getProperty(k)(obj)); | |
return { values }; | |
} |
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 shallowCompare = (obj1, obj2) => | |
typeof obj1 === 'object' && typeof obj2 === 'object' | |
? Object.keys(obj1).length === Object.keys(obj2).length && | |
Object.keys(obj1).every( | |
key => obj2.hasOwnProperty(key) && obj1[key] === obj2[key] | |
) | |
: obj1 === obj2 | |
const memoizeByProps = (...props) => Component => | |
React.memo(Component, (prevProps, nextProps) => |
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 loop = { | |
timer: null, | |
count: 0, | |
start(fn, time=1000, limit = 100) { | |
fn(this.stop.bind(this), this.count); | |
this.count++; | |
if (this.count < limit) { | |
this.timer = setTimeout(() => this.start(fn, time, limit), time) | |
} else { | |
this.stop() |