This file contains 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
load('http://olado.github.io/doT/doT.min.js'); | |
// USAGE | |
//1. Compile template function | |
// var tempFn = doT.template("<h1>Here is a sample template {{=it.foo}}</h1>"); | |
// 2. Use template function as many times as you like | |
// var resultText = tempFn({foo: 'with doT'}); | |
// INTERPOLATION. |
This file contains 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
// | |
// https://github.com/janl/mustache.js | |
// Logic-less templates | |
// | |
load('https://cdn.jsdelivr.net/mustache.js/0.8.1/mustache.js'); | |
view = { | |
title: "Joe", | |
calc: function () { | |
return 2 + 4; | |
} |
This file contains 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://mathjs.org | |
// An extensive math library for JavaScript and Node.js | |
// here is a port of http://mathjs.org/examples/basic_usage.js.html | |
// | |
load('http://cdnjs.cloudflare.com/ajax/libs/mathjs/1.2.0/math.min.js') | |
function json(x) { return JSON.stringify(x); } |
This file contains 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
// | |
// four different ways to check if a variable is an integer | |
// from stackoverflow | |
// http://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript | |
// | |
//Raw solution | |
function isInt1(value) { | |
return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10)); | |
} |
This file contains 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://Ramdajs.org - a functional library | |
// | |
load('https://cdnjs.cloudflare.com/ajax/libs/ramda/0.14.0/ramda.js'); | |
incr = R.add(1); | |
x = incr(10); | |
if (x !== 11) throw ''; | |
x = R.all(function(x) { return x%2==0; },[1,2,3,4]); | |
if (x !== false) throw ''; | |
x = R.any(function(x) { return x%2==0; },[1,2,3,4]); |
This file contains 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://xtype.js.org | |
// Elegant, highly efficient data validation for JavaScript | |
// | |
load('https://rawgit.com/lucono/xtypejs/master/xtype.js'); | |
x = xtype.isSingleCharString('g') | |
if (x !== true) throw ''; | |
x = xtype.isNonEmptyObject({foo: 'bar'}) | |
if (x !== true) throw ''; |
This file contains 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
// | |
// Basic Show n Tell for jade. See: http://jade-lang.com/ | |
// | |
load('https://cdn.jsdelivr.net/jade/1.3.1/jade.min.js'); | |
f = jade.compile('b bold'); | |
s = f(); | |
if (s != '<b>bold</b>') throw ''; | |
This file contains 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
// | |
// A compiler for the Mustache templating language | |
// http://twitter.github.com/hogan.js | |
// | |
load('https://cdnjs.cloudflare.com/ajax/libs/hogan.js/3.0.2/hogan.js'); | |
data = { | |
screenName: "dhg" | |
}; |
This file contains 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
// | |
// https://github.com/marak/Faker.js/ - | |
// Generate massive amounts of fake contextual data | |
// | |
load('https://cdnjs.cloudflare.com/ajax/libs/Faker/0.7.2/MinFaker.js'); | |
from = new Date(1990, 1,1); | |
to = new Date(2000, 1,1); | |
date = Faker.Date.between(from, to); | |
if (date > from) throw '' |
This file contains 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
// | |
// neural networks in javascript | |
// https://github.com/harthur/brain | |
// | |
load('http://harthur.github.io/brain/brain-0.6.3.js'); | |
net = new brain.NeuralNetwork(); | |
net.train([{input: [0, 0], output: [0]}, | |
{input: [0, 1], output: [1]}, |