Skip to content

Instantly share code, notes, and snippets.

@fredrick
fredrick / stub.py
Created March 15, 2011 17:07
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])
# 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: http://wiki.nginx.org/HttpMapModule#map
map $http_x_scheme $x_scheme {
var gistPrefix = 'https://gist.github.com/',
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
fredrick / README.md
Created November 22, 2011 18:17
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.

#Usage

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.

#Author

@MetaThis
MetaThis / server.js
Created August 25, 2011 22:03
Simple example of a Node.js proxy to CouchDB GET requests
var http = require('http'),
request = require('request'), // request module from https://github.com/mikeal/request
url = require('url');
http.createServer(function (req, res) {
var href = url.parse(req.url,true).href;
request('http://127.0.0.1:5984' + href).pipe(res);
}).listen(1337);
// now try something like http://127.0.0.1:1337/your_db_name/_all_docs/?limit=10
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
chrismdp / bootstrap_chef.bash
Created June 15, 2011 07:12 — forked from michaelvobrien/bootstrap_chef.bash
Bootstrap Chef Solo on Ubuntu
#!/usr/bin/env bash
# call like this on the target server:
# NODENAME='foo' CHEF_ENV='production' RUNLIST='["role[foo]","recipe[bar]"]' CHEFREPO='git@example.com:repo.git' bash <( curl -L https://raw.github.com/gist/1026628 )
# 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
audionerd / Forwarding ports from a docker container with Vagrant 1.6.md
Last active June 25, 2019 20:45
Forwarding ports from a docker container with Vagrant 1.6

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
gjreda / espn-cbb.py
Created October 26, 2013 22:24
Grabs college basketball play-by-play data for a given date range. Example usage: python espn.cbb.py 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
# CONSTANTS
ESPN_URL = "http://scores.espn.go.com"
@tolitius
tolitius / src.multi-method.clj
Created January 29, 2012 07:04
clojure bootcamp: "defmulti" example
;; inspired by suggestion in THE doc: http://java.ociweb.com/mark/clojure/article.html
(ns bootcamp.multi-method)
(defn measure-it [size]
(cond
(< size 3) :small
(< size 6) :medium
(< size 12) :large
:else :hard-to-measure ))