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 / Middleware.js
Created May 27, 2016 12:00 — forked from darrenscerri/Middleware.js
A very minimal Javascript (ES5 & ES6) Middleware Pattern Implementation
var Middleware = function() {};
Middleware.prototype.use = function(fn) {
var self = this;
this.go = (function(stack) {
return function(next) {
stack.call(self, function() {
fn.call(self, next.bind(self));
});
var timing = performance.timing;
var requestEntries = performance.getEntries();
var perfData = {
PageName: window.location.pathname,
JSFilesCount: requestEntries.filter(function(element){return element.name.indexOf('.js')> -1;}).length,
CSSFilesCount: requestEntries.filter(function(element){return element.name.indexOf('.css')> -1;}).length,
FilesCount: requestEntries.length + 1,
TimeToFirstByte: timing.responseStart - timing.navigationStart,
TimeToDOMContentLoad:
timing.domContentLoadedEventEnd - timing.navigationStart,

URLs into Indexed DB, via Service Workers

Let's say you're using Indexed DB for the offline data store for a catalog. One of the object stores contains product images. Wouldn't it be great if you could just have something like this in your catalog page?

<img src="indexeddb/database/store/id">
@asvny
asvny / gist:dd9aefc524f11d97fe6755bd7ac44246
Created June 29, 2016 15:27 — forked from nakamura-to/gist:2144314
Visitor Pattern in JavaScript
// see http://d.hatena.ne.jp/ashigeru/20090113/1231855642
var calc = {
add: function (node) {
return visit(this, node.l) + visit(this, node.r);
},
sub: function (node) {
return visit(this, node.l) - visit(this, node.r);
},
val: function (node) {
/*\
title: $:/plugins/sukima/dombuilder/dombuilder.js
type: application/javascript
module-type: library
Micro DSL for DOM creation and stringification.
\*/
/**
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());
@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
@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 / 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) {
function throttle(fn, wait) {
var time = Date.now();
return function() {
if ((time + wait - Date.now()) < 0) {
fn();
time = Date.now();
}
}
}