Skip to content

Instantly share code, notes, and snippets.

View seanh's full-sized avatar

Sean Hammond seanh

View GitHub Profile
@seanh
seanh / README
Created January 21, 2009 19:35
My Panda3D snippets formerly on snipplr.com.
This was broken up into individual gists (search for Panda3D).
@seanh
seanh / README
Created January 21, 2009 19:37
My implementation of Panda3D's messager pattern
My implementation of Panda3D's messager pattern
This is my implementation of the messager pattern used by Panda3D for event
handling. It's a really nice idea but I think Panda's version is implemented
weirdly, it uses the subscribe objects as keys in the dictionary. That means
that if you want more than one object to subscribe to the same message you have
to subclass DirectObject and use self.accept(...), can't just call the messager
directly or you'll get a different behaviour, it means that a single object
instance can't subscribe two different functions to the same message, and it
means that your objects have to be hashable (!) because the messager uses them

Moved to

@seanh
seanh / README
Created January 30, 2009 14:20
Now Playing in Rhythmbox web app
A little web app that I wrote to tell the world what song is currently
playing in rhtyhmbox on the jukebox at the forest cafe. Requires rhythmbox-
client and web.py 0.31. templates.html should go in a folder called
templates.
package scrapbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Interface that must be implemented by objects that subscribe to messages.
*/
@seanh
seanh / HTMLNode.java
Created March 12, 2009 14:37
HTMLNode is a Piccolo node for rendering HTML text.
/* Copyright 2005, University of Colorado */
/*
* CVS Info -
* Filename : $Source$
* Branch : $Name$
* Modified by : $Author$
* Revision : $Revision$
* Date modified : $Date$
*/
@seanh
seanh / ConcreteObservable.java
Created March 13, 2009 19:26
Observer design pattern in java
package observer;
import java.util.Set;
import java.util.HashSet;
public class ConcreteObservable<T> implements Observable<T> {
private Set<Observer<T>> observers = new HashSet<Observer<T>>();
public void addObserver(Observer o) {
@seanh
seanh / walk.py
Created March 18, 2009 14:26
Recursively walk a directory in Python with os.walk.
"""Recursively walk a directory with os.walk."""
import os
base_dir = '/home/seanh' # The directory to walk
for root, dirs, files in os.walk(base_dir):
print 'root: ',root
print ' dirs:'
for d in dirs:
print ' ',d
@seanh
seanh / README.mkdn
Created April 10, 2009 16:28
Python-Markdown 2.0 plugin for Pyblosxom

Moved to

@seanh
seanh / formatFilename.py
Created April 11, 2009 18:30
Turn any string into a valid filename in Python.
def format_filename(s):
"""Take a string and return a valid filename constructed from the string.
Uses a whitelist approach: any characters not present in valid_chars are
removed. Also spaces are replaced with underscores.
Note: this method may produce invalid filenames such as ``, `.` or `..`
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
and append a file extension like '.txt', so I avoid the potential of using
an invalid filename.