Skip to content

Instantly share code, notes, and snippets.

View dcramer's full-sized 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 December 6, 2010 19:15
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
dcramer / remix.md
Last active June 14, 2023 16:22
Running Remix Problems

Remix Issues

Transaction Names

useMatches only exposes the filepath, but we want a parameterized route:

8:53:24 AM web.1 |  {
8:53:24 AM web.1 |    id: 'routes/bottles.$bottleId._index',
8:53:24 AM web.1 |    pathname: '/bottles/4/',
blueprint:
name: ZHA - Sonoff SNZB-01
description: 'Perform actions with the Sonoff SNZB-01 Button.
You can set functions for single press, double press and hold. This allows you to assign,
e.g., a scene or anything else.'
domain: automation
input:
remote:
@dcramer
dcramer / args.py
Last active June 1, 2021 14:28
Python Standards (that I would change and enforce if I could)
# dont do this
this_function_name(foo, bar
baz)
# do this
cramers_version(
foo, bar, baz)
# allow this
cramers_version(foo, bar,
@dcramer
dcramer / .zshrc
Last active April 5, 2021 20:37
zsh
# 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
# }
apiVersion: networking.gke.io/v1beta1
kind: ManagedCertificate
metadata:
name: zeus-ci
spec:
domains:
- zeus.ci
- updates.zeus.ci
---
apiVersion: extensions/v1beta1
# get some languages
brew 'go'
brew 'node'
brew 'python'
brew 'ruby'
# and common dlls
brew 'geoip'
brew 'libxmlsec1'
brew 'openssl'
{
"extra": {...},
"contexts": {
"contxtName": {...},
}
}
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 March 29, 2019 00:21 — forked from mattrobenolt/cramermath.py
David Cramer math
"""
cramermath
~~~~~~~~~~
Usage:
>>> import cramermath
>>> cramermath.log(10)
0.014728067495500818
"""