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
View settings.py
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'
},
View gist:6ec83fcfd78aa695ce6ae08fa0db6561
### 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 Jun 18, 2019
Graphene pagination
View cursor.py
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
Utilities for testing graphene APIs
View README.md

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 Nov 11, 2015
Word matching Django func
View word_match.py
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 Oct 6, 2015
Django 1.9 upgrade notes
View upgrading.md

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 Aug 29, 2015
BUCS Outdoors proposal
View outdoors.md

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.

View forms.py
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 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 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 Feb 26, 2015
Cellar after installing hdf4 with --enable-fortran
View gist:aa80effbcf33f3b5065a
$ 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
You can’t perform that action at this time.