Skip to content

Instantly share code, notes, and snippets.

Richard Barnes r-barnes

View GitHub Profile
@r-barnes
r-barnes / plot_directive.py
Last active Jan 3, 2018
Modified plot_directive for matplotlib which preserves images between compilation
View plot_directive.py
"""
A directive for including a matplotlib plot in a Sphinx document.
By default, in HTML output, `plot` will include a .png file with a
link to a high-res .png and .pdf. In LaTeX output, it will include a
.pdf.
The source code for the plot may be included in one of three ways:
1. **A path to a source file** as the argument to the directive::
@r-barnes
r-barnes / mask_creator.py
Last active Oct 21, 2017 — forked from tonysyu/mask_creator.py
Tool to create polygon mask in Matplotlib
View mask_creator.py
"""
Interactive tool to draw mask on an image or image-like array.
Adapted from matplotlib/examples/event_handling/poly_editor.py
"""
import numpy as np
# import matplotlib as mpl
# mpl.use('tkagg')
import matplotlib.pyplot as plt
@r-barnes
r-barnes / sample_optim.mop
Last active Sep 10, 2015
Sample Model for Syntax Highlighting
View sample_optim.mop
package bob
import Modelica.Constants;
function mu
input Real t;
output Real y;
algorithm
y := 2.4*abs(cos(Constants.pi/12*t));
end mu;
@r-barnes
r-barnes / unambig_url_shortener.rb
Last active Aug 29, 2015
Richard's Unambiguous URL Shortener
View unambig_url_shortener.rb
#!/usr/bin/ruby
require 'digest'
#This function takes an input string, a desired hash length, and an attempt
#number. It returns a hash of the specified length encoded in an alphabet which
#is unambiguous in both upper and lower case. The attempt number should
#initially be 0. If the hash is found to conflict with a previous result, then
#the attempt number should be incremented and the function called again with the
#same input string and hashlen. If you have incremened attempt number an
You can’t perform that action at this time.