This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "httpclient" | |
# Usage: | |
# reevoo_hq = LongLat.from_postcode("SE1 0RF") | |
# reevoo_hq.long # => -0.10276 | |
# reevoo_hq.lat # => 51.500991 | |
class LongLat | |
PostcodeLookupError = Class.new(RuntimeError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseColor | |
attr_reader :r,:g,:b,:a | |
def alpha(v) | |
BaseColor.new(r,g,b,v) | |
end | |
def initialize(r, g, b, a = 1.0) | |
@r, @g, @b, @a = normalize(r), normalize(g), normalize(b), normalize(a, 1.0) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example Rails Usage: | |
# config.middleware.use Rack::LessCss, "/stylesheets", File.join(RAILS_ROOT, "public", "stylesheets") | |
# | |
# public/stylesheets/foo.less is now used to render /stylesheets/foo.css | |
# | |
require 'less' | |
module Rack | |
class LessCss | |
File = ::File | |
def initialize(app, css_path, css_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No Boom, it was creating the handle first... cause app Boom | |
# This does however, as you say, "Boom" | |
Factory.define :product do |p| | |
p.product_handles do |p| | |
[Factory.build(:product_handle)] | |
end | |
end | |
# Only issue here is that the product has knowledge of the handle... knowledge it need not have. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example Usage: | |
# | |
# FactoryWithCallbacks.define :product do |p| | |
# p.on_create do |prod| | |
# Factory(:product_alias, :product => prod) | |
# end | |
# end | |
class FactoryWithCallbacks < Factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Tom's Magical "Don't Mate Your Root" Script | |
# Prevents "mate /" from crashing your Mac. | |
function mateforce(){ | |
`which mate` $* | |
} | |
function line_count_less_than(){ | |
ruby -e " | |
max_count = ARGV.first.to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# # Fish has a has_been_caught_by_someone_called(...) scope that is too complex (several joins, and group bys) | |
# Fish.count # => 999,999,999 | |
# my_fish = Fish.has_been_caught_by_someone_called("bubba") | |
# | |
# my_fish.count # => 999,999 | |
# my_fish.update_all(:color => "green") # Too complex, too many joins, group by etc... mysql will not play ball. | |
# my_fish.all... # => OUT OF MEMORY!!!!!! | |
# my_fish.each_in_batches{|f| f.update_attribute(:color => "green") } # => Takes more than a decade. | |
# my_fish.complex_update_all(:color => "green") # => 999,999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
gem "twitter4r" | |
require "twitter" | |
require "active_support" | |
Twitter::Client.configure do |conf| | |
conf.application_name = "Twitter Echo" | |
end | |
username, password = ARGV.shift, ARGV.shift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The data setup inside the block may take upto a second to be ready to pass the test. But probably much less. | |
def retrying_for(secconds = 1) | |
limit = Time.now + secconds | |
begin | |
yield | |
rescue | |
if Time.now < limit | |
sleep 0.05 | |
retry | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mateforce(){ | |
`which mate` $* | |
} | |
function mate(){ | |
if find $* -type f | ~/line_count_less_than 1000 | |
then | |
mateforce $* | |
else | |
echo "Too many files!" |