Skip to content

Instantly share code, notes, and snippets.

View mjtamlyn's full-sized avatar

Marc Tamlyn mjtamlyn

  • Photocrowd
  • Oxford
View GitHub Profile
@mjtamlyn
mjtamlyn / settings.py
Created January 10, 2018 09:25
Logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
### Keybase proof
I hereby claim:
* I am mjtamlyn on github.
* I am mjtamlyn (https://keybase.io/mjtamlyn) on keybase.
* I have a public key whose fingerprint is 43B2 D38F 7D86 E0FD B442 D407 2D52 B74A 095C B09A
To claim this, I am signing this object:
@mjtamlyn
mjtamlyn / cursor.py
Last active December 2, 2021 08:42
Graphene pagination
import functools
from django.db.models import Prefetch, QuerySet
import attr
import graphene
from cursor_pagination import CursorPaginator
from graphene.utils.str_converters import to_snake_case
from graphql_relay import connection_from_list
@mjtamlyn
mjtamlyn / README.md
Last active May 25, 2016 15:15
Utilities for testing graphene APIs

Some prototype utilities for testing projects built with graphene.

Context

Simple utility class for creating context objects (e.g. context=Context(user=user))

Fragment

A wrapper class for strings to say "don't touch me". Can be used for arguments and as keys of the object passed to build_query.

GrapheneTestCase

A unittest.TestCase mixin with utility functions

@mjtamlyn
mjtamlyn / word_match.py
Created November 11, 2015 16:19
Word matching Django func
from django.db.models import Func
class WordMatch(Func):
"""Combination function which checks whether any non-empty words are in common.
Roughly equivalent to bool(set(a.split()) & set(b.split())), but with MOAR sql.
"""
sql_template = "array_length(array_remove(array(select unnest(string_to_array(%s, ' ')) intersect select unnest(string_to_array(%s, ' '))), ''), 1) >= 1"
output_field = models.BooleanField()
@mjtamlyn
mjtamlyn / upgrading.md
Last active October 6, 2015 10:16
Django 1.9 upgrade notes

Upgrading photocrowd.com to Django 1.9a1

Here are notes on my current progress testing photocrowd.com on Django 1.9 prereleases. I hope this will be useful for other people testing their projects.

The starting point was a completely up to date (according to pypi) set of my requirements on October 5th 2015.

Requirement updates

  • Django floppy forms is fixed on github master
  • Django timezone field is fixed on github develop
@mjtamlyn
mjtamlyn / outdoors.md
Last active August 29, 2015 14:23
BUCS Outdoors proposal

BUCS Outdoors - Proposed format change

Background

This year, BUCS Outdoors was oversubscribed by around 100 entries. The resulted in a cut to just 11 archers per club. Some notable established clubs such as Edinburgh were particularly badly hit by this, and generally it was Novice archers who were cut. With the continued growth of sactudent archery, the situation is likely to continue to worsen over the next few years.

class MyForm(forms.Form):
# ... Many fields
def clean(self):
foo = self.cleaned_data.get('foo')
bar = self.cleaned_data.get('bar')
if foo and bar and foo > 0 and bar < 0:
self.add_error('bar', ValidationError('Some message', code='foo_bar_mismatch'))
# ... Other validation rules here
@mjtamlyn
mjtamlyn / gist:5a3ae33cdd004e85d3c5
Created February 26, 2015 10:57
brew install hdf4 --debug --verbose --enable-fortran
==> Installing hdf4 from homebrew/homebrew-versions
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading http://www.hdfgroup.org/ftp/HDF/releases/HDF4.2.10/src/hdf-4.2.10.tar.bz2
Already downloaded: /Library/Caches/Homebrew/hdf4-4.2.10.tar.bz2
==> Verifying hdf4-4.2.10.tar.bz2 checksum
tar xf /Library/Caches/Homebrew/hdf4-4.2.10.tar.bz2
==> Patching
patching file CMakeLists.txt
==> cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/hdf4/4.2.10 -DCMAKE_BUILD_TYPE=None -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DHDF4_BUILD_TOOLS=ON -DHDF4_BUILD_UTILS=ON -DHDF4_BUILD_WITH_INSTALL_NAME=ON -DHDF4_ENABLE_JPEG_LIB_SUPPORT=ON -DHDF4_ENABLE_NETCDF=OFF -DHDF4_ENABLE_SZIP_ENCODING=ON -DHDF4_ENABLE_SZIP_SUPPORT=ON -DHDF4_ENABLE_Z_LIB_SUPPORT=ON -DHDF4_BUILD_FORTRAN=ON -DCMAKE_Fortran_MODULE_DIRECTORY=/usr/local/Cellar/hdf4/4.2.10/include
@mjtamlyn
mjtamlyn / gist:aa80effbcf33f3b5065a
Created February 26, 2015 10:55
Cellar after installing hdf4 with --enable-fortran
$ find /usr/local/Cellar/hdf4/4.2.10
/usr/local/Cellar/hdf4/4.2.10
/usr/local/Cellar/hdf4/4.2.10/bin
/usr/local/Cellar/hdf4/4.2.10/bin/gif2hdf
/usr/local/Cellar/hdf4/4.2.10/bin/hdf24to8
/usr/local/Cellar/hdf4/4.2.10/bin/hdf2gif
/usr/local/Cellar/hdf4/4.2.10/bin/hdf2jpeg
/usr/local/Cellar/hdf4/4.2.10/bin/hdf8to24
/usr/local/Cellar/hdf4/4.2.10/bin/hdfcomp
/usr/local/Cellar/hdf4/4.2.10/bin/hdfed