Skip to content

Instantly share code, notes, and snippets.

View asvny's full-sized avatar
🎯
Focusing

Annamalai Saravanan asvny

🎯
Focusing
View GitHub Profile
@asvny
asvny / flatten.js
Created August 22, 2016 15:01
functional flatten
const flatten = xs => {
let next = (acc, xs) => xs.reduce((x, y) => Array.isArray(y)
? next(x, y)
: (x[x.length] = y, x)
, acc);
return next([], xs);
}
@asvny
asvny / FP_Observables.js
Created August 20, 2016 13:13 — forked from yelouafi/FP_Observables.js
Observables with pure FP
// Observable is an Union Type, with the following variants
const Empty = () => ['EMPTY']
const Cons = (head, tail) => ['CONS', head, tail]
const Future = promise => ['FUTURE', promise]
// race between 2 promises; each promise will resolve to a lazy value
const lazyRace = (p1, p2) => Promise.race([p1,p2]).then(lazy => lazy())
// function composition
const compose = (...fns) => (arg) => fns.reduceRight((res, f) => f(res), arg)
function throttle(fn, ms) {
var last = (new Date()).getTime();
return (function() {
var now = (new Date()).getTime();
if (now - last > ms) {
last = now;
fn.apply(null, arguments);
}
});
}
@asvny
asvny / iterators.js
Created August 9, 2016 16:28 — forked from poetix/iterators.js
Lazy map, filter and reduce in Javascript
Iterators = (function() {
var each, map, filter, reduce, toArray, toObject;
function _map(iter, f) {
return {
hasNext: iter.hasNext,
next: function() { return f(iter.next()); }
};
}
function throttle(fn, wait) {
var time = Date.now();
return function() {
if ((time + wait - Date.now()) < 0) {
fn();
time = Date.now();
}
}
}
@asvny
asvny / scroller.js
Created August 9, 2016 01:04
scroll native js
function scrollIt(element, duration = 200, easing = 'linear', callback) {
// define timing functions
const easings = {
linear(t) {
return t;
},
easeInQuad(t) {
return t * t;
},
easeOutQuad(t) {
@asvny
asvny / normalize.js
Last active July 30, 2016 08:05
postcss-modules-normalize
const postcss = require('postcss');
const fs = require('fs');
const __isDEV__ = false;
const plugin = postcss.plugin('postcss-cssmodules-normalize', function (opts={}) {
return function (css, result) {
var selMap = new Map();
@asvny
asvny / statuses.md
Created July 11, 2016 21:56 — forked from vkostyukov/statuses.md
HTTP status codes used by world-famous APIs
API Status Codes
[Twitter][tw] 200, 304, 400, 401, 403, 404, 406, 410, 420, 422, 429, 500, 502, 503, 504
[Stripe][stripe] 200, 400, 401, 402, 404, 429, 500, 502, 503, 504
[Github][gh] 200, 400, 422, 301, 302, 304, 307, 401, 403
[Pagerduty][pd] 200, 201, 204, 400, 401, 403, 404, 408, 500
[NewRelic Plugins][nr] 200, 400, 403, 404, 405, 413, 500, 502, 503, 503
[Etsy][etsy] 200, 201, 400, 403, 404, 500, 503
[Dropbox][db] 200, 400, 401, 403, 404, 405, 429, 503, 507
function run(makeGenerator) {
return function() {
var generator = makeGenerator.apply(this, arguments);
var handle = function(p) {
if (p.done) return p.value;
return p.value.then(function(v) {
return handle(generator.next(v));
});
};
return handle(generator.next());
/*\
title: $:/plugins/sukima/dombuilder/dombuilder.js
type: application/javascript
module-type: library
Micro DSL for DOM creation and stringification.
\*/
/**