Skip to content

Instantly share code, notes, and snippets.

View adamcharnock's full-sized avatar

Adam Charnock adamcharnock

View GitHub Profile
import graphene
import six
from graphene import relay
from graphene import ObjectType
from graphene.core.types import ObjectTypeMeta
from graphene.core.types.scalars import String
from graphene.utils.str_converters import to_snake_case
schema = graphene.Schema(name='My Schema')

Keybase proof

I hereby claim:

  • I am adamcharnock on github.
  • I am adamcharnock (https://keybase.io/adamcharnock) on keybase.
  • I have a public key whose fingerprint is D658 C40E 8212 4500 BDAF 517D B852 9215 0D16 8D94

To claim this, I am signing this object:

@adamcharnock
adamcharnock / gist:991454274cda8a66107a
Last active February 17, 2016 08:30
Plan: Django Image Backend

Plan: Django Image Backend

Motivation

Several services exist to manage image transformations on behalf of the developer (imgix & cloudinary, to name two). However, these services rely on generating the appropriate markup at render time. In same cases this is a URL pointed to the their service, at other times this is a rendering the <img> tag in a specific format.

Existing methods of image resizing perform this resize locally. Either online, or in an offline worker. It is also common to require the image sizes to be specified at the model level, whereas this should really only exist within the presentation logic.

Solution

@adamcharnock
adamcharnock / gist:3779308f4f1fb994397e
Created June 11, 2015 17:54
Experimenting with making a ShortUUID class
from uuid import UUID, uuid4
import base64
def make_uuid(type_bits, type_size):
bits = uuid4().int
id_size = 128 - type_size
# Zero out the type bits
bits &= pow(2, id_size) - 1
# Now add in the type
bits |= (type_bits << id_size)
@adamcharnock
adamcharnock / method_proxy.py
Last active September 11, 2015 13:10
A sqlalchemy-continuum plugin for making model methods and properties available on the versioned model
""" A sqlalchemy-continuum plugin for making model methods
and properties available on the versioned model
"""
from functools import wraps
from sqlalchemy_continuum.plugins import Plugin
def override_in_versioned(function=None):
""" Use the explicitly mark methods which should be
@adamcharnock
adamcharnock / post-checkout
Created April 22, 2014 11:28
.git/hooks/post-checkout
#!/bin/bash
echo "Cleaning up .pyc files and empty directories"
REPO_ROOT=./$(git rev-parse --show-cdup)
# Delete .pyc files and empty directories.
find $REPO_ROOT -name "*.pyc" -delete
find $REPO_ROOT -type d -empty -delete
{"hero":{"id":26,"secret_identity":"georgie","firstname":"George","full_name":"George Smith","enemy_id":1,"thing_1":"drink more beer","thing_2":"watch more TV","resilience_score":0}}
<?xml version="1.0" ?>
<!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
<coverage branch-rate="0" line-rate="0.8934" timestamp="1310992801111" version="3.4">
<!-- Generated by coverage.py: http://nedbatchelder.com/code/coverage -->
<packages>
<package branch-rate="0" complexity="0" line-rate="0.9635" name="ci">
<classes>
<class branch-rate="0" complexity="0" filename="ci/__init__.py" line-rate="1" name="__init__">
<methods/>
#!/bin/bash -ex
# Setup node-jshint and run it
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
curl http://npmjs.org/install.sh | sudo clean=no sh
@adamcharnock
adamcharnock / gist:1073858
Created July 9, 2011 19:18
Initial work on a Ruby/Rails setup script for https://continuous.io
#!/bin/bash -e
# The following variables are available to you
# (values are examples only)
#
# TIMEZONE="UTC" # The timezone this server should be given
# CI_USER="ci" # The user to setup and run the tests as
# # (although you are free to ignore this)
#
# GIT_URI="git://github.com/andymccurdy/redis-py.git" # The Git URL for this project