Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| import simplejson as json | |
| import lxml | |
| class objectJSONEncoder(json.JSONEncoder): | |
| """A specialized JSON encoder that can handle simple lxml objectify types | |
| >>> from lxml import objectify | |
| >>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>") | |
| >>> objectJSONEncoder().encode(obj) | |
| '{"price": 1.5, "author": "W. Shakespeare"}' | |
| """ | 
| from django.core.exceptions import ValidationError | |
| from django.db.models import Field, CharField | |
| __all__ = ['MultiColumnField'] | |
| try: | |
| from hashlib import md5 | |
| except ImportError: | |
| from md5 import new as md5 | 
| class QuerySetDoubleIteration(Exception): | |
| "A QuerySet was iterated over twice, you probably want to list() it." | |
| pass | |
| # "Skinny" here means we use iterator by default, rather than | |
| # ballooning in memory. | |
| class SkinnyManager(Manager): | |
| def get_query_set(self): | |
| return SkinnyQuerySet(self.model, using=self._db) | 
| from PIL import Image | |
| import scipy | |
| import scipy.cluster | |
| from pprint import pprint | |
| image = Image.open('logo_newsblur_512.png') | |
| NUM_CLUSTERS = 15 | |
| # Convert image into array of values for each point. | |
| ar = scipy.misc.fromimage(image) | 
| These are the scripts I use to create the playlists for the AI Class (available here: http://www.mrspeaker.net/2011/10/26/ai-class-playlists/). It's not pretty, but it works. I put them up here due to popular demand. | |
| The first stage is to grab the video list HTML from YouTube and extract/sort the videos. This is done with the Video_ID_scraper.html file (instructions there). | |
| Next, paste the video info into the YouTube_Playlist_Uploader.py script and it generates the playlist. It relies on the GData APIs so you need a dev key etc. | |
| Any questions to [email protected] | 
| pm list packages -f | 
| alias server='open http://localhost:8000 && python -m SimpleHTTPServer' | 
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/usr/bin/env sh | |
| ## | |
| # This is script with usefull tips taken from: | |
| # https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
| # | |
| # install it: | |
| # curl -sL https://raw.github.com/gist/2108403/hack.sh | sh | |
| # | 
| # npm mirroring, courtesy @jbuck and Mozilla. | |
| # See https://github.com/jbuck/npm-readonly-mirror | |
| curl npmrc.zeke.xxx >> .npmrc | |
| git add .npmrc | |
| git commit -m "mozilla .npmrc" | |
| git push heroku master |