Skip to content

Instantly share code, notes, and snippets.

View rubiety's full-sized avatar

Ben Hughes rubiety

View GitHub Profile
@rubiety
rubiety / october_trip.txt
Created June 21, 2014 06:34
October Trip
Routing:
http://www.gcmap.com/mapui?P=YVR-MUC-FRA-BKK-HKG,HKG-BKK-SYD-AKL,AKL-PVG-NRT-SIN-BKK-NRT-ICN-JFK-LAX
Lufthansa First Class, Vancouver to Munich: $10,541
Thai Airways A380 First Class, Frankfurt to Bangkok: $9,610
Thai Airways 747 First Class, Bangkok to Hong Kong: $776
Thai Airways 747 (A380?) First Class, Bangkok to Sydney: $2,989
Air New Zealand Dreamliner Business Class, Auckland to Shanghai: $2,500
ANA Business Class, Shanghai to Tokyo: $1,158
ANA Dreamliner Business Class, Tokyo to Singapore: $3,253
@rubiety
rubiety / hidden_fields_from_params.rb
Created January 23, 2015 19:23
Dumping hidden fields from nested params hash
def hidden_fields_from_params(hash, prefix = "")
hash.map do |hash_key, hash_value|
if hash_value.is_a?(Hash)
hidden_fields_from_params(hash_value, "#{prefix}[#{hash_key}]")
else
hidden_field_tag("#{prefix}[#{hash_key}]", hash_value)
end
end.join("\n").html_safe
end

Keybase proof

I hereby claim:

  • I am rubiety on github.
  • I am rubiety (https://keybase.io/rubiety) on keybase.
  • I have a public key whose fingerprint is C2B6 4E10 316C 96DA 6218 C7BF 31B1 B5C8 1528 8AF1

To claim this, I am signing this object:

@rubiety
rubiety / gist:821c6f1818752ad63218
Last active August 29, 2015 14:23
Mile Optimization Example
» AwardChartEntry.first_class.between(Airport["SAN"], Airport["ICN"]).order("amount asc").map(&:name)
=> [
[0] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Saver Award in First: 80000 miles one way on own metal",
[1] "Aeroplan Canada & Continental USA to Asia 1 ClassicFlight Award in First: 105000 miles one way",
[2] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Saver Award in First: 120000 miles one way on partner metal",
[3] "Skypass North America to Korea Off Peak Award in First: 160000 miles round trip",
[4] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Standard Award in First: 190000 miles one way on own metal",
[5] "MileagePlus Mainland U.S., Alaska & Canada to North Asia Standard Award in First: 190000 miles one way on partner metal",
[6] "Aeroplan Canada & Continental USA to Asia 1 ClassicFlight Award in First: 210000 miles round trip",
[7] "Skypass North America to Korea Peak Award in First: 240000 miles round trip"
@rubiety
rubiety / gist:5426
Created August 14, 2008 13:27 — forked from qrush/gist:5425
#############################################################
# Application
#############################################################
set :application, "" #your app's name here
set :server_ip, "" #your server's ip here
set :deploy_to, "/home/rails/#{application}" #the path to your rails app here
#############################################################
# Servers
named_scope :with_keywords, lambda {|q|
fields = %w(title information items.sku)
tokens = q.split.collect {|c| "%#{c.downcase}%"}
clause = (["(" + fields.map {|f| "#{f} LIKE ?" }.join(" OR ") + ")"] * tokens.size).join(" AND ")
{ :include => [:items], :conditions => [clause, *(tokens * fields.size).sort] }
}
@rubiety
rubiety / gist:29404
Created November 26, 2008 14:35 — forked from qrush/gist:29315
# If you ever needed an array of all ActiveRecord models in your Rails app (+ Session):
Dir["app/models/**/*.rb"].each {|r| require r}
subclasses_of(ActiveRecord::Base).map(&:class_name)
# Or *all* models:
ActiveRecord::Base.connection # Preloads driver constants
constants_before = Object.constants
Dir["app/models/**/*.rb"].each {|r| require r}
Object.constants - constants_before
class ActivityEntry < ActiveRecord::Base
belongs_to :target, :polymorphic => true
belongs_to :user
# Target Scopes
named_scope :for, lambda {|obj| {:conditions => {:target_id => obj.id, :target_type => obj.class.name}} }
named_scope :for_listings, {:conditions => {:target_type => 'Listing'} }
named_scope :manageable_by, lambda {|user|
case
when user.can_manage_company? then {}
indigosun:vim-fu bhughes$ rake preinstall
(in /Users/bhughes/Workspace/Source/vim-fu)
Usage: /usr/local/git/bin/git-submodule [--quiet] [--cached] [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] [--] [<path>...]
# Bad:
1.upto(10) do |i|
puts "X" * i
end
# Good:
((nil.object_id - 3)..(2**3 + 2)).map do |i|
lambda { "X" * i }
end.collect {|i| i.send(:call)}.tap do |a|
puts a.class.instance_method(:join).send(:bind, a).call("\n")