Skip to content

Instantly share code, notes, and snippets.

View rab's full-sized avatar
👨‍💻
Home Office is a mess (as usual)

Rob Biedenharn rab

👨‍💻
Home Office is a mess (as usual)
View GitHub Profile
@rab
rab / poi.rb
Created January 25, 2009 20:20
POI helpers for your GPSr
#!/usr/bin/env ruby -w
#
# Copyright (c) 2008 Rob Biedenharn
# Rob [at] AgileConsultingLLC.com
# Rob_Biedenharn [at] alum.mit.edu
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
@rab
rab / image_size.rb
Created April 3, 2009 12:46
ImageSize finds the width x height
# image_size.rb
#
# Copyright (c) 2007 Rob Biedenharn
# Rob [at] AgileConsultingLLC.com
# Rob_Biedenharn [at] alum.mit.edu
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
@rab
rab / quiz.rb
Created May 20, 2009 00:15 — forked from ryanb/quiz.rb
added test for puts/gets swap
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. The tests should fail if any part of the application breaks.
# For example: If "gets" is moved before "puts" then the tests should
# fail since that breaks the application.
#
# 2. You cannot change the Quiz class. But you can use whatever framework
# and tools you want for the tests. (RSpec, Cucumber, etc.)
@rab
rab / rails aliases.bash
Created June 16, 2009 23:03
Bash functions to start mongrel_rails and webrick applications
cons () { if [ -e Gemfile ]; then
be='bundle exec'
else
be=""
fi
if [ -x "script/console" ]; then
${be} ruby script/console ${1:-${RAILS_ENV:-development}}
else
${be} rails console ${1:-${RAILS_ENV:-development}}
fi
@rab
rab / distinct_sets.rb
Created November 22, 2009 06:00
Ruby Quiz #225 Distinct Sets (with Tests)
require 'set'
def distinct_sets(setlist)
Set.new( setlist.map{|s|Set.new(s)} ).
divide {|a,b| ! (a&b).empty? }.to_a.
map{|e|e.to_a.inject{|b,l|b|l}.to_a.sort{|a,b| if Numeric === a && Numeric === b
a <=> b
else
a.to_s <=> b.to_s
end }}
def mask(x)y=x.dup;y[6...-4]=y[6...-4].gsub(/./,'*');y end
first_name last_name employer
Fred Flintstone Bedrock Quarry
Clark Kent The Daily Planet
Ralph Kramden Metro Bus
Joe Friday LAPD
David Hansson 37Signals
Jim Weirich EdgeCase
@rab
rab / README.md
Created August 18, 2010 20:48
Simulating Vehicle traffic for Bruce Wayner <winshocker@gmail.com>

run with:

ruby simulating_vehicles.rb

or to see each vehicle:

ruby -v simulating_vehicles.rb

You'll have to tally the results yourself across many runs, but this is way more than you deserve. (And you really need to understand it before you turn it in.)

class Person
include ActiveModel::MassAssignmentSecurity
attr_accessor :name, :birthday, :handsomeness
attr_protected :handsomeness
def initialize(params = {})
self.attributes = params
end
@rab
rab / .git-completion.sh
Created January 12, 2011 15:31
Colorful bash prompt with rvm and git goodness
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names