Skip to content

Instantly share code, notes, and snippets.

View williamn's full-sized avatar

William williamn

  • Jakarta, Indonesia
View GitHub Profile
@williamn
williamn / to_kmlcolor.rb
Created June 21, 2011 08:30
Converting HEX color (RRGGBB) to KML color (AABBGGRR)
# Taken from http://rcos.cs.rpi.edu/projects/flagship-safety/commit/converting-hex-color-rrggbb-to-kml-color-aabbggrr/
#
# Generates a KML color given a hex color string.
# Converts the format from #RRGGBB to AABBGGRR.
# The alpha channel defaults to ff.
def to_kmlcolor(color="#000000", alpha = "ff")
alpha + color[5,3] + color[3,2] + color[1,2]
end
@williamn
williamn / enviroment.rb
Created June 16, 2011 05:02
Fixing "undefined local variable or method `version_requirements' for #<Rails::GemDependency:0x...> (NameError)"
# Phillip Koebbe from Ruby on Rails suggested inserting following code between the "bootstrap" and
# "initialize" sections of enviroment.rb. This hack fixes the problem.
if Gem::VERSION >= "1.3.6"
module Rails
class GemDependency
def requirement
r = super
(r == Gem::Requirement.default) ? nil : r
end
@williamn
williamn / dchmod.sh
Created January 12, 2011 08:00
Change permissions only for directories
# Original URL => http://www.tiplib.com/150/change-permissions-only-directories
find . -type d -exec chmod a+x {} \;
source :gemcutter
gem "rails", "~> 2.3.5"
gem "sqlite3-ruby", :require => "sqlite3"
# bundler requires these gems in all environments
# gem "nokogiri", "1.4.2"
# gem "geokit"
group :development do
# bundler requires these gems in development
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
"Run `gem install bundler` to upgrade."
class Rails::Boot
def run
load_initializer
Rails::Initializer.class_eval do
def load_gems
@bundler_loaded ||= Bundler.require :default, Rails.env
end
end
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
begin
require 'cucumber/rake/task'
namespace :hudson do
def report_path
"hudson/report/features"
@williamn
williamn / example.feature
Created November 12, 2010 08:20
Feature/story example
Story: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed
Scenario 1: Account has sufficient funds
Given the account balance is \$100
And the card is valid
And the machine contains enough money
@williamn
williamn / .bash_logout
Created November 8, 2010 02:22
Clear bash history when logout
clear
history -c && rm -f ~/.bash_history
require 'rcov/rcovtask'
namespace :test do
namespace :coverage do
desc "Delete aggregate coverage data."
task(:clean) { rm_f "coverage.data" }
end
desc 'Aggregate code coverage for unit, functional and integration tests'
task :coverage => "test:coverage:clean"
%w[unit functional integration].each do |target|