Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
@boutell
boutell / static.js
Created December 31, 2012 22:39
express.static middleware must be added before any routes are added to the project, which is potentially confusing when constructing reusable modules to be added to projects as needed. I wish app.use() behaved as just another route for precedence purposes
// HOPED-FOR BEHAVIOR: both /cats.txt AND /cats/cats.txt say: Cats Static
// ACTUAL BEHAVIOR: /cats.txt says Cats Static, but /cats/cats.txt says: Main Wildcard
var express = require('express');
var fs = require('fs');
var app = express();
// Adding the static middleware at the beginning means it wins out over any routes present
// (but only interferes if the file exists)
@boutell
boutell / nestedapps.js
Created December 31, 2012 22:41
Nested Express apps. The "Main Wildcard" route always beats all routes in catsApp even though it is added first with app.use. I wish app.use() had the same precedence as adding a route.
// HOPED-FOR BEHAVIOR: /cats says: Cats Home
// ACTUAL BEHAVIOR: /cats says: Main Wildcard
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Main Home');
})
app/console dukelist:migrate-legacy-database --env=prod
@boutell
boutell / gist:4614579
Created January 23, 2013 22:12
Nightly cron job to clean up dukelist postings
/var/www/dukelist/app/console dukelist:cleanup --env=prod
(cd /var/www/dukelist && ./app/console dukelist:cleanup --env=staging)
(cd /var/www/dukelist && ./app/console dukelist:cleanup --env=prod --send-emails)
./symfony doctrine:build --all --db --env=prod
./symfony project:sync-content frontend prod from staging@staging
@boutell
boutell / gist:5024073
Created February 24, 2013 14:40
gitc: the all-purpose "add and commit and merge and push and just DO ALL THE THINGS" git command
alias gitc='git add -A . && git commit && git pull && git push'
@boutell
boutell / gist:5409228
Created April 18, 2013 01:31
Piping a knox S3 http response (an input stream) to an output file, reliably detecting error and invoking a completion callback
var res = // Any input stream
var out = fs.createWriteStream(localPath);
res.pipe(out);
var dead = false;
function die(err) {
if (!dead) {
dead = true;
res.end();
out.end();
return callback(err);
@boutell
boutell / gist:5412937
Created April 18, 2013 14:02
How do I make my object an event emitter/receiver?
function Thing() {
var self = this;
// Thing is now an event emitter/receiver
require('events').EventEmitter.call(self);
}
var thing = new Thing();
thing.emit('foo');