Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

David Cramer dcramer

View GitHub Profile
dcramer /
Created Dec 6, 2010
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')
dcramer /
Last active Feb 26, 2019
Python Standards (that I would change and enforce if I could)
# dont do this
this_function_name(foo, bar
# do this
foo, bar, baz)
# allow this
cramers_version(foo, bar,
View gist:3898601
View gist:6abbf037a51bc342f512724c889b2dc0
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuJUzqmnQCHvvgqJgAxew3qqrJtNQp3Ap1T0Bu4LFSLJ1ysSOFkC0v1eCmmNrLvUf7WYRmDBDC0aH8pxKFjE1CFZqolJFlp469aVaOcsqP3dfERGuWZ2zXokZjZr88CDmja7QVQ1l9gevnftHxy9rgov2mNdRqpJZpNcgct+0JvyFeJKhaCcyX2nYK5G0qe8FDub1azT3E/Ey3g/NvNzbmyqjDdIEU5hJo5J2uDGq26gXrudzJ/iARl7vJrvn160VNIn+tUvsejyc8UuqwIxu/4GVzKRcENJJUOg0GYhkIss7++ZbvvnINxbDi9wCgf8C5IQ4MD6Pp6dlvdihov6Np dcramer@MacBook-Pro-4.local
class BaseJobResource(Resource):
def dispatch_request(
self, provider: str, owner_name: str, repo_name: str, build_number: int, job_number: int, *args, **kwargs
) -> Response:
queryset = Job.query.join(Build, == Job.build_id).join(
Repository, == Build.repository_id
Repository.provider == RepositoryProvider(provider),
Repository.owner_name == owner_name, == repo_name,
View componentToString.js
import ReactDOM from 'react-dom';
const componentToString = function(node) {
let el = document.createElement('div');
ReactDOM.render(node, el);
return el.innerHTML;
View gist:550438
class QuerySetDoubleIteration(Exception):
"A QuerySet was iterated over twice, you probably want to list() it."
# "Skinny" here means we use iterator by default, rather than
# ballooning in memory.
class SkinnyManager(Manager):
def get_query_set(self):
return SkinnyQuerySet(self.model, using=self._db)
dcramer / gist:7728286
Created Dec 1, 2013
find oldest file in directory
View gist:7728286
find -type f -printf '%T+ %p\n' | sort -r | head -1
View responses.rst
import responses

def test_my_api():
    responses.add(responses.GET, '',
                  body='{"error": "not found"}', status=404,
View gist:7330744
# supervisor
command=uwsgi --addr=
# when you restart it does them in batches, instead of one at a time
$ sudo supervisorctl restart sentry
- stops all 10 procs
You can’t perform that action at this time.