This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 __future__ import division | |
import os | |
import subprocess | |
try: | |
from cStringIO import StringIO | |
except ImportError: | |
from StringIO import StringIO |
This file contains hidden or 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 import models | |
from django import forms | |
from django.forms.models import modelform_factory | |
class ValidatingModel(models.Model): | |
class Meta: | |
abstract = True | |
def __init__(self, *args, **kwargs): | |
self.model_form_class = modelform_factory(self.__class__) |
This file contains hidden or 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.conf import settings | |
from django.core.exceptions import ImproperlyConfigured | |
from django.db.models import loading | |
from django.db.models.fields.related import RelatedField | |
INDENT = ' ' | |
for app_name in settings.INSTALLED_APPS: | |
print app_name | |
app_label = app_name.split(".")[-1] | |
try: |
This file contains hidden or 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 __future__ import division | |
import datetime | |
import hashlib | |
import inspect | |
import math | |
import pytz | |
import time | |
import urllib | |
from common.cache import incr, decr |
This file contains hidden or 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.core.cache import cache | |
def _incr_decr(key, incr=True, min=None, max=None, initial=None): | |
'''Incr/decr function which handles key creation as needed''' | |
# FIXME: min/max have rampant race conditions which could be fixed using | |
# memcache's "cas" feature, but current pylibmc + libmemcached causes a | |
# segfault when used. | |
initial = initial or min or 0 |