Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am skeate on github.
  • I am skeate (https://keybase.io/skeate) on keybase.
  • I have a public key ASAPiJ3LR-xVyxGOnXl_bKoL2z0kycl9QUZhe_tacTvqxAo

To claim this, I am signing this object:

@skeate
skeate / gist:2917e5d13a7b98282af9
Last active August 29, 2015 14:23
Javascript chainable if
Object.prototype.if = function(cond) {
var self = this;
var wrapFunc = function(f) {
return function() {
if (cond) {
return f.apply(self, arguments);
} else {
return self;
}
};
@skeate
skeate / compile.js
Last active August 29, 2015 13:58
Underscore template precompiling script. Compiles any .html files into templates.js. Include the file and templates can be run with templates["filename"](data).
var _ = require("underscore")._;
var fs = require("fs");
fs.readdir(".", function(err,files){
fs.writeFileSync('./templates.js',"templates={};"+
files
.filter(function(f){return f.substr(-5) == ".html"})
.map(function(f){return {name:'templates["'+f.substr(0,f.length-5)+'"]',source:fs.readFileSync(f).toString()};})
.map(function(s){return s.name+"="+_.template(s.source).source+";";})
.join('')