Skip to content

Instantly share code, notes, and snippets.

View ashchristopher's full-sized avatar

Ash Christopher ashchristopher

  • Shopify
  • Toronto, Ontario
View GitHub Profile
> /vagrant/src/sandbox/python-social-auth/social/backends/base.py(40)complete()
39 def complete(self, *args, **kwargs):
---> 40 return self.auth_complete(*args, **kwargs)
41
> /vagrant/src/sandbox/python-social-auth/social/backends/oauth.py(355)auth_complete()
354
--> 355 def auth_complete(self, *args, **kwargs):
356 """Completes loging process, must return user instance"""
ipdb> n
@ashchristopher
ashchristopher / Django - TypedChoiceField
Created May 13, 2015 19:25
Django's ChoiceField error.
from django import forms
CHOICES = (
('1', 1),
('2', 2),
('3', 3),
('4', 4),
('5', 5),
)
@ashchristopher
ashchristopher / gist:143d43f903d3bf8fc79d
Created January 27, 2015 04:08
Better iterator for QuerySets
import gc
def queryset_iterator(queryset, chunksize=1000):
"""
Iterate over a Django Queryset ordered by the primary key
This method loads a maximum of chunksize (default: 1000) rows in it's
memory at the same time while django normally would load all rows in it's
memory. Using the iterator() method only causes it to not preload all the
classes.
class BaseRouter(object):
"""
Base class for routers allowing several apps to be grouped in a shard group.
Subclasses need to define a list of app names and a prefix for the db names of the shard group.
e.g.,
app_list = ('my_app1', )
db_names_prefix = 'my_shard_'
"""
app_list = tuple()
@ashchristopher
ashchristopher / keybase.md
Created August 13, 2014 18:48
keybase.md

Keybase proof

I hereby claim:

  • I am ashchristopher on github.
  • I am ashchristopher (https://keybase.io/ashchristopher) on keybase.
  • I have a public key whose fingerprint is 4479 24F8 BAB0 4C22 34EF 776C 8BE8 BEDB C5B4 0CC5

To claim this, I am signing this object:

@ashchristopher
ashchristopher / simple_monkey_patch
Created April 23, 2014 14:41
Simple monkeypatch example.
In [1]: def monkey_patch():
...: return u"This is a monkey patch!"
...:
In [2]: import uuid
In [3]: print uuid.uuid4()
dda44145-8555-44c8-a9eb-e7337ee94437
In [4]: uuid.uuid4 = monkey_patch
@ashchristopher
ashchristopher / gist:9197591
Created February 24, 2014 21:30
Mock out a signal receiver?
def _track_event(event_name, identity_user_id, event_id, **kwargs):
EventTracker.track('api', 'hook.processed', data={
'event': event_name,
'identity_user_id': identity_user_id,
'event_id': event_id,
})
@receiver(hook_event_received, dispatch_uid='hooks.models.track_event')
def track_event(event_name, identity_user_id, event_id, **kwargs):
#!/bin/sh
setup_brew () {
if ![-f "/usr/local/bin/brew"]; then
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
fi
}
setup_ipython () {
brew install readline
@ashchristopher
ashchristopher / gist:5776108
Created June 13, 2013 18:26
List all django urls
import urls
def show_urls(urllist, depth=0):
for entry in urllist:
print " " * depth, entry.regex.pattern
if hasattr(entry, 'url_patterns'):
show_urls(entry.url_patterns, depth + 1)
show_urls(urls.urlpatterns)
@ashchristopher
ashchristopher / json_encoder
Created April 19, 2013 00:41
Example JSON encoder.
from django.db import models
from django.utils.functional import Promise
from django.utils.encoding import force_unicode
from django.utils import simplejson as json
from decimal import Decimal
from django.core import serializers
from django.conf import settings
from django.http import HttpResponse, HttpResponseForbidden, Http404
from django.core.mail import mail_admins
from django.db.models.query import QuerySet