Skip to content

Instantly share code, notes, and snippets.

View r-barnes's full-sized avatar

Richard Barnes r-barnes

View GitHub Profile
@r-barnes
r-barnes / mask_creator.py
Last active May 8, 2023 16:25 — forked from tonysyu/mask_creator.py
Tool to create polygon mask in Matplotlib
"""
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
#include <cub/cub.cuh>
#include <thrust/device_vector.h>
#include <algorithm>
#include <chrono>
#include <random>
struct SumCountRet {
@r-barnes
r-barnes / plot_directive.py
Last active January 3, 2018 19:00
Modified plot_directive for matplotlib which preserves images between compilation
"""
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 / sample_optim.mop
Last active September 10, 2015 01:48
Sample Model for Syntax Highlighting
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 August 29, 2015 14:05
Richard's Unambiguous URL Shortener
#!/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