Skip to content

Instantly share code, notes, and snippets.

View codysoyland's full-sized avatar

Cody Soyland codysoyland

View GitHub Profile
@codysoyland
codysoyland / temporary_settings.py
Created June 21, 2011 21:47
Context manager for monkey-patching django settings (useful in unit tests)
# Example usage:
# with temporary_settings(CELERY_ALWAYS_EAGER=True):
# run_task.delay() # runs task with eager setting enabled.
from contextlib import contextmanager
from django.conf import settings
@contextmanager
def temporary_settings(**temp_settings):
orig_settings = {}
import gevent
from gevent.server import StreamServer
from gevent.pool import Group
from gevent_zeromq import zmq
context = zmq.Context()
class CodependentGroup(Group):
"""
A greenlet group that will kill all greenlets if a single one dies.
@codysoyland
codysoyland / post-checkout
Created January 18, 2011 20:19
place in .git/hooks/post-checkout to delete empty directories and pyc files
#! /bin/sh
echo "Purging pyc files and empty directories..."
# Start from the repository root.
cd ./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find . -name "*.pyc" -delete 2>&1 > /dev/null &
find . -type d -empty -delete 2>&1 > /dev/null &
/*
twirc.js
========
Automating Twitter messages to IRC. BSD license.
Installation:
-------------
* brew install node
from django.template import Parser, Lexer, Token, Context, TextNode, TOKEN_BLOCK, TOKEN_COMMENT, TOKEN_TEXT, TOKEN_VAR
from django.conf import settings
LITERAL_DELIMITER = '8====D'
class LiteralNode(TextNode):
pass
def parse(parser):
depth = 0
diff --git a/tastypie/api.py b/tastypie/api.py
index 0344a81..b4f2adc 100644
--- a/tastypie/api.py
+++ b/tastypie/api.py
@@ -50,6 +50,19 @@ class Api(object):
# Register it globally so we can build URIs.
_add_resource(self, resource, canonical)
+ def register_representation(self, representation, name, canonical=True):
+ """
# working with mercurial, the easy way
# requires hg-git
hg clone http://bitbucket.org/ianb/pip
cd pip
hg bookmark hg/default
hg gexport
ln -s .hg/git .git
echo ".hg" >> .git/info/exclude
git reset hg/default
from HTMLParser import HTMLParser
import sys
import pprint
import urllib
from pip.commands.search import highest_version
import pkg_resources
class PyPISearchParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
[user]
email = codysoyland@gmail.com
name = Cody Soyland
[color]
ui = true
[core]
whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
from piston.handler import BaseHandler
from piston.emitters import Emitter
def serialize(data):
return Emitter(data, {}, BaseHandler).construct()