Skip to content

Instantly share code, notes, and snippets.

View jdunck's full-sized avatar

Jeremy Dunck jdunck

View GitHub Profile
@jdunck
jdunck / uuid.py
Created May 26, 2009 01:21 — forked from mmalone/uuid.py
import socket
def sockrecv(sock):
d = ''
while not d or d[-1] != '\n':
d += sock.recv(8192)
return d
<style>
html {visibility:hidden;}
</style>
<script>
if(self==top) {
document.documentElement.style.visibility='visible';
} else {
top.location=self.location;
}
</script>
@jdunck
jdunck / prefixed.py
Created June 4, 2010 13:26 — forked from bkonkle/prefixed.py
A namespacing cache backend for django
import types
from django.conf import settings
from urllib import urlencode
from django.core.cache.backends.base import BaseCache
from django.utils.encoding import smart_str
#future-proofing against any Django upstream additions of new cache methods.
# If we didn't do this, we'd silently use the base class's methods, which wouldn't
# use the prefix as required.
_expected_methods = set(['__contains__', '__init__', 'add', 'close',
@jdunck
jdunck / Javascript Location object.
Created September 16, 2010 20:56
A window.location-compatible URL parsing class
// Location shim 1.0
// (c) Jeremy Dunck
// MIT License
function Location(url) {
obj = parseUri(url);
this.hash = obj.anchor ? "#" + obj.anchor : "";
this.host = obj.authority;
this.hostname = obj.host;
this.href = url;
@jdunck
jdunck / warn_on_path_overlap.py
Created March 6, 2011 06:58
Python wart remover: avoid overlapping sys.path which results in duplicate imports.
import sys, os.path, logging
try:
import sysconfig
except ImportError:
sysconfig = None
def warn_on_path_overlap():
"""
@jdunck
jdunck / gist:1293038
Created October 17, 2011 16:41
fabfile task to spot dupe-numbered south migrations
# this is intended to be run as part of a fab-suite, i.e. fab git_push, which runs tests, all files committed, etc. before pushing.
def ensure_no_duped_migrations():
migration_dirs = local('find %s -type d -iname migrations' % ROOT_DIR,
True).split('\n')
for migration_dir in migration_dirs:
full_migration_dir = path.join(ROOT_DIR, migration_dir)
# FIXME: for GNU find, need regextype=posix-extended
dupe_checker = ("find -E %s -iregex '.*/[0-9]{4,}[^/]*\.py' -exec basename {} ';'| cut -d_ -f1 | sort | uniq -d" %
@jdunck
jdunck / gist:1323787
Created October 28, 2011 22:54
Clean up defunct celery PeriodicTask entries
from djcelery.models import PeriodicTask
from django.utils import importlib
bad_tasks = []
good_tasks = []
for pt in PeriodicTask.objects.iterator():
path_name, task_name = pt.task.rsplit('.', 1)
try:
module = importlib.import_module(path_name)
(function() {
var el = document.createElement('div'),
b = document.getElementsByTagName('body')[0],
otherlib = false,
msg = '';
el.style.position = 'fixed';
el.style.height = '32px';
el.style.width = '220px';
el.style.marginLeft = '-110px';
el.style.top = '0';
@jdunck
jdunck / gist:1411661
Created November 30, 2011 23:01
validate everywhere
from django.db.models import Model
class ModelBase(Model):
class Meta:
abstract = True
def save(self, *args, **kwargs):
self.full_clean()
super(ModelBase, self).save(*args,**kwargs)
SELECT DISTINCT (contacts_itemcandidate.id is not null) AS `social_like`, (contacts_itemdistrict.id is not null) AS `in_district`, (contacts_item.api_voter_id > 0) AS `is_voter`, `contacts_item`.`id`
FROM `contacts_item`
INNER JOIN
`contacts_itemuser`
ON
(`contacts_item`.`id` = `contacts_itemuser`.`item_id`)
LEFT OUTER JOIN
`contacts_itemcandidate`
ON
(`contacts_item`.`id` = `contacts_itemcandidate`.`item_id`)