Skip to content

Instantly share code, notes, and snippets.

# Example of using Gchart (gchart.rubyforge.org) to graph
# some basic carpooling data (www.petrock.org/carpool)
Gchart.line(:size => "800x300", :title => "Carpool Data",
:legend => @participants.collect {|person| person.name},
:line_colors => @participants.collect {|person| person.color}.join(','),
:format => 'image_tag',
:data => @participants.collect {|person| @history[person.name] })
@fixlr
fixlr / test_helper.rb
Created January 14, 2009 13:59
Not mine. I just wanted to have it readily available.
# Prettier test declarations via:
# test "something being tested" do
# test code goes here...
# end
class Test::Unit::TestCase
def self.test(name, &block)
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
defined = instance_method(test_name) rescue false
raise "#{test_name} is already defined in #{self}" if defined
if block_given?
@fixlr
fixlr / gist:54569
Created January 29, 2009 15:02
DSpace: Determine Size of a bottom-level Sub-community
SELECT size_bytes
FROM bitstream , item2bundle, bundle2bitstream
WHERE item2bundle.bundle_id = bundle2bitstream.bundle_id
AND bundle2bitstream.bitstream_id = bitstream.bitstream_id
AND item2bundle.item_id = ANY(
SELECT item_id
FROM item
WHERE owning_collection = ANY(
SELECT collection_id
FROM community2collection
require 'benchmark'
n = 100000
Benchmark.bm do |x|
x.report('copy') { n.times do ; h = {}; h = h.merge({1 => 2}); end }
x.report('no copy') { n.times do ; h = {}; h.merge!({1 => 2}); end }
end
# user system total real
# copy 0.460000 0.180000 0.640000 ( 0.640692)
@fixlr
fixlr / dspace-IPAuthentication.java.diff
Created April 14, 2009 19:41
Simple modification to DSpace to allow IP-based authorization while Tomcat is behind a proxy
184c184
< String addr = request.getRemoteAddr();
---
> String addr = request.getHeader("x-real-ip");
> if (addr == null) {
> addr = request.getRemoteAddr();
> }
@fixlr
fixlr / gist:107649
Created May 6, 2009 18:20
Clear login inputs on focus and restore their default values on blur.
function formInputs() {
return document.getElementById('loginform').getElementsByTagName('input');
}
function formClear() {
var inputs = formInputs();
for (i = 0; i<inputs.length; i++) {
if (inputs[i].type != 'submit' && inputs[i].value == inputs[i].defaultValue) {
inputs[i].value = '';
}
#!/usr/local/env ruby
#
# Watch a set of files and open them in Safari and/or Firefox if they change.
# The files should probably be plain HTML files, but I'm not the boss of you.
# Refreshes index.htm or index.html by default (if they exist)
require 'optparse'
require 'ostruct'
options = OpenStruct.new
#!/usr/bin/env ruby
#
# This stupid Braid game completely locks up OSX when the
# campaign file gets corrupted. Rather than restarting over
# and over again while I try to restore from a previous save
# point, I decided to whip up this kill script.
while true do
braid_id = %x[ps auxx | grep "Braid.app" | grep -v auxx | grep -v grep | awk '{print $2}']
if braid_id.empty?
function remove_a(title) {
var all = document.getElementsByTagName('a');
for (i = 0; i < all.length; i++) {
element = all[i];
if (element.title.match(title)) {
element.parentNode.removeChild(element);
}
}
}
@fixlr
fixlr / parss.rb
Created September 18, 2009 19:41
Build a custom RSS feed for Penny Arcade comics and news posts
#!/usr/bin/env ruby
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'rss/maker'
class PA
attr_accessor :date