Skip to content

Instantly share code, notes, and snippets.

fredrick /
Created Mar 15, 2011
Dynamically define object variables/methods at instantiation (quick mock)
class Stub(object):
def __init__(self, **kwargs):
for key in kwargs:
setattr(self, key, kwargs[key])
View gist:979302
# This is a nginx config snippet showing how to inherit an http header
# or defaulting it to a specific value. This is useful because it allows
# upstream load balancers to set specific headers, but if they're missing
# the app LB will know how to default it.
# This will inherit the previously set X-Scheme variable, or otherwise
# default it to the current `$scheme`. Requires nginx 0.9.0+.
# Docs:
map $http_x_scheme $x_scheme {
View tumblrGists.js
var gistPrefix = '',
cachedWrite = document.write,
body = $('body'),
gists = $('p.gist').map(function(n, p) {
p = $(p);
var a = $('a', p),
href = a.attr('href');
if (a.length && href.indexOf(gistPrefix) == 0) {
fredrick /
Created Nov 22, 2011
Graylog2 Upstart Jobs

#Graylog2 Upstart

A basic set of Upstart jobs to get Graylog2 up and running quickly. Assumes MongoDB and Graylog2 installed in /opt/. Tested on Ubuntu Server 10.04 LTS, MongoDB 2.0.0, graylog2-server-0.9.5p1, and graylog2-web-interface-0.9.5p2.


Place job definitions in /etc/init/ and then use service [job] [command] to start/stop/restart/status the services manually. On boot, the services flow into each other, only starting if dependent services have started. For more on controlling jobs or Upstart in general (a replacement for System-V init), see the cookbook.


MetaThis / server.js
Created Aug 25, 2011
Simple example of a Node.js proxy to CouchDB GET requests
View server.js
var http = require('http'),
request = require('request'), // request module from
url = require('url');
http.createServer(function (req, res) {
var href = url.parse(req.url,true).href;
request('' + href).pipe(res);
// now try something like
View gist:2996793
set softtabstop=2
set shiftwidth=2
set tabstop=2
set expandtab "expandtab (whitespace)
set number "line numbers
set ai "autoindent
set si "smartindent
set tw=79 "wrap on 79
set sta "smarttab
set history=100 "remember more than 20 cmd-history
chrismdp / bootstrap_chef.bash
Created Jun 15, 2011 — forked from michaelvobrien/bootstrap_chef.bash
Bootstrap Chef Solo on Ubuntu
View bootstrap_chef.bash
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='' bash <( curl -L )
# You will need to ensure that the ssh key is already set up on the server.
set -e
export CHEF_DIR="${HOME}/chef"
sudo rm -rf $CHEF_DIR
mkdir -p "$CHEF_DIR"
audionerd / Forwarding ports from a docker container with Vagrant
Last active Jun 25, 2019
Forwarding ports from a docker container with Vagrant 1.6
View Forwarding ports from a docker container with Vagrant

Forwarding ports from a docker container with Vagrant 1.6

Vagrant 1.6 has a really nice feature which allows you to run a docker environment from any machine that can run Vagrant (even a Mac)

Behind the scenes, Vagrant creates a host VM which runs the docker containers.

The "gotcha" is: Vagrant won't automatically forward ports all the way back from the container->vagrant host VM->your mac. You have to do that step manually, by configuring your own host VM for Vagrant to use for hosting docker containers with. That host VM is told what ports to open.

Here's how I set up a local Wordpress development testing container.

gjreda /
Created Oct 26, 2013
Grabs college basketball play-by-play data for a given date range. Example usage: python 2013-01-01 2013-01-07
from bs4 import BeautifulSoup
from urllib2 import urlopen
from datetime import datetime, timedelta
from time import sleep
import sys
import csv
tolitius / src.multi-method.clj
Created Jan 29, 2012
clojure bootcamp: "defmulti" example
View src.multi-method.clj
;; inspired by suggestion in THE doc:
(ns bootcamp.multi-method)
(defn measure-it [size]
(< size 3) :small
(< size 6) :medium
(< size 12) :large
:else :hard-to-measure ))