Skip to content

Instantly share code, notes, and snippets.

View davidbanham's full-sized avatar

David Banham davidbanham

View GitHub Profile
@davidbanham
davidbanham / gist:9757890
Created March 25, 2014 09:14
Test scripts
A common way to write your test script in a package.json is:
"scripts": {
"test": "mocha"
},
But that expects the user to have mocha (or karma, etc) installed globally. A more portable way to do it is call the locally installed runner directly:
"scripts": {
"test": "./node_modules/.bin/mocha"
@davidbanham
davidbanham / keybase.md
Created March 17, 2014 06:48
keybase.md

Keybase proof

I hereby claim:

  • I am davidbanham on github.
  • I am davidbanham (https://keybase.io/davidbanham) on keybase.
  • I have a public key whose fingerprint is 8428 8E68 6C9A DC59 EC48 CBFA 13F6 3D81 CDB8 59E6

To claim this, I am signing this object:

@davidbanham
davidbanham / rack-angular-xsrf.rb
Last active December 1, 2016 14:34
Angular XSRF rack middleware
class TokenAdder
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
response = Rack::Response.new body, status, headers
@davidbanham
davidbanham / wrapper.js
Created January 28, 2014 22:34
A wrapper to run your .coffee files via node
// Include the CoffeeScript interpreter so that .coffee files will work
var coffee = require('coffee-script');
// Explicitly register the compiler if required. This became necessary in CS 1.7
if (typeof coffee.register !== 'undefined') coffee.register();
// Include our application file
var app = require(process.argv[2] || './app.coffee');
#Sometimes I want to munge data that I've pulled from a backend with Angular. The Promises implementation augments the object with it's own $properties and I don't want to munge those.
app = angular.module 'GetOffMyLawn'
app.controller 'DangKids', ($scope, $resource) ->
Wat = $resource '/wat'
Wat.get {}, (data) ->
#data is something like { foo: {something: 1, somethingElse: 2} }
@davidbanham
davidbanham / gist:7478238
Created November 15, 2013 02:37
Go dir structure
.
├── bin
│   └── gotour
├── pkg
│   └── darwin_amd64
│   └── code.google.com
└── src
├── code.google.com
└── github.com
└── davidbanham
@davidbanham
davidbanham / gist:5927279
Created July 4, 2013 12:29
Aggregate a stream
var http = require('http');
opts = {
domain: 'google.com'
}
http.get(opts, function(res) {
response = ''
res.on('data', function(data) {
response += data.toString()
}
res.on('end', function() {
@davidbanham
davidbanham / gist:5617210
Created May 21, 2013 02:50
Too something to fail.
var upnode = require('../');
var dnode = require('dnode');
var test = require('tap').test;
var net = require('net');
test('simple', function (t) {
t.plan(1);
var port = Math.floor(Math.random() * 5e4 + 1e4);
var up = upnode.connect(port);
@davidbanham
davidbanham / gist:5204449
Last active December 15, 2015 04:50
Example of couchdb array keys
// Design Doc:
{
"_id": "_design/things",
"_rev": "3-c05af422e754a6734d1843e309fa1135",
"language": "javascript",
"views": {
"filter": {
"map": "function(doc) { emit([doc.country, doc.city], doc); }"
}
@davidbanham
davidbanham / gist:4527127
Created January 14, 2013 01:17
Express coffee shim
// Include the CoffeeScript interpreter so that .coffee files will work
var coffee = require('coffee-script');
// Include our application file
var app = require('./app.coffee');