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 / test-nbdime-html-diff.py
Last active January 25, 2024 19:39
Python script showing how html diffs of Jupyter notebooks can be created non-interactively (e.g. from the command-line in CI) using nbdime.
"""
Python script showing how html diffs of Jupyter notebooks can be created
non-interactively (e.g. from the command-line in CI) using nbdime
(https://github.com/jupyter/nbdime) in combination with nbdime PR #744:
https://github.com/jupyter/nbdime/pull/744
Usage:
$ python test-nbdime-html-diff.py NB_PATH1 NB_PATH2
@cjerdonek
cjerdonek / test-rw.py
Created June 27, 2017 00:55
Python asyncio readers-writer synchronization example with lock-free reads
import asyncio
import random
NO_READERS_EVENT = asyncio.Event()
NO_WRITERS_EVENT = asyncio.Event()
WRITE_LOCK = asyncio.Lock()
class State:
@cjerdonek
cjerdonek / test_yield.py
Created November 1, 2014 16:28
A Python 3.4 module to illustrate a difference between exception handling in generators and context managers.
"""
This module illustrates a difference in exception handling between
generator functions and context managers.
This script should be run with **Python 3.4.2** or higher (which is what
it was originally run with).
To witness what is illustrated in this module, run the following two
commands from the command-line.
@cjerdonek
cjerdonek / md2rst.py
Last active August 29, 2015 14:07
Python Pandoc filter for converting GitHub markdown to Python reST long_description for PyPI
#!/usr/bin/env python
"""
Python Pandoc filter [1] for converting a GitHub markdown file to a Python
reST long_description (suitable for display on PyPI).
Sample usage:
$ pandoc --filter ./md2rst.py --write=rst --output=long_description.rst README.md
@cjerdonek
cjerdonek / drive.js
Created August 31, 2014 01:48
Javascript example of using Selenium WebDriver's Javascript API to connect to Sauce Labs
// This is an example of using the Selenium WebDriver's Javascript API
// to connect to Sauce Labs (using the remote web driver) and doing
// a simple test.
//
// To run from the command-line:
//
// $ node drive.js
//
// You need to have selenium-webdriver installed with npm.
@cjerdonek
cjerdonek / .bashrc
Created November 21, 2013 15:30
A snippet to automatically call virtualenvwrapper's "workon" command when entering a directory in the shell. This can be added to your .profile, .bash_profile, .bashrc, etc.
# Call virtualenvwrapper's "workon" if .venv exists. This is modified from--
# http://justinlilly.com/python/virtualenv_wrapper_helper.html
# which is linked from--
# http://virtualenvwrapper.readthedocs.org/en/latest/tips.html#automatically-run-workon-when-entering-a-directory
check_virtualenv() {
if [ -e .venv ]; then
env=`cat .venv`
echo "Found .venv in directory. Calling: workon ${env}"
workon $env
fi
@cjerdonek
cjerdonek / backup_environments.sh
Created August 21, 2013 18:12
A script to back up environments from chef server to your git repo.
# Back up environments from chef server to a git repo.
# Run this from the top of your chef repo.
envs=`knife environment list`
for env in $envs
do
path="environments/${env}.json"
knife environment show $env -F json > $path
git add $path
done
@cjerdonek
cjerdonek / getattr-example.py
Created November 14, 2012 01:51
A __getattr__ example.
"""
An example of decorating a built-in type with another object.
Attributes and methods on the built-in type delegate to the other object.
"""
class WrappedInt(int):
"""
@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):
@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