Skip to content

Instantly share code, notes, and snippets.

View invisiblefunnel's full-sized avatar

Danny Whalen invisiblefunnel

View GitHub Profile
def segmentize(points, km):
npoints = len(points)
if npoints == 0:
return []
elif npoints == 1:
return [points[0]]
a, b = points[:2]
rest = segmentize(points[2:], km)
if haversine(a, b) > km:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Timetable layout is a hard problem to solve for all cases. Here’s an approach which will not generalize to all routes, but works often enough to be useful (link). In short, build a directed graph of all adjacent stop pairs (edges) made by trips in the timetable and topologically sort it to get the “header row”, then layout the stop times accordingly. A fully generalized approach requires finding an approximation of the shortest common supersequence of the set of stopping patterns—which is definitely non-trivial to do really well.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function parse_git_branch {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function color_git_branch {
# '$1' represents the first variable passed to the script
if [[ "x$1" = "x" ]]; then
echo -e "$1"
else
local status="$(git status 2> /dev/null | tail -n1)"