Skip to content

Instantly share code, notes, and snippets.

View robdodson's full-sized avatar
🏠
Working from home

Rob Dodson robdodson

🏠
Working from home
View GitHub Profile
function test(arg){
return arg + arg;
}
function testDecorator(fn, args){
var arg = args[0] * 2;
return fn(arg);
}
@robdodson
robdodson / snippets.js
Created August 31, 2012 20:21
y combinator
/**
* Creates a recursive function from one that isn't
* @param {Function} x A non-recursing function
* @return {Function} A recursive version of x
*/
function yCombinator(x) {
return (function(procedure) {
return x(function(arg) {
return procedure(procedure)(arg);
});
@robdodson
robdodson / snippets.js
Created August 31, 2012 20:38
wrapper
/**
* Wraps a `Function` with another `Function`. This allows
* the wrapper function to intercept and manipulate the
* return value of the orginal function.
* @param {Function} fn The function to wrap
* @param {Function} wrapper The wrapper function
* @return {Function} Return the wrapped function
*/
function wrap(fn, wrapper) {
return function() {
@robdodson
robdodson / d3.csv.js
Created October 10, 2012 19:19
Getting column names with d3.csv
<script type="text/javascript">
/*
Example cars.csv:
Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38
*/
@robdodson
robdodson / app.js
Created October 17, 2012 21:34
middleware
app.configure(function(){
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
// app.use(express.basicAuth( function( user, pass ) {
// return 'COE' == user && 'b0gu5' == pass;
// }));
app.use(express.bodyParser());
app.use(express.methodOverride());
@robdodson
robdodson / static.js
Created October 17, 2012 21:39
static.js
exports = module.exports = function static(root, options){
options = options || {};
// root required
if (!root) throw new Error('static() root path required');
options.root = root;
return function static(req, res, next) {
console.log('!!! STATIC HIT !!!');
console.log(req.path);
@robdodson
robdodson / app.js
Created October 17, 2012 21:54
routes
app.resource("data/post", PostResource);
app.resource("data/author", AuthorResource);
app.resource("data/media", MediaResource);
// additional post routes
app.delete('/data/post', PostResource.destroy_all);
app.delete ('/data/author', AuthorResource.destroy_all);
app.delete ('/data/media', MediaResource.destroy_all);
@robdodson
robdodson / app.js
Created October 17, 2012 22:07
proxy
httpProxy.createServer(function(req,res,proxy) {
if (req.url.match(/\/data/)) {
console.log('data');
proxy.proxyRequest(req, res, {
host: config.DATA_APP_HOST,
port: config.DATA_APP_PORT
});
} else if (req.url.match(/\/wordpress/)) {
console.log('wordpress');
proxy.proxyRequest(req, res, {
[
{
"args":
{
"to": "eol"
},
"command": "move_to"
},
{
"args":
@robdodson
robdodson / Default (OSX).sublime-keymap
Created January 12, 2013 17:08
insert-semicolon-keyboard
{ "keys": ["super+;"], "command": "run_macro_file", "args": { "file": "Packages/User/insert-semicolon.sublime-macro" } },