Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I may be slow to respond.

David Cramer dcramer

💭
I may be slow to respond.
View GitHub Profile
@dcramer
dcramer / track_data.py
Created Dec 6, 2010
Tracking changes on properties in Django
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')
@dcramer
dcramer / args.py
Last active Jun 21, 2020
Python Standards (that I would change and enforce if I could)
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 gist:e9a9225dcdeffa8fd7fafbe283bf0cf6
apiVersion: networking.gke.io/v1beta1
kind: ManagedCertificate
metadata:
name: zeus-ci
spec:
domains:
- zeus.ci
- updates.zeus.ci
---
apiVersion: extensions/v1beta1
View Brewfile
# get some languages
brew 'go'
brew 'node'
brew 'python'
brew 'ruby'
# and common dlls
brew 'geoip'
brew 'libxmlsec1'
brew 'openssl'
View .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
source <(antibody init)
antibody bundle < ~/.config/zsh_plugins
# TODO(dcramer): literally doesnt work at all
# function update_antibody() {
# antibody bundle < ~/.config/zsh_plugins > ~/.config/zsh_plugins.sh
# }
View attach_foreignkey.py
def attach_foreignkey(objects, field, select_related=None):
"""
Shortcut method which handles a pythonic LEFT OUTER JOIN.
``attach_foreignkey(posts, Post.thread)``
"""
field = field.field
qs = field.rel.to.objects.filter(pk__in=distinct(getattr(o, field.column) for o in objects))
if select_related:
qs = qs.select_related(*select_related)
@dcramer
dcramer / cramermath.py
Created Mar 29, 2019 — forked from mattrobenolt/cramermath.py
David Cramer math
View cramermath.py
"""
cramermath
~~~~~~~~~~
Usage:
>>> import cramermath
>>> cramermath.log(10)
0.014728067495500818
"""
View gist:3898601
View gist:6abbf037a51bc342f512724c889b2dc0
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuJUzqmnQCHvvgqJgAxew3qqrJtNQp3Ap1T0Bu4LFSLJ1ysSOFkC0v1eCmmNrLvUf7WYRmDBDC0aH8pxKFjE1CFZqolJFlp469aVaOcsqP3dfERGuWZ2zXokZjZr88CDmja7QVQ1l9gevnftHxy9rgov2mNdRqpJZpNcgct+0JvyFeJKhaCcyX2nYK5G0qe8FDub1azT3E/Ey3g/NvNzbmyqjDdIEU5hJo5J2uDGq26gXrudzJ/iARl7vJrvn160VNIn+tUvsejyc8UuqwIxu/4GVzKRcENJJUOg0GYhkIss7++ZbvvnINxbDi9wCgf8C5IQ4MD6Pp6dlvdihov6Np dcramer@MacBook-Pro-4.local
You can’t perform that action at this time.