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 / 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) {

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">
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,
@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));
});
@asvny
asvny / app.js
Created May 10, 2016 11:46 — forked from arvis/app.js
Basic express and mongoose CRUD application
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, mongoose = require('mongoose')
, path = require('path');
@asvny
asvny / async.js
Created April 1, 2016 09:59
async in js
function async(genFunc) {
var gen = genFunc();
function step(value) {
var next = gen.next(value);
var promise = next.value;
return promise
.then((v) => {
if (!next.done) {
step(v);
}
const code = `clicking on ".container" add class "active" on it`;
//
const compose = (...funcs) => value => funcs.reduceRight((a, b) => b(a), value);
const flatten = (arr) => { return Array.isArray(arr) ? [].concat.apply([], arr) : [arr] };
const findBlocks = () => {
let codeBlocks = [...document.querySelectorAll('code')];
// return codeBlocks.map(codeBlock => codeBlock.textContent.trim())
var t = 'The quick brown fox jumped over the lazy dog' ;
const longestWord = (input) => {
let arr = input.split(' ');
let arrL = arr.map((word)=>word.length);
let max=arrL.reduce((prev,curr,i)=> curr > prev ? i : prev,0);
return arr[max];
}
@asvny
asvny / blogServiceWorker.js
Created December 21, 2015 08:33 — forked from adactio/blogServiceWorker.js
A Service Worker to progressively enhance a blog by storing assets in a cache, and keeping limited caches of pages and images for offline browsing.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// A cache for core files like CSS and JavaScript
var staticCacheName = 'static';
// A cache for pages to store for offline
@asvny
asvny / basicServiceWorker.js
Created December 21, 2015 08:32 — forked from adactio/basicServiceWorker.js
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';