Skip to content

Instantly share code, notes, and snippets.

View ncoghlan's full-sized avatar

Alyssa Coghlan ncoghlan

View GitHub Profile
@ncoghlan
ncoghlan / helpers.py
Created October 16, 2012 12:02
Tentative Python 3.4 async example
from concurrent.futures import Future
# This first part is a helper function to wait for the first Future in a group to complete
def _wait_first(futures):
# futures must be a set as items will be removed as they complete
# we create a signalling future to return to our caller. We will copy
# the result of the first future to complete to this signalling future
signal = Future()
signal.completed = None
def copy_result(completed):
@ncoghlan
ncoghlan / gist:2836237
Created May 30, 2012 13:10
A Django CBV example using some of the power of Python classes
# Example based on http://lukeplant.me.uk/blog/posts/djangos-cbvs-were-a-mistake/
# Not tested, just designed to give a general idea of the games CBVs let you play
from django.core.urlresolvers import reverse_lazy
from django.views.generic.edit import ProcessFormView
# Utilities for interacting with a user
class UserViewMixin(object):
_high_priority_user = None
@property