Instantly share code, notes, and snippets.

View track_data.py
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')
View gist:3898601
View gist:6abbf037a51bc342f512724c889b2dc0
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuJUzqmnQCHvvgqJgAxew3qqrJtNQp3Ap1T0Bu4LFSLJ1ysSOFkC0v1eCmmNrLvUf7WYRmDBDC0aH8pxKFjE1CFZqolJFlp469aVaOcsqP3dfERGuWZ2zXokZjZr88CDmja7QVQ1l9gevnftHxy9rgov2mNdRqpJZpNcgct+0JvyFeJKhaCcyX2nYK5G0qe8FDub1azT3E/Ey3g/NvNzbmyqjDdIEU5hJo5J2uDGq26gXrudzJ/iARl7vJrvn160VNIn+tUvsejyc8UuqwIxu/4GVzKRcENJJUOg0GYhkIss7++ZbvvnINxbDi9wCgf8C5IQ4MD6Pp6dlvdihov6Np dcramer@MacBook-Pro-4.local
View base_job.py
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, Build.id == Job.build_id).join(
Repository, Repository.id == Build.repository_id
).filter(
Repository.provider == RepositoryProvider(provider),
Repository.owner_name == owner_name,
Repository.name == repo_name,
View args.py
# dont do this
this_function_name(foo, bar
baz)
# do this
cramers_version(
foo, bar, baz)
# allow this
cramers_version(foo, bar,
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."
pass
# "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)
View gist:7728286
find -type f -printf '%T+ %p\n' | sort -r | head -1
View responses.rst
import responses

@responses.activate
def test_my_api():
    responses.add(responses.GET, 'http://twitter.com/api/1/foobar',
                  body='{"error": "not found"}', status=404,
                  content_type='application/json')
View gist:7330744
# supervisor
[sentry]
numprocs=10
command=uwsgi --addr=0.0.0.0:90%(process_num)02d
# when you restart it does them in batches, instead of one at a time
$ sudo supervisorctl restart sentry
- stops all 10 procs