Skip to content

Instantly share code, notes, and snippets.

@asross
asross / cacheprop.py
Last active April 9, 2017 17:23
Like @Property, but only evaluated once
class cacheprop(object):
def __init__(self, getter): self.getter = getter
def __get__(self, shelf, _):
value = self.getter(shelf)
shelf.__dict__[self.getter.__name__] = value
return value
class Foo():
@cacheprop
def bar(self):
@asross
asross / figure_grid.py
Last active September 7, 2018 14:44
A helper to plot grids of graphs in matplotlib.pyplot
"""
Examples:
with figure_grid(5, 3) as grid:
grid.next()
# plot something
grid.next()
# plot something
# ...etc
@asross
asross / KDN5.xml
Last active May 10, 2016 20:20
Attempt at demonstrating OrderSet chemotherapy regimen timing using as few extensions as possible
<OrderSet>
<moduleMetadata>
<identifier>
<system value="http://nccn.org/ordertemplates" />
<value value="KDN5" />
</identifier>
</module>
<!-- Here we only have one course (which repeats for 6 21-day cycles), but we could have multiple courses -->
<action>
@asross
asross / README.md
Created January 18, 2016 14:01 — forked from benelsen/README.md

The current solar terminator is shown in blue, assuming a spherical Earth and an axial tilt of 23.4°. Hmm, on second thought, I think I didn’t account for the orbit of the Earth around the sun, so this is not entirely accurate. Please fork this example and fix it!

@asross
asross / supersub.sh
Created July 3, 2015 15:12
supersub
## replace all instances of $1 with $2 within $3.
function supersub {
ack -l "$1" "$3" | xargs perl -p -i -e "s/$1/$2/g"
}
class DeepOpenStruct
def initialize(hash)
hash.each { |k, v| define_singleton_method(k) {
instance_variable_get(:"@#{k}") || instance_variable_set(:"@#{k}", coerce(v))
} }
end
def [](k)
send(k)
end
# execute e.g.
# $ kill_matching phantomjs
function kill_matching {
export matchee=$1
ruby -e 'puts `ps aux | grep #{`echo $matchee`}`.split("\n").each{|l| `kill -9 #{l.split[1]}` unless l.include?("grep") }'
}
@asross
asross / font_randomizer.js
Last active August 29, 2015 13:58
Randomize the size and family of all fonts.
function randomizeFonts() {
if (window.jQuery) {
elements = jQuery('*');
families = jQuery.unique(elements.map(function() { return jQuery(this).css('font-family') }));
families.push("'comic sans ms', sans-serif");
elements.each(function() {
jQuery(this).css('font-size', 32*Math.random() + 'px');
jQuery(this).css('font-family', families[Math.floor(Math.random()*families.length)]);
});
def twitter_puddle(wall):
height = max(wall)
total = 0
for x in range(1, len(wall)-2):
lowest_wall = min(max(wall[:x]), max(wall[x+1:]))
if lowest_wall > wall[x]:
total += lowest_wall - wall[x]
return total
assert(twitter_puddle([2, 5, 1, 2, 3, 4, 7, 7, 6]) == 10)
function groc { # git rebase origin/{current}
local remote_branch="${1:-origin}/$(git branch | grep \* | cut -c 3-)"
git rebase $remote_branch
}
function gpoc { # git push origin {current}
local current_branch="$(git branch | grep \* | cut -c 3-)"
git push origin $current_branch
}