Skip to content

Instantly share code, notes, and snippets.

View sanketmaru's full-sized avatar
🎧
Code & Music -- Infinite Loop

Sanket Maru sanketmaru

🎧
Code & Music -- Infinite Loop
View GitHub Profile
@sanketmaru
sanketmaru / template.js
Created September 30, 2015 06:30
template function
function getValidationData(param, param1){
return {
pattern:param,
data: param1,
}
}
getValidationData.apply(this, [param, param1]);
@sanketmaru
sanketmaru / flyweight.js
Last active September 17, 2015 06:04 — forked from addyosmani/flyweight.js
The Flyweight pattern
// Flyweight.js - Copyright Addy Osmani, 2012.
// Consider public domain
// My implementation in JS of this:
// http://en.wikipedia.org/wiki/Flyweight_pattern
// Simulate pure virtual inheritance/'implement' keyword for JS
Function.prototype.implementsFor = function (parentClassOrObject) {
if (parentClassOrObject.constructor == Function) {
// Normal Inheritance
this.prototype = new parentClassOrObject;
@sanketmaru
sanketmaru / composition.md
Last active September 17, 2015 05:53 — forked from addyosmani/composition.md
JS Musings

Composition

On an architectural level, the way we craft large-scale applications in JavaScript has changed in at least one fundamental way in the last four years. Once you remove the minutia of machinery bringing forth data-binding, immutable data-structures and virtual-DOM (all of which are interesting problem spaces) the one key concept that many devs seem to have organically converged on is composition. Composition is incredibly powerful, allowing us to stitch together reusable pieces of functionality to "compose" a larger application. Composition eschews in a mindset of things being good when they're modular, smaller and easier to test. Easier to reason with. Easier to distribute. Heck, just look at how well that works for Node.

Composition is one of the reasons we regularly talk about React "Components", "Ember.Component"s, Angular directives, Polymer elements and of course, straight-up Web Components. We may argue about the frameworks and libraries surrounding t

@sanketmaru
sanketmaru / word-cloud-data.js
Created August 5, 2015 12:06
You want to build a word cloud, an infographic where the size of a word corresponds to how often it appears in the body of text.
var inputString = 'We came, we saw, we conquered...then we ate Bill\'s (Mille-Feuille) cake.'
function(inputString){
var words = [];
for(var i=0;i<inputString.length;i++){
var word = [];
var stringElem = inputString[i];
word.push(stringElem);
if(stringElem === ' ' || stringElem === ',' ){ // marks the end of word
words.push(word);
@sanketmaru
sanketmaru / weight-problem.js
Created August 5, 2015 02:26
Solution to weight puzzle.
(function(){
var w1,w2,w3,w4;
//w1+w2+w3+w4 = 40;
// applying a brute force approach
for(w1=1;w1<40;w1++){
for(w2=1;w1<40;w2++){
for(w3=1;w3<40;w3++){
@sanketmaru
sanketmaru / promise-sync-example.js
Last active July 20, 2016 12:06
promise-sync-example
Promise.map(emailParams,function(emailParam) {
logger.info('sending email to sendmail for %j', emailParam, {});
var host = "www.example.com/";
var html = jadeS.renderFile(template, {
farms: emailParam.farms,
headerImage: "image",
heading: emailParam.heading,
fieldFocusUrl: "someurl",
host: host
});
@sanketmaru
sanketmaru / isolated_scopes
Created July 27, 2015 16:53
Angular JS isolated scopes
JSFiddle demonstrating the isolated scopes
http://jsfiddle.net/juanmendez/k6chmnch/
@sanketmaru
sanketmaru / links
Created July 7, 2015 12:27
javascript links
@sanketmaru
sanketmaru / levenstein
Last active August 29, 2015 14:22
levenstein distance
// code has been copied from http://rosettacode.org/wiki/Levenshtein_distance#Java
package main.java;
public class Levenstein {
public static int distance(String a, String b) {
a = a.toLowerCase();
b = b.toLowerCase();
// i == 0
@sanketmaru
sanketmaru / prototype-methods
Created May 21, 2015 03:10
Methods Constructor functionvs vs prototypes
Below is the jsperf test which creates instances when methods are defined inside constructor methods vs in prototype object.
Methods defined in prototype object is faster as each instance shares the same prototype object thats with the constructor function.
http://jsperf.com/prototype-vs-constructor-methods