This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getValidationData(param, param1){ | |
return { | |
pattern:param, | |
data: param1, | |
} | |
} | |
getValidationData.apply(this, [param, param1]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSFiddle demonstrating the isolated scopes | |
http://jsfiddle.net/juanmendez/k6chmnch/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://thatjsdude.com/interview/js2.html | |
http://code.tutsplus.com/articles/master-developers-addy-osmani--net-31661 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |