Skip to content

Instantly share code, notes, and snippets.

View adamcharnock's full-sized avatar

Adam Charnock adamcharnock

View GitHub Profile
@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 / 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 / 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

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:

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')
from django import forms
from django.forms import fields
from singledispatch import singledispatch
from graphene.core.types.scalars import ID, Boolean, Float, Int, String
from graphene.contrib.django.fields import ConnectionOrListField, DjangoModelField
try:
UUIDField = forms.UUIDField
except AttributeError:
import React from 'react';
import Relay from 'react-relay';
export default class ${NAME} extends React.Component {
static propTypes = {};
static defaultProps = {};
render() {
return (
$ flynn run locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
0.000 2016-08-22 19:50:18; Factorio 0.13.17 (build 23946, mac, steam)
0.000 Operating system: Mac OS X 10.11.5
0.000 Program arguments: "/Users/adam/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app"
0.000 Read data path: /Users/adam/Library/Application Support/Steam/steamapps/common/Factorio/factorio.app/Contents/data
0.000 Write data path: /Users/adam/Library/Application Support/factorio
0.000 Binaries path: /Users/adam/Library/Application Support/Steam/steamapps/common
0.017 Graphics options: [FullScreen: true] [VSync: true] [UIScale: 100%] [MultiSampling: OFF] [Graphics quality: normal] [Video memory usage: high] [Light scale: 100%] [Screen: 255] [DXT: false]
0.017 Available display adapters: 1
0.017 [0]: resolution 1440x900px at [0,0]
0.017 Create display on adapter 0. Size 1280x720 at position [70, 72].

Checklist

  • Celery report:
$ celery -A celery_tasks report

software -> celery:4.0.2 (latentcall) kombu:4.0.2 py:3.6.1
            billiard:3.5.0.2 py-amqp:2.1.4
platform -&gt; system:Darwin arch:64bit imp:CPython