Skip to content

Instantly share code, notes, and snippets.

@mattvonrocketstein
mattvonrocketstein / schizoid.py
Created September 14, 2010 01:27
schizoid methods for python
""" schizoid methods for python
"""
import inspect, new, sys
# master registry for methodnames, decorators, and proxy scope dummy object
registry = {}
class proxy(object): pass
def personalityDependant(func):
@mattvonrocketstein
mattvonrocketstein / metaclasses.py
Created October 13, 2010 16:05
python metaclass AllStaticMethods
class AllStaticMethods(type):
"""
"""
def __new__(cls, name, bases, dct, finished=True):
"""
NOTE: the 'finished' flag is used for chaining..
make sure you know what you're doing if you use it.
"""
is_nonprivate_function = lambda name,obj: (not name.startswith('_')) and is_function(obj)
for x in dct:
@mattvonrocketstein
mattvonrocketstein / do_when.py
Created October 13, 2010 18:27
hacky decorators for defeating annoying race conditions
""" some decorator hacks for defeating annoying race conditions """
def when(predicate, limit=100, sleep_time=1, eager=False):
""" this function is dedicated to Christopher Michael Heisel
When predicate is True, the decorated function will run
(and nevermind exactly when it was called). If the predicate
tests False for more times than <limit>, this function will
simply exit and the decorated function will never be called.
@mattvonrocketstein
mattvonrocketstein / pyack
Created February 8, 2012 01:34
a dumb interface for getting ack data into python
""" pyack
a dumb interface for getting ack data into python
USAGE:
call it with a given search string or directory
>>> z = pyack('search_string')
>>> z = pyack('search_string directory')
>>> z = pyack('search_string directory --whatever-ack-args')
@mattvonrocketstein
mattvonrocketstein / gist:6678175
Created September 23, 2013 22:59
partition tests by type, retrieve misc. test metadata
import os, sys
import inspect
import unittest, unittest2
from django import test as dtest
import nose
def _suite2list(s):
return [x for x in _suite2iter(s)]
@mattvonrocketstein
mattvonrocketstein / triage.py
Last active August 29, 2015 13:57
triage thingy for radon output
#!/usr/bin/env python
""" triage.py reformats radon output
this code anticipates a command line usage as follows:
$ triage.py ./code
it works by reformatting the output of a radon command-line similar to this:
$ radon cc ./code/ --total-average --show-complexity > radon.out
vagrant@devbox:~$ git lo
log lol lola
vagrant@devbox:~$ git lo
git: 'lo' is not a git command. See 'git --help'.
Did you mean one of these?
log
lol
@mattvonrocketstein
mattvonrocketstein / pybcompgen.py
Last active August 29, 2015 14:08
Pybcompgen calculates context sensitive tab-completion data from environment bash system settings
#!/usr/bin/env python
""" pybcompgen
Pybcompgen calculates context sensitive tab-completion data which is
derived from environment bash system settings. It doesn't need to know
anything about whether you use /etc/completion or /etc/bash_completion.d,
all that matters is whether *bash* knows about the completion. The benefit
of doing this are obvious: you get access to all the completion features
that the system has installed without caring how the completion features
work. Note that this approach doesn't just work for things in the users
@mattvonrocketstein
mattvonrocketstein / grays_anatomy_downloader
Created January 7, 2015 09:28
this code downloads all the grays anatomy images on wikimedia into ./grays_anatomy_plates
#
# this code downloads all the grays anatomy images on wikimedia into ./grays_anatomy_plates
#
import time
import os, urllib2
from BeautifulSoup import BeautifulSoup
plates_url = 'http://commons.wikimedia.org/wiki/Gray%27s_Anatomy_plates'
base = 'https://commons.wikimedia.org'
save_dir = 'grays_anatomy_plates'
#!/bin/bash
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://raw.github.com/gist/2776679/04ca3bbb9f085b192f6aca945120fe12d59f15f9/install-redis.sh
# chmod 777 install-redis.sh
# ./install-redis.sh
###############################################
echo "*****************************************"