Skip to content

Instantly share code, notes, and snippets.

View christabor's full-sized avatar
😅
I may be slow to respond.

Chris Tabor christabor

😅
I may be slow to respond.
View GitHub Profile
@christabor
christabor / django model fields
Last active August 29, 2015 14:04
Get all django model fields in one go...
from django.db import models
DJANGO_FIELDS = (
(str(field).upper(), field)
for field in dir(models) if field.endswith('Field')
)
@christabor
christabor / python stdlib -> js functions
Created August 8, 2014 07:11
python stdlib functions in js - incomplete
window.pyfuncs = pyfuncs || {};
pyfuncs.string.ascii_lowercase = function() {
return 'abcdefghijklmnopqrstuvwxyz';
};
pyfuncs.string.ascii_uppercase = function() {
return pyfuncs.string.ascii_lowercase().toUpperCase();
};
@christabor
christabor / pythondecorators
Created September 9, 2014 22:40
Some uses for python decorators?
class Db():
def __init__(self):
self.foo = 'FOO'
def save(self, msg, *args, **kwargs):
print 'Saving... {}'.format(msg)
class RemoteTransport():
def __init__(self):
@christabor
christabor / randomgibberish-py
Last active August 29, 2015 14:06
random gibberish text generator
from string import ascii_lowercase
from random import choice
def long_word(max):
return ''.join([choice(ascii_lowercase + ' ') for _ in xrange(max)])
1 1 36 1 0
2 69 36 33 1
3 4761 36 9 0
4 328509 36 9 1
5 22667121 36 9 1
6 1564031349 36 9 3
7 107918163081 36 9 1
8 7446353252589 36 9 5
9 513798374428641 36 9 0
10 35452087835576229 36 9 9
@christabor
christabor / ca-generator
Last active August 29, 2015 14:06
Random rules for Cellular Automata in python
from random import choice
from pprint import pprint as ppr
def rule(n, choices):
pattern = ''
for x in range(n):
pattern += choice(choices)
return pattern
@christabor
christabor / gist:761443715961c6afeb30
Created October 5, 2014 21:54
Raphael nodejs shim
// Shim for Raphael
Raphael = (typeof module !== 'undefined' && module.exports) ? require('node-raphael') : Raphael;
//...lib stuff
@christabor
christabor / dropwhile
Created October 8, 2014 07:43
dropwhile
import itertools
def is_odd_exp(n):
print n, 'exp mod 2 =', n ** n % 2
if n ** n % 2 == 0:
return False
return True
function PI() {
echo 'Fuck PHP';
echo 'Also, use radians for chrissake';
}
@christabor
christabor / gist:ed706b4330b180b4bc27
Created January 5, 2015 22:02
python magic methods
class Database(object):
def __init__(self):
self.data = {}
def insert(self, key, val):
print 'Making db insertion....'
self.data[key] = val