Skip to content

Instantly share code, notes, and snippets.

View coldnebo's full-sized avatar

Larry Kyrala coldnebo

View GitHub Profile
@coldnebo
coldnebo / another_partial.html.erb
Last active August 29, 2015 14:09
capture doesn't work outside of the view it's in?
alert('something');
@coldnebo
coldnebo / require_speedtest.rb
Last active August 29, 2015 14:10
measure how fast gem require is.
require 'benchmark'
include Benchmark
def with_require
fork { require 'rake' }
end
def without_require
fork {}
end
@coldnebo
coldnebo / turbulence.m
Last active August 29, 2015 14:24
script for extracting the turbulence around a photo of a building.
close all
% read the building picture
I1 = imread('IMG_5380.JPG');
% correct the rotation
I2 = imrotate(I1, -90);
% crop it to the area of interest
I3 = imcrop(I2,[378.5 0.5 948 814]);
% focus on an roi to isolate just the sky from the building...
rp = [0 815;70 815;251 435;570 363;949 657;949 0;0 0];
@coldnebo
coldnebo / genhtml.rb
Last active August 29, 2015 14:26
poor man's webcomponents, circa May 2010
# genhtml.rb
require 'rubygems'
require 'xml/libxml'
require 'libxslt'
xml_file = ARGV[0]
stylesheet_doc = XML::Document.file('homework.xsi')
stylesheet = LibXSLT::XSLT::Stylesheet.new(stylesheet_doc)
@coldnebo
coldnebo / lambda_no_call.rb
Created July 28, 2010 20:07
blog: how to call lambdas without call()
# inspired by the protovis library pv.Scale.linear().range()
# adapted from rspec codebase
def let(name, scale_function)
Kernel.send :define_method, name do |p|
scale_function.call(p)
end
end
# returns a mapping function from the desired domain (x1,x2) to the desired range (y1,y2)
@coldnebo
coldnebo / gist:832527
Created February 17, 2011 19:58
blog: example of possible ruby xml marshaling...
<foo>
<bar @mike="hi">
<ug>what</ug>
<ug>who</ug>
</bar>
</foo>
> foo.bar.mike # = "hi"
> foo.bar.ug # = ["what", "who]
> foo.bar.ug[0] # = "what"
@coldnebo
coldnebo / Rakefile
Created June 1, 2011 23:50
patch for rake in ruby-1.9.2-p180
# testing rakefile
task :default do
sh('exit 1')
end
@coldnebo
coldnebo / string_patch.rb
Created June 9, 2011 18:49
ruby 1.9.2 character encoding helper
class String
def hexbytes
self.bytes.to_a.map {|c| c.to_s(16).upcase}.join
end
def hexchars
self.chars.to_a.map {|c| c.hexbytes}
end
def unicodechars
@coldnebo
coldnebo / bind_cursor.bash
Created August 18, 2011 18:44
bash helper to navigate directory stacks
# I use pushd and popd to maintain a directory stack and so I like being able to navigate
# around the stack with the cursor keys. Here's how:
# 1) pushd <new dir>
# 2) use CTRL+UP, CTRL+LEFT or CTRL+RIGHT as follows:
# bind ctrl + cursor keys:
# left = prev; right = next; up = list
bind '"\e[1;5A":"dirs\C-m"'
bind '"\e[1;5D":"pushd -0 2>/dev/null\C-m"'
bind '"\e[1;5C":"pushd +1 2>/dev/null\C-m"'
@coldnebo
coldnebo / Gemfile
Created March 27, 2012 18:20
how to get ruby 1.9.3-p125 and ruby-debug working on ubuntu 11.10
source 'http://rubygems.org'
# your gems here.
group :development do
# from http://beginrescueend.com/support/troubleshooting/
# requires running:
# $ rvm reinstall 1.9.3 --patch debug --force-autoconf
#
# my platform section below may be debatable (lots of ways to skin the cat) but the crucial part