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 / 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, 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 / 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)
@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 / test.js
Last active September 6, 2016 16:04
Object function serialize and deserialize
let obj = {
id: 14521,
name: 'Annamalai',
notify:function(){
console.log(`Hallo ${this.name} ! Your ID is ${this.id}`)
}
}
//obj.notify();
@asvny
asvny / timelapse.sh
Created September 27, 2016 02:48 — forked from aemkei/timelapse.sh
Create a Timelapse with ffmpeg
ffmpeg -framerate 25 -f image2 -pattern_type glob -i "*.JPG" -s:v 1920x1440 -c:v libx264 -r 25 ../timelapse.mp4
@asvny
asvny / components.ui-input.js
Last active June 10, 2017 03:59
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
classNames:['ui-input'],
classNameBindings:[
'isFilled:has-value'
],
currentValue: '',
isFilled: Ember.computed.notEmpty('currentValue'),
});
@asvny
asvny / controllers.application.js
Last active October 3, 2016 12:06
multiple checkbox
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
checked:[],
grp: [
{ d: 'a' , v: false },
{ d: 'b' , v: false },
{ d: 'c' , v: false },
{ d: 'd' , v: false }
@asvny
asvny / sw-multiplex.js
Created March 4, 2017 09:36 — forked from ghaiklor/sw-multiplex.js
Multiplexing downloads via Service Workers
/**
* Size of one chunk when requesting with Range
* @type {Number}
* @private
*/
const CHUNK_SIZE = 204800;
/**
* Concat two ArrayBuffers
* @param {ArrayBuffer} ab1
@asvny
asvny / custom-fonts.js
Created March 20, 2017 11:26
fetch custom fonts from page
[...document.styleSheets[0].rules].filter(sel => sel.cssText.startsWith('@font-face') ).map(sel =>sel.style.fontFamily)