Skip to content

Instantly share code, notes, and snippets.

@inlinestyle
inlinestyle / factory_dict.py
Created May 23, 2012 01:15
An extension of collections.defaultdict that I wish were in the stdlib.
import inspect
from types import FunctionType
from collections import defaultdict
class FactoryDict(defaultdict):
"""
>>> fd = FactoryDict(int)
>>> fd['foo'] += 7
>>> fd['foo']
7
@inlinestyle
inlinestyle / .bash_profile
Created August 3, 2012 04:03
A sweet PS1 for displaying git state and virtualenv
red="\[\e[0;31m\]"
green="\[\e[0;32m\]"
yellow="\[\e[0;33m\]"
purple="\[\e[0;35m\]"
cyan="\[\e[0;36m\]"
end="\[\e[0m\]"
GIT_PS1_SHOWUPSTREAM=auto
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWDIRTYSTATE=true
from collections import defaultdict
import functools
class multimethod(object):
"""
multimethod.register('function', dispatcher)
@multimethod.register('function')
def dispatcher(): pass
from collections import defaultdict
import functools
class Registry(object):
def __init__(self):
self.dispatchers = {}
self.functions = defaultdict(dict)
def __enter__(self):
@inlinestyle
inlinestyle / starter-profile.sh
Created February 12, 2013 18:38
Starter profile for designers, etc. The commented `curl` commands should be run in the shell to get git stuff working.
red="\[\e[0;31m\]"
green="\[\e[0;32m\]"
yellow="\[\e[0;33m\]"
purple="\[\e[0;35m\]"
cyan="\[\e[0;36m\]"
end="\[\e[0m\]"
#curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
if [ -f ~/.git-completion.bash ]
then
@inlinestyle
inlinestyle / package.json
Created February 16, 2013 17:42
package.json for johnny-five
{
"dependencies": {
"johnny-five": "git+ssh://git@github.com:rwldrn/johnny-five.git"
}
}
app.all '/push/*', (request, response) ->
response.json 503, {}
app.get '/api/v2/user_messages', (request, response) ->
response.json 200, {messages: [{message_heading: 'Scheduled Maintenance', message_text: 'We are currently conducting maintenance'}]} # in-app messaging!
app.all '/api/*', (request, response) ->
response.json 503, {}
app.all '/*', (request, response) ->
response.setHeader 'Retry-After', '3600'
response.send 503, render503Page() # renders html for web 503 page
@inlinestyle
inlinestyle / megatron.go
Created September 5, 2014 03:56
Boilerplate for a stream API in go
package main
import (
"fmt"
"github.com/codegangsta/martini-contrib/binding"
"github.com/go-martini/martini"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"net/http"
)
@inlinestyle
inlinestyle / optimus.go
Last active August 29, 2015 14:06
HTTP/JSON API that consumes stream/event POSTs and publishes them to a local Kafka cluser
package main
import (
"encoding/json"
"fmt"
"github.com/codegangsta/martini-contrib/binding"
"github.com/go-martini/martini"
"github.com/shopify/sarama"
"net/http"
)
@inlinestyle
inlinestyle / lecture.md
Last active August 29, 2015 14:14
Lecture outline for Python Lists/Dicts talk

Lists:

  • Making lists with stuff in them

Item Access

  • access just like strings!
  • O-indexed
  • assignment with list[index] syntax, touch on mutability ("this can be changed, strings can't")

Length