Skip to content

Instantly share code, notes, and snippets.

View kezabelle's full-sized avatar

Keryn Knight kezabelle

View GitHub Profile
@kezabelle
kezabelle / frozen_queryset.py
Last active April 7, 2017 10:44
Playing with the idea of a queryset which cannot be accidentally Evaluated, only cloned.
class UnevaluableQuerySet(QuerySet):
def __init__(self, *a, **kw):
super(UnevaluableQuerySet, self).__init__(*a, **kw)
self._frozen = False
def freeze(self):
clone = self._clone()
clone._frozen = True
return clone
@kezabelle
kezabelle / filtersets.py
Created March 29, 2017 14:49
django-filters .. paring down the choices in a related widget.
from django_filters import FilterSet
class MyModelFilterSet(FilterSet):
class Meta:
model = MyModel
fields = ['my_relation'] # internally this is a reverse relation, so MyModelInstance.my_relation_set.all()
# How do I get it so that the ModelChoiceFilter (actually a ModelMultipleChoiceFilter!) is only
# those items which exist given the FilterSet's original queryset (self.queryset.all())
@kezabelle
kezabelle / settings_test.py
Created March 10, 2017 15:40
go away migrations during a pytest run. For my own recollection, but also for w0rp in #django IRC.
# https://simpleisbetterthancomplex.com/tips/2016/08/19/django-tip-12-disabling-migrations-to-speed-up-unit-tests.html
class DisableMigrations(object):
def __contains__(self, item):
return True
def __getitem__(self, item):
return 'notmigrations'
MIGRATION_MODULES = DisableMigrations()
@kezabelle
kezabelle / mod_wsgi.conf
Created March 9, 2017 14:01
maybe something like this is enough for mod_wsgi; for indy1T9 on #django IRC.
<VirtualHost *:80>
ServerName whatever
ServerAlias www.whatever
<Directory /PATH/TO/PROJECT/CONFIGDIR>
<Files wsgi.py>
Require all granted
Satisfy Any
</Files>
</Directory>
@kezabelle
kezabelle / _README.md
Last active February 22, 2017 09:24
Issue with button:focus in OSX Firefox (see https://github.com/LeadDyno/intercooler-js/issues/115)

To run

  • cd to the directory the file is saved in
  • python3 -m http.server
  • navigation to ???:8000/formerror.html
  • Press next or prev
  • Check the params sent with the Intercooler intercepted request.

In OSX Chrome

@kezabelle
kezabelle / files.md
Created September 29, 2016 13:59
changelog stuff

File handling

Probably want to be able to read from STDIN or a file ...

File names, without extension.

All files should be checked for extension equivalents, and for lowercase or alternative-case variants.

  • CHANGELOG
  • CHANGES
@kezabelle
kezabelle / mm2px.py
Created September 14, 2016 09:25
I need to know the maths for pixels + DPI to mm. For kitely.
"""
python mm2px.py 290 210 150
"""
import sys
w = float(sys.argv[1]) # 1830
h = float(sys.argv[2]) # 1547
dpi = int(sys.argv[3]) # 150
w_mm = (w * dpi) / 25.4
h_mm = (h * dpi) / 25.4
print((w_mm, h_mm))
@kezabelle
kezabelle / getters.py
Created August 31, 2016 10:14
I wonder which is faster? Turns out, neither, really.
from random import randint
from operator import attrgetter, itemgetter
from contexttimer import Timer
class Lol(object):
@property
def test(self):
return randint(1, 100)
def __getitem__(self, x):
@kezabelle
kezabelle / itermtriggers.txt
Created August 29, 2016 11:41
Text triggers for iterm2 (3)
line ([1-9]\d+|[1-9]), in ([^\d\W]\w+)
@kezabelle
kezabelle / sorto.py
Created August 16, 2016 11:16
Maybe approximate doing order_by("thing", "-otherthing", "thing2") in Django, but for python things. Originally piqued my interest because of bmispelon on #django IRC
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from pprint import pprint
from operator import itemgetter
from copy import deepcopy
import sys
"""
Wheeee:
python sorto.py "age" "gender"