Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
from django import forms
import datetime
import base64
import hmac, sha, simplejson
from django.utils.safestring import mark_safe
"""
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1434
# http://github.com/simonw/django-signed/raw/master/django_signed/baseconv.py
from baseconv import BaseConverter
class Base32Converter(BaseConverter):
# Human-friendly, see http://www.crockford.com/wrmg/base32.html
replacements = {
'o': '0',
'O': '0',
'I': '1',
'i': '1',
# Scrape two months worth of horoscopes from shine.yahoo.com
from BeautifulSoup import BeautifulSoup as Soup
import urllib, datetime
URL = "http://shine.yahoo.com/astrology/%s/daily-extended/%s/"
signs = (
'aries',
'leo',
/* Use this to cause a function to fire no more than once every 'ms' milliseconds.
For example, an expensive mousemove handler:
$('body').mouseover(ratelimit(function(ev) {
// ...
}, 250));
*/
function ratelimit(fn, ms) {
var last = (new Date()).getTime();
@simonw
simonw / howto.txt
Created February 11, 2010 23:49 — forked from joonathan/howto.txt
Save the supervisord.initscript script as /etc/init.d/supervisord
Run /usr/sbin/update-rc.d -f supervisord defaults
import re
p = re.compile(
r'(<b>|</b>|<i>|</i>|<blockquote>|</blockquote>|<a href="[^"]+">|</a>)',
re.IGNORECASE
)
escape = lambda s: s.replace(
'&', '&amp;'
).replace(
'>', '&gt;'
"""
Import Yahoo! GeoPlanet in to MongoDB.
This creates a geoplanet collection containing documents like this:
{
'_id': woeid,
'name': name,
'iso': iso,
'language': language,
import itertools
def x_at_a_time(iterator, x):
def fn((item, i)):
return i / x
it = itertools.groupby(itertools.izip(iterator, itertools.count()), fn)
for key, group in it:
yield list(p[0] for p in group)
from baseconv import BaseConverter
class Base32Converter(BaseConverter):
# Human-friendly, see http://www.crockford.com/wrmg/base32.html
replacements = {
'o': '0',
'O': '0',
'I': '1',
'i': '1',
'L': '1',
from django.http import HttpResponse
from django.utils import simplejson
import re
callback_re = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]+$')
def api_response(request, status_code, info):
info['status'] = status_code
if request.GET.get('format', '') == 'html':
return HttpResponse(