Skip to content

Instantly share code, notes, and snippets.

View durden's full-sized avatar

Luke Lee durden

View GitHub Profile
@durden
durden / callable.py
Created June 16, 2011 02:22
Clever way to use Python __call__ and __getattr__ to create web APIs that can map directly (dynamically) to actual API
class MyCallable(object):
def __init__(self, urlparts, callable):
self.urlparts = urlparts
self.callable = callable
def __call__(self, **kwargs):
print kwargs
print self.urlparts
def __getattr__(self, name):
# Return a callable object of this same type so that you can just keep
# chaining together calls and just adding that missing attribute to the
@durden
durden / gist:1028560
Created June 16, 2011 02:27
Deployment of Django 1.2 app to Gondor (http://gondor.io)
** Structure should have repo directory then django project directory under it.
** Only files that are committed to the repo are used in deployment.
** Make sure to not have any other .git projects/directories in your project
other than the one at the top level. This causes problems like not finding
settings files, etc.
** <project> refers to the 'main' project where your git repository (.git
directory resides)
** <project_name> refers to the 'main' django project directory (were
settings.py resides)
@durden
durden / create_virtualenv.sh
Created June 25, 2011 18:08
Shell script wrapper for easily starting/populating a virtual env
#!/bin/sh
# This is a function so that we can use 'workon' to switch since it will
# refresh the environment and pass it onto the caller. Thus, no reason to run
# another shell after this command or calling workon manually, etc.
start_virtualenv_main() {
# Assume your working in the directory of the project name
curr=`pwd`
proj=`basename $curr`
This is an updated test from frappy
@durden
durden / liquid sn0b
Created July 12, 2011 03:42
dash idea
Liquid Snobs (DIY Drinker)
- Categories (post type):
1. Coffee
2. Beer
3. Cocktails
** might could add tea or something else
- Each part has it's own slightly different css/look and feel
@durden
durden / bash_oop.sh
Created July 26, 2011 12:08
OOP in bash
#!/bin/bash
# ---------------------------------------------------------------------------
# OO support functions
# Kludged by Pim van Riezen <pi@madscience.nl>
# http://lab.madscience.nl/oo.sh.txt
# ---------------------------------------------------------------------------
DEFCLASS=""
CLASS=""
THIS=0
import sys, types
module = sys.modules[__name__]
for name, var in vars(module).items():
if type(var) == types.FunctionType and name.startswith('filter_'):
value = var(value)
#django dash test
@durden
durden / listchunk.py
Created September 10, 2011 15:37
Iterate of a list chunk by chunk
class ListChunk:
def __init__(self, items, chunksize):
self.items = items
self.chunksize = chunksize
self.ii = 0
def __iter__(self):
return self
def next(self):
if self.ii >= len(self.items):
raise StopIteration
@durden
durden / heroku_deployment
Created October 1, 2011 18:04
Codrspace deployment for heroku
Install rvm (ruby community equivalent of virtualenv):
- bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Install ruby 1.9.2:
- rvm install 1.9.2 && rvm use 1.9.2 --default
Heroku:
- gem install heroku
- heroku create --stack cedar
- Automatically adds a git remote called 'heroku'