Skip to content

Instantly share code, notes, and snippets.

View davidbanham's full-sized avatar

David Banham davidbanham

View GitHub Profile
@davidbanham
davidbanham / gist:1186032
Created September 1, 2011 12:02
Dynamically generate a file download in express without touching the filesystem
var express = require('express');
var app = require('express').createServer();
app.listen('3030');
app.get('/', function(req, res) {
res.contentType('text/plain');
res.send('This is the content', { 'Content-Disposition': 'attachment; filename=name.txt' });
});
.printonly {
display: none;
}
@media print {
.noprint, nav, footer {
display: none;
}
.printonly {
display: block;
package main
import (
"context"
"crypto/tls"
"fmt"
"log"
"net/http"
"os"
"strings"
@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 / Infinite_Gist.js
Last active December 21, 2015 09:07
Infinite Gist
while (true) {console.log('Man, you know I can\'t eat your ghost chups.')}
@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);