Skip to content

Instantly share code, notes, and snippets.

View codysoyland's full-sized avatar

Cody Soyland codysoyland

View GitHub Profile
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
@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 &
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 / gateway.sh
Created January 11, 2012 00:14
fabric gateway script
#!/bin/sh
echo $* | ssh gateway "cat > /tmp/fab-runner; chmod +x /tmp/fab-runner"
ssh gateway -t screen bash -init-file /tmp/fab-runner
# Usage: gateway.sh fab production deploy
@codysoyland
codysoyland / gist:2505907
Created April 27, 2012 04:45
stupid gevent memcache server
from gevent.server import StreamServer
#import gevent
import time
class ClientDisconnected(Exception):
pass
class Handler(object):
def __init__(self, cache, socket, address):
self.cache = cache
@codysoyland
codysoyland / requiredreading.txt
Created July 6, 2012 15:45 — forked from adamfast/requiredreading.txt
Preserved for #lawrence history, this was the "required reading" list of totally-non-work-related inside jokes of the World Online crew.
DJ Ango, yo!
http://railsenvy.com/2007/9/10/ruby-on-rails-vs-django-commercial-7
The Whistles
http://www.youtube.com/watch?v=ccgXjA2BLEY
Do it live!
http://www.youtube.com/watch?v=2tJjNVVwRCY
REMIX: http://www.youtube.com/watch?v=5j2YDq6FkVE&NR=1
@codysoyland
codysoyland / prime_sieve.py
Last active April 23, 2017 14:24
A prime number generator using Python generators, inspired by concurrent prime sieve at http://play.golang.org/p/9U22NfrXeq
from itertools import count
def filter(input, prime):
for i in input:
if i % prime:
yield i
def get_primes(num):
g = count(2)
for _ in xrange(num):
#!/usr/bin/env python
import requests
import subprocess
import re
import string
import textwrap
import argparse
def parse_args():
import functools
class memoize(object):
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
return self.cache_get(args, lambda: self.func(*args))
def __get__(self, obj, objtype):
return self.cache_get(obj, lambda: self.__class__(functools.partial(self.func, obj)))
@codysoyland
codysoyland / riak_zmq.erl
Created August 23, 2011 16:23
Riak postcommit ZeroMQ publisher
-module(riak_zmq).
-export([postcommit_publish/1, get_zmq_publisher/0, zmq_publisher/0, zmq_publisher/1]).
postcommit_publish(RObj) ->
Body = riak_object:get_value(RObj),
{ok, Pid} = get_zmq_publisher(),
Pid ! {send, Body}.
get_zmq_publisher() ->