Skip to content

Instantly share code, notes, and snippets.

View cjerdonek's full-sized avatar

Chris Jerdonek cjerdonek

  • Shotwell Labs, Inc.
  • San Francisco, CA
View GitHub Profile
@cjerdonek
cjerdonek / url-autolink-test
Created January 23, 2011 02:51
Testing URL autolinking.
@cjerdonek
cjerdonek / test_issue_53.py
Created December 20, 2011 01:42
a git-bisect script to find where pystache issue #53 was fixed
#!/usr/bin/env python
# coding: utf-8
"""
A script to use in conjunction with git-bisect to find the point
in pystache's development branch at which issue #53 was fixed:
https://github.com/defunkt/pystache/pull/53
Because git-bisect expects the "bad" outcome to come after the "good"
@cjerdonek
cjerdonek / define_settitle.sh
Created May 8, 2012 17:21
Set the title of a Mac Terminal
#!/bin/bash
# Set the title of a Mac Terminal. From--
# http://www.devdaily.com/blog/post/mac-os-x/change-title-bar-of-mac-os-x-terminal-window
settitle() {
echo -n -e "\033]0;${1}\007"
}
@cjerdonek
cjerdonek / runtests.py
Created May 16, 2012 04:19
In Python, add extra tests to a unittest.main() test run (without depending on global state).
import unittest
def run_tests(data):
extra_tests = create_extra_tests(data)
test_program_class = make_test_program_class(extra_tests)
# In this constructor call you can include any of the arguments supported
# by unittest.main().
test_program_class() # runs tests.
@cjerdonek
cjerdonek / newtab.scpt
Created May 20, 2012 20:56
Initialize a new Terminal tab from the command-line (Mac OS X)
# Mac OSX: initialize a new Terminal tab from the Terminal command-line.
#
# Usage: osascript newtab.scpt TITLE PATH
#
# Summary:
#
# (1) opens a new terminal tab in the same window,
# (2) sets the title of the tab, and
# (3) cds into an initial directory.
#
@cjerdonek
cjerdonek / rename.sh
Created June 13, 2012 05:53
Shell script to git-mv several files (for Groome)
dir_names=`ls tests`
for dir_name in $dir_names
do
git mv "tests/$dir_name/project" "tests/$dir_name/structure"
done
@cjerdonek
cjerdonek / test.py
Created June 23, 2012 11:27
Sample code for Pystache issue #123
# Sample code for: https://github.com/defunkt/pystache/issues/123
class MyClass(object):
def __init__(self, data):
self.attr = 5
self.data = data
def __getitem__(self, key):
return self.data[key]
@cjerdonek
cjerdonek / test.py
Created June 24, 2012 19:16
For Python unit testing, using a context manager instead of setUp() and tearDown()
# For Python unit testing, an idea for how to use a context manager for
# a unittest.TestCase instead of the setUp() and tearDown() methods.
#
# This is a possible answer to--
#
# http://stackoverflow.com/questions/8416208/in-python-is-there-a-good-idiom-for-using-context-managers-in-setup-teardown
from contextlib import contextmanager
import unittest
@cjerdonek
cjerdonek / strip-prefix.sh
Created July 14, 2012 14:00
Bash shell script to strip a fixed-length prefix from the names of directories in a directory.
# Bash shell script to strip a fixed-length prefix from the
# names of directories in a directory.
dir_names=`ls -d`
for dir_name in $dir_names
do
mv $dir_name ${dir_name:7}
done
@cjerdonek
cjerdonek / mixin-example.py
Created November 14, 2012 01:06
A simple mixin example
"""
A simple mixin example.
This script illustrates using a mixin to impart a "foo" method to other
class definitions.
"""
class FooMixin(object):