Skip to content

Instantly share code, notes, and snippets.

#!/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 June 14, 2012 00:29
Basic, synchronous way of supporting layouts in express 3.x
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 June 14, 2012 00:30
Basic, synchronous way of supporting layouts in express 3.x
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 June 24, 2012 22:05
Javascript: express 3 boilerplate
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 August 12, 2012 07:14
Toggle between two or more functions
/**
* 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"
@matthewmueller
matthewmueller / lazy-load-redux-action.js
Last active October 9, 2015 01:56
Non-working lazy-load redux action. The reason it doesn't work is because webpack cannot resolve dynamic paths (without assistance). Makes sense to create a loader like `react-proxy-loader` that will generate this. Then you can stick this in middleware and be done.
/**
* Module Dependencies
*/
var relative = require('path').relative
/**
* Action
*/
@matthewmueller
matthewmueller / clean.js
Created August 22, 2012 22:56
Clean window
/**
* 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 August 25, 2012 02:32
super basic bind function
function __bind(fn, context) {
return function() {
return fn.apply(context, arguments);
};
}
@matthewmueller
matthewmueller / index.js
Created September 5, 2012 03:39
vhost on separate paths
var express = require('express'),
app = module.exports = express();
app.use('/a', express.vhost('*', require('./a')));
app.use('/b', express.vhost('*', require('./b')));
app.listen(8080);
@matthewmueller
matthewmueller / index.js
Created October 10, 2015 09:24
redux reduxed
var Debug = require('redux-debug')
var debug = require('debug')
var assign = require('object-assign')
var thunk = require('redux-thunk')
var Redux = require('redux')
function store_enhancer (options) {
return function (next) {
return function (reducer, initial_state) {