This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def paginate_iterable(iterable, page_size): | |
current_page = [] | |
for item in iterable: | |
current_page.append(item) | |
if len(current_page) == page_size: | |
yield current_page | |
current_page = [] | |
if len(current_page) > 0: | |
yield current_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import signals | |
class CompositeBitField(object): | |
def __init__(self, fields): | |
self.fields = fields | |
def contribute_to_class(self, cls, name): | |
self.name = name | |
self.model = cls | |
cls._meta.add_virtual_field(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String file contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"playlist": { | |
"creator": "David Gouldin", | |
"track": [ | |
{ | |
"info": "http://www.rdio.com/artist/Rick_Astley/album/The_Greatest_Hits/", | |
"album": "The Greatest Hits", | |
"location": [ | |
"http://rd.io/e/QVGOBDdzOP0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
f = open('playlist.json', 'r') | |
playlist = json.loads(f.read()) | |
f.close() | |
tracks = [] | |
track_ids = [] | |
for track in playlist['playlist']['track']: | |
track_id = track['identifier'][0] | |
if track_id not in track_ids: | |
tracks.append(track) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exclude_params = ( | |
u'realm', | |
u'oauth_signature', | |
) | |
params = filter(lambda i: i[0] not in exclude_params, params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div id="fb-root"></div> | |
<script src="//connect.facebook.net/en_US/all.js"></script> | |
<script type="text/javascript"> | |
var scopes = [ | |
'email', | |
'user_birthday', | |
'user_likes', | |
'user_interests', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `foo` ( | |
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, | |
`name` varchar(255) NOT NULL | |
); | |
CREATE TABLE `bar` ( | |
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, | |
`name` varchar(255) NOT NULL, | |
`foo_id` integer NOT NULL | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@utils.filter_params | |
def prepare_headers(params, headers=None, realm=None): | |
"""Prepare the Authorization header. | |
Per `section 3.5.1`_ of the spec. | |
Protocol parameters can be transmitted using the HTTP "Authorization" | |
header field as defined by `RFC2617`_ with the auth-scheme name set to | |
"OAuth" (case insensitive). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: import librabbitmq | |
In [2]: connection = librabbitmq.Connection(userid='bad', password='bad') | |
--------------------------------------------------------------------------- | |
ConnectionError Traceback (most recent call last) | |
<ipython-input-2-23c4e6e59779> in <module>() | |
----> 1 connection = librabbitmq.Connection(userid='bad', password='bad') | |
/Users/dgouldin/virtualenv/djangocon2012/lib/python2.7/site-packages/librabbitmq/__init__.pyc in __init__(self, host, userid, password, virtual_host, port, channel_max, frame_max, heartbeat, lazy, **kwargs) | |
166 self._avail_channel_ids = array('H', xrange(self.channel_max, 0, -1)) |