(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.
| /** | |
| * vainilla js simple slider | |
| * source: http://cssdeck.com/labs/image-slider-1 | |
| */ | |
| /** | |
| css: | |
| .image-slider-wrapper{ | |
| overflow: hidden; | |
| } |
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| import datetime | |
| import sys | |
| def compare(dates): | |
| if len(dates) < 2: |
| function _noop() {} | |
| function _constant(v) { return function() { return v; }; } | |
| /** | |
| * intercept <form> and submit it via XHR | |
| * @param {String} formSelector | |
| * @param {Function} successCallback | |
| * @param {Function} errorCallback | |
| * @param {Function} beforeSubmit | |
| */ |
| /** | |
| * Prefixes each array element with given | |
| * @param {String} prefix | |
| * @usage e.g var pfixed = ["one", "two", "three"].prefixEach("number: "); | |
| */ | |
| Array.prototype.prefixEach = function(prefix) { | |
| return this.map(_ary(String.prototype.concat.bind(prefix))); | |
| }; | |
| function _ary(fn, arity) { |
| /** | |
| * replaces variables in element innerHTML, e.g. | |
| * DOM: <span id="fillMe">hey {{#}}, whats up {{#}}</span> | |
| * Code: document.querySelector('#fillMe').fillWith('bro') | |
| * Output: hey bro, whats up bro | |
| * | |
| * DOM: <span id="fillMe">the {{animal}} is sitting at the {{forniture}}</span> | |
| * Code: document.querySelector('#fillMe').fillWith({'animal': 'cat', 'forniture': 'table'}); | |
| * Output: the cat is sitting at the table | |
| */ |
| 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); |
| // 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) { |
| // 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; |
(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.
| /* | |
| why fixDate? | |
| if we create a JS Date writing: | |
| var d = new Date("2015-05-15") | |
| we are not specifying any timezone | |
| the browser/environment will asume it is UTC+000, | |
| and always represent it in user's LOCAL TIMEZONE! | |
| so, running in an environment located in a UTC-3 zone, | |
| d would actually show 2015-05-14 at 21:00 | |
| and may lead to errors. |