Skip to content

Instantly share code, notes, and snippets.

View alexeyraspopov's full-sized avatar
✍️
Working on something exciting

Oleksii alexeyraspopov

✍️
Working on something exciting
View GitHub Profile
@alexeyraspopov
alexeyraspopov / gulp-pipe.js
Created February 2, 2014 14:39
Simple way to write your pipes
module.exports = function(array){
return array.reduce(function(a, b){
return a.pipe(b);
});
};
<snippet>
<content><![CDATA[
${2:${1:module}} = require('${1:module}')$0
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>req</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
demethodize = Function.prototype.bind.bind(Function.prototype.call);
concat = demethodize(Array.prototype.concat);
curry = demethodize(Function.prototype.bind);
map = demethodize(Array.prototype.map);
function pick(property){
return (target) => target[property];
}
function property(target){
return (property) => target[property];
}
function invoke(method, args){
return (target) => target[method].apply(this, args);
demethodize = Function.prototype.bind.bind(Function.prototype.call);
slice = demethodize(Array.prototype.slice);
function limitTo(fn, limit){
return () => fn.apply(this, slice(arguments, 0, limit));
}
@alexeyraspopov
alexeyraspopov / main.js
Last active August 29, 2015 14:00
Как избавиться от лишних аргументов функции в итераторах
function compose(f, g){
return (...args) => f(g(...args));
}
function identity(value){
return value;
}
function process(...list){
// something to do
function mapReduce(map, reduce, zero){
return function loop(from, to){
if(from > to){
return zero;
}
return reduce(map(from), loop(from + 1, to));
};
}
function filter(fn){
var child = stream();
child.changed = function(old, value){
return fn(value);
};
return child;
}
function TodoVM(model){
this.title = observable(model.title);
this.completed = observable(model.observable)
}
filters = {
all: () => true,
active: (todo) => !todo.completed(),
completed: (todo) => todo.completed()
};
provider = typeof window === 'object' && window.performance || Date;
timestamp = typeof provider.now === 'function' ? provider.now.bind(provider) : function(){ return +new Date(); };