Skip to content

Instantly share code, notes, and snippets.

brandon-rhodes /
Created Jul 12, 2018
Make Sphinx doctest insensitive to object address differences
# Append this to the `` file at the root of your Sphinx project
# that is already using the `sphinx.ext.doctest` extension:
import doctest
import re
import sphinx.ext.doctest as ext_doctest
ADDRESS_RE = re.compile(r'\b0x[0-9a-f]{1,16}\b')
class BetterDocTestRunner(ext_doctest.SphinxDocTestRunner):
# Inspired by the following sentence that I ran across this morning:
# "f_lineno is the current line number of the frame - writing to
# this from within a trace function jumps to the given line
# (only for the bottom-most frame). A debugger can implement a
# Jump command (aka Set Next Statement) by writing to f_lineno."
# There is an older implementation of a similar idea:
brandon-rhodes / VenusFromJupiter.ipynb
Created Aug 5, 2014
Where Venus appears from Jupiter, relative to Jupiter's axis and equator
View VenusFromJupiter.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
brandon-rhodes / gist:7ba1582c65a817ac3bcd
Created Jul 15, 2014
Two-level breadth-first descent using a generator
View gist:7ba1582c65a817ac3bcd
# Generators leave it up to the caller whether
# to build a list, or set, or maybe just to
# loop and not build a data structure at all:
def get_children(self):
for c in self.children.itervalues():
yield c
for c in self.children.itervalues():
for c2 in c.get_children():
yield c2
brandon-rhodes / listlines.rst
Created Jan 4, 2014
Test of putting literal lines inside of list items.
View listlines.rst

The following list has three items.

  • The first item is a normal paragraph with no lines breaks or other details.

  • The second item has only a single line break inside, as it has only two interior lines that each start with
brandon-rhodes /
Last active Jun 10, 2020
Script that builds a Google Earth overlay that projects the map of Tolkien’s Middle-earth atop modern Europe at the correct position and scale. Once the .kmz overlay file has been generated, simple open it using the File menu in Google Earth.
"""Project a map of Middle-earth on modern Europe.
Builds an `overlay.kmz` file in the current directory which should be
opened with Google Earth.
import os
import urllib2
import zipfile
from math import cos, radians
brandon-rhodes / refraction.ipynb
Created Apr 14, 2013
A quick iPython Notebook showing the algorithm that libastro, and thus PyEphem, uses to adjust the visual altitude of objects that are 15° or higher in the sky. (For objects closer to the horizon, a different formula is used; see `refract.c`.)
View refraction.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
brandon-rhodes / gist:3438936
Created Aug 23, 2012
Geographically correct alternative to's sweepArc() function
View gist:3438936
/* NOTE: this function requires the Google Maps "geometry" library which
Radarmatic does not currently load. It would need to load Maps with: */
function sweepArc(context, center_x, center_y, radius, width,
start_angle, end_angle) {
/* Special case: if we are being asked to draw the big gray circle
around the current radar site, then draw a big gray circle. */
brandon-rhodes /
Created Aug 10, 2012
Shell script that finds a free TCP port, runs the Python built-in HTTP file server on that port, and then opens a new Google Chrome tab displaying the site's root directory
# To use: cd to a directory you want to browse, and run this script.
# This lets you skip finding a free TCP port on your system and
# running SimpleHTTPServer on that port and pointing your browser there.
# Instead, we ask the SimpleHTTPServer to run at whichever free port the
# operating system would like to assign, we watch its output to see what
# port was in fact assigned, and then we open a new tab in the browser
# (in this case, Google Chrome) automatically.