Skip to content

Instantly share code, notes, and snippets.

def get_class(class_to_get, *args, **kwargs):
"""Will get the class regardless of whether it's a module or not:
>>> get_class('module.MyClassName')
MyClassName()
"""
try:
dot = class.rindex('.')
except ValueError:
pass
else:
# A test runner that doesn't require a database, and then reports coverage of your Django apps
# Usage: in settings.py, add:
# TEST_RUNNER="path.to.nodb_coverage_testrunner.run_tests"
import os
import unittest
from glob import glob
from django.test.utils import setup_test_environment, teardown_test_environment
from django.conf import settings
<div class="form_row{% if field.errors %} has_errors{% endif %}{% if class %} {{ class }}{% endif %}{% if field.field.required %} required{% endif %}">
<label for="{{ field.auto_id }}">
{% if label %}{{ label }}{% else %}{{ field.label }}{% endif %}
{% if field.field.required %}<span>(required)</span>{% endif %}
</label>
{{ field }}
{% if field.errors %}
<p class="error">{{ field.errors|join('<br>') }}</p>
{% endif %}
{% if help_text %}
from email.utils import formatdate
from email.message import Message
from email.mime.text import MIMEText
import smtplib
import textwrap
def send_email(to_address, to_name, from_address, from_name, subject, body, **kwargs):
msg = MIMEText(body)
msg['To'] = '%s <%s>' % (to_name, to_address)
msg['From'] = '%s <%s>' % (from_name, from_address)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>myvmname.virtualbox</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/VBoxHeadless</string>
import urllib
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
def url_params(url, **kwargs):
bits = url.split('?')
query_vars = {}
if len(bits) > 1:

Smarkets (London, UK)

Job description

Smarkets, a London-based betting exchange startup, is looking for an experienced front end web developer for a full time position with an immediate start.

Our front end application is a collection of Django apps built on an exclusively Python API client (to a RESTful Erlang API), and we're looking for someone to build out user-facing features.

import re
pattern = re.compile('^.*?((?<!\.[a-z0-9]{8})png|jpg|gif|swf|ico|flv|zip)$')
# I want the first two to match, but not the second two
file_list = [
'main.ie6.zip',
'main.zip',
'main.cb1c4aa1.zip',
'main.cb1c4aa1.cb1c4aa1.zip'
]
all_possible_plays = Play.objects.filter(preview_only=False, play_start__gte=start_date,
play_start__lt=end_date, users__is_staff=False)
for play in all_possible_plays:
if play_history.has_key(play.song.pk):
#increment tallies
play_history[play.song.pk]['plays'] += 1
if play.credit_taken:
play_history[play.song.pk]['credit_plays'] += 1
@bradwright
bradwright / gist:595081
Created September 24, 2010 08:57 — forked from andyhd/gist:595058
# a heavy int is one where the average of the digits is greater than 7
# eg: 8678 is heavy because (8 + 6 + 7 + 8) / 4 = 7.25
# 8677 is not heavy because ( 8 + 6 + 7 + 7) / 4 = 7
def is_heavy(my_number, heaviness=7):
# cast @my_number to a string so we can iterate over it, then create a list of
# numbers greater than @heaviness. if this list length is greater to or equal than half
# the length of the original list, it's heavy
return len([i for i in str(my_number) if int(i) > heaviness]) >= (len(str(my_number)) / 2)