Skip to content

Instantly share code, notes, and snippets.

View seanh's full-sized avatar

Sean Hammond seanh

View GitHub Profile
@seanh
seanh / blog.py
Created April 11, 2009 19:54
A little script that I use when I want to add an entry to my pyblosxom blog. Given a title it creates the file for me and deals with adding timestamps and figuring out a filename.
#!/usr/bin/env python
# TODO: support specifying categories on the command-line with tab-complete.
# TODO: support specifying extension as a command-line argument
# TODO: support specifying notes_dir as an option
# TODO: published_key, modified_key and timestr as command-line options
# TODO: specify editor on the command-line, or fall back on $EDITOR.
# TODO: support specifying a template to be used to create the file.
import os,sys,datetime,string
@seanh
seanh / CardLayoutDemo.java
Created May 17, 2009 18:24
A simple demonstration of Java Swing's CardLayout.
package scratch;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* A simple demonstration of Swing's CardLayout.
*
* @author seanh
@seanh
seanh / AutoSelectingTextField.java
Created May 25, 2009 15:17
A JTextField subclass that automatically selects all text when focused for the first time.
package storymaps;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* A JTextField that automatically selects all text when focused IF the text
* it currently contains is the initial text that it was constructed with.
* The text field also deselects the text when it loses focus.
@seanh
seanh / MyClass.java
Created May 25, 2009 15:22
Get a Swing GUI up and running. (Handy for testing swing components.)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyClass {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = frame.getContentPane();
@seanh
seanh / StyledTextWrapAndScroll.java
Created June 9, 2009 16:19
Swing problem with styled text component and scroll pane
package scratch;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author seanh
*/
@seanh
seanh / gist:132213
Created June 18, 2009 21:43
Use dmenu to lookup a word with gnome-dictionary
#!/bin/sh
gnome-dictionary --look-up `dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`
@seanh
seanh / gist:132216
Created June 18, 2009 21:45
Use dmenu to open files in gedit
#!/bin/sh
gedit `ls | dmenu -nb '#a5b474' -sb '#444444' -nf '#eeeeee' -sf '#a5b474' -fn '-*-*-*-*-*-*-20-*-*-*-*-*-*-*'`
@seanh
seanh / gist:165218
Created August 10, 2009 14:11
Read a file in Python
# The built-in function `open` opens a file and returns a file object.
# Read mode opens a file for reading only.
try:
f = open("file.txt", "r")
try:
# Read the entire contents of a file at once.
string = f.read()
# OR iterate over the file line-by-line:
for line in f:
# Do something with line.
@seanh
seanh / slug.py
Created November 7, 2009 21:42
An in-progress PyBlosxom plugin for handling slug URLs.
"""
A plugin for handling slug URLs. A slug is a nice, short URL for reaching a
particular post.
If a URL ending in /slug/hello-world is requested this plugin will search the
datadir for a post that has the metadata line:
#slug hello-world
If such a post is found the page for that post will be shown in the browser. So
@seanh
seanh / detect-broken-symlinks.py
Created November 8, 2009 19:48
A Python script to check for broken symlinks in the current working directory. I use this as part of a pre-commit hook with git.