Skip to content

Instantly share code, notes, and snippets.

@mccutchen
mccutchen / funcgeo.py
Created October 27, 2009 22:41
Functional geometry
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Functional Geometry
Original idea by Peter Henderson, see
http://www.ecs.soton.ac.uk/~ph/funcgeo.pdf and
http://www.ecs.soton.ac.uk/~ph/papers/funcgeo2.pdf
# Unescape HTML Entities
#
# October 28, 2006 | Fredrik Lundh
#
# This function converts HTML entities and character references to
# ordinary characters.
#
# From: http://effbot.org/zone/re-sub.htm#unescape-html
import re, htmlentitydefs
@mccutchen
mccutchen / esquire.py
Created April 1, 2010 18:19
Creates a poster of Esquire magazine covers for a given decade.
"""Creates a poster of Esquire magazine covers for a given decade.
The covers for a given decade can be downloaded with something like
the following curl command:
curl -O http://www.esquire.com/cm/esquire/cover-images/196[0-9]_[1-12].jpg
"""
import os, sys
import Image
[4/9/10 3:00:20 PM] Will McCutchen: Hollow
[4/9/10 3:00:43 PM] frend29: hallo
[4/9/10 3:00:55 PM] Will McCutchen: Halo!
[4/9/10 3:01:08 PM] frend29: hi
[4/9/10 3:01:33 PM] Will McCutchen: Hillo there!
[4/9/10 3:02:04 PM] frend29: who r u
[4/9/10 3:02:26 PM] Will McCutchen: Me am Will. You am who?
[4/9/10 3:03:06 PM] frend29: i am smeth
[4/9/10 3:03:36 PM] Will McCutchen: What kind of name is that?
[4/9/10 3:04:18 PM] frend29: somouni jalal
@mccutchen
mccutchen / ingredientparser.py
Created April 9, 2010 21:08
A rough first translation of Jesse's BNF grammar into pyparsing
from string import lowercase, uppercase
from pyparsing import (Word, Literal, ZeroOrMore, Regex, Or, CharsNotIn,
Optional, CaselessLiteral, Combine, Suppress,
srange, alphas, alphanums, nums)
def Literals(s, splitchar=None):
"""Splits the given string (defaults to splitting on spaces), turns each
item into a Literal, and combines them into an Or clause."""
return Or(map(Literal, s.split(splitchar)))
map:help.asciiArtToMap([
// Hey, wait! This is an ascii art of the map? Yes! "asciiArtToMap" convers an array of string in an array of arrays, using...
"||T----------------------------------------------------TxxT----------------------------------------------------T||",
"|||| ||xx|| ||||",
"|||| . . . . . . . . . . . . ||xx|| . . . . . . . . . . . . ||||",
"|||| ||xx|| ||||",
"|||| . T------------T . T----------------T . ||xx|| . T----------------T . T------------T . ||||",
"|||| ||xxxxxxxxxx|| ||xxxxxxxxxxxxxx|| ||xx|| ||xxxxxxxxxxxxxx|| ||xxxxxxxxxx|| ||||",
"|||| o ||xxxxxxxxxx|| . ||xxxxxxxxxxxxxx|| . ||xx|| . ||xxxxxxxxxxxxxx|| . ||xxxxxxxxxx|| o ||||",
"||||
@mccutchen
mccutchen / gist:393804
Created May 7, 2010 18:16
Get a Django shell in production
cd /home/webapps/kidjango/current
export PYTHONPATH=`pwd`:$PYTHONPATH
django-admin.py shell --settings=key.settings_ki
@mccutchen
mccutchen / gist:443892
Created June 18, 2010 16:53
Remote fixture loading hack
# GAE_ENV=production ./manage.py remoteshell, then...
key-ingredient> from ki.webapp.gaetest import fixtures
key-ingredient> from help import models
key-ingredient> fixtures.load_fixtures('help/fixtures/faqs.json', [models])
@mccutchen
mccutchen / fabfile.py
Created August 17, 2010 18:35
A first cut at a fabfile that meets our App Engine deployment criteria
from __future__ import with_statement
import functools
import os
import sys
from fabric.api import *
from google.appengine.api import appinfo
# Answering this question:
# http://stackoverflow.com/questions/3679306/
>>> import json
>>> class Foo(object):
... def __init__(self, a, b):
... self.a = a
... self.b = b
...
>>> foo = Foo('a string', ['a', 'list', 'of', 'strings'])