Skip to content

Instantly share code, notes, and snippets.

Matthew Mueller matthewmueller

Block or report user

Report or block matthewmueller

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@matthewmueller
matthewmueller / Underscore templating with Express
Created Mar 25, 2011
Javascript: Use underscore templating to parse HTML files in Express
View Underscore templating with Express
// Express with Underscore templating
app.register('.html', {
compile : function(str, options) {
return function(locals) {
return _.template(str, locals);
};
}
});
@matthewmueller
matthewmueller / gist:2018609
Created Mar 11, 2012
Javascript: after(len) - counter used for async iteration
View gist:2018609
/*
Counter used for async calls
Example:
var files = ['a', 'b'];
finished = after(files.length);
finished() // false
finished() // true
@matthewmueller
matthewmueller / gist:2018660
Created Mar 11, 2012
Javascript: step(fns...) - Tiny, flexible step function for running async functions in series
View gist:2018660
/*
Step - tiny, but flexible step library
Usage:
var first = function(next) {
...
return next(null, name, date);
}
View gist:2641307
#!/usr/bin/env node
var nom = require('nom'),
join = require('path').join,
args = process.argv.slice(2);
if(!args[0]) {
console.log('Usage: read <url>');
process.exit(0);
}
@matthewmueller
matthewmueller / express-layout.js
Created Jun 14, 2012
Basic, synchronous way of supporting layouts in express 3.x
View express-layout.js
app.engine('mu', function(path, options, fn) {
var views = app.get('views'),
view = path;
if(options.layout) {
view = join(views, '..', options.layout);
options.body = fs.readFileSync(path, 'utf8');
}
cons.hogan(view, options, function(err, str) {
@matthewmueller
matthewmueller / express-layout.js
Created Jun 14, 2012
Basic, synchronous way of supporting layouts in express 3.x
View express-layout.js
app.engine('mu', function(path, options, fn) {
var views = app.get('views'),
view = path;
if(options.layout) {
// Assumes layouts and views are at same level
view = join(views, '..', options.layout);
options.body = fs.readFileSync(path, 'utf8');
}
@matthewmueller
matthewmueller / index.js
Created Jun 24, 2012
Javascript: express 3 boilerplate
View index.js
var express = require('express'),
cons = require('consolidate'),
port = process.argv[2] || 8080,
app = express();
app.engine('html', cons.hogan);
app.set('view engine', 'html');
app.set('views', __dirname);
app.configure(function() {
@matthewmueller
matthewmueller / toggle.js
Created Aug 12, 2012
Toggle between two or more functions
View toggle.js
/**
* toggle between n functions
*
* Example:
*
* var a = function(p) { console.log("a:", p); };
* var b = function(p) { console.log("b:", p); };
*
* var func = toggle(a, b);
* func('hi') // => "a: hi"
View clean.js
/**
* Written by Jonathan Bolster
* Blog Post: http://bolsterweb.com/2011/10/how-clean-is-your-window-object/
*/
(function(window){
var keys = {},
cleanWindow,
iframe = document.createElement("iframe");
iframe.style.display ="none";
@matthewmueller
matthewmueller / bind.js
Created Aug 25, 2012
super basic bind function
View bind.js
function __bind(fn, context) {
return function() {
return fn.apply(context, arguments);
};
}
You can’t perform that action at this time.