Skip to content

Instantly share code, notes, and snippets.

Marc Tamlyn mjtamlyn

Block or report user

Report or block mjtamlyn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
'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'
View gist:6ec83fcfd78aa695ce6ae08fa0db6561
### Keybase proof
I hereby claim:
* I am mjtamlyn on github.
* I am 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 /
Last active Jun 18, 2019
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 /
Last active May 25, 2016
Utilities for testing graphene APIs

Some prototype utilities for testing projects built with graphene.


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


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.


A unittest.TestCase mixin with utility functions

mjtamlyn /
Created Nov 11, 2015
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 /
Last active Oct 6, 2015
Django 1.9 upgrade notes

Upgrading to Django 1.9a1

Here are notes on my current progress testing 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 /
Last active Aug 29, 2015
BUCS Outdoors proposal

BUCS Outdoors - Proposed format change


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 / gist:5a3ae33cdd004e85d3c5
Created Feb 26, 2015
brew install hdf4 --debug --verbose --enable-fortran
View gist:5a3ae33cdd004e85d3c5
==> Installing hdf4 from homebrew/homebrew-versions
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading
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
mjtamlyn / gist:aa80effbcf33f3b5065a
Created Feb 26, 2015
Cellar after installing hdf4 with --enable-fortran
View gist:aa80effbcf33f3b5065a
$ find /usr/local/Cellar/hdf4/4.2.10
You can’t perform that action at this time.