Skip to content

Instantly share code, notes, and snippets.


Christian Trosclair xn

View GitHub Profile
xn / gist:714891
Created Nov 25, 2010
home_run failing with subtraction using ActiveSupport and DateTime
View gist:714891
irb(main):001:0> require 'active_support/core_ext'
=> true
irb(main):002:0> x =
=> Mon, 01 Jan 2001
irb(main):003:0> x - 1.second
=> 2000-12-31 23:59:59 -0500
irb(main):004:0> y =
=> Mon, 01 Jan 2001 00:00:00 +0000
irb(main):005:0> y - 1.second
TypeError: expected numeric or date
View neat_hash_default.rb
p Hash[(instance_variables - [:@options]).map { |i| [i, instance_variable_get(i)] }]
xn / gist:853172
Created Mar 3, 2011
ideas for specing
View gist:853172
describe 'get /projects' do
context 'when user logged in' do
it "returns a list of projects scoped by user"
View gist:875262
# Add this to more_web_steps.rb
# Selenium docs: today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
window = page.driver.browser.window_handle
alert = page.driver.browser.switch_to.alert
alert.text.should == text
page.driver.browser.switch_to.window window
xn / preftools.rb_stacktrace
Created Apr 26, 2011
segfault in perftools.rb
View preftools.rb_stacktrace
In a sinatra app:
use ::Rack::PerftoolsProfiler, :default_printer => 'gif', :mode => 'objects'
Linux anjaneya 2.6.35-28-generic #50-Ubuntu SMP Fri Mar 18 18:42:20 UTC 2011 x86_64 GNU/Linux
#0 0x00007f30be71b2a3 in select () from /lib/
#1 0x00007f30bf2c954a in rb_thread_select (max=<value optimized out>, read=0x7fff9c5bd5a0, write=0x0, except=0x0, timeout=<value optimized out>) at eval.c:11462
#2 0x00007f30bf2e1f3c in rb_f_select (argc=<value optimized out>, argv=<value optimized out>, obj=<value optimized out>) at io.c:4946
#3 0x00007f30bf2c2d14 in rb_call0 (klass=<value optimized out>, recv=<value optimized out>, id=<value optimized out>, oid=<value optimized out>, argc=<value optimized out>, argv=<value optimized out>, body=0x7f30bf76bde8, flags=0) at eval.c:5928
#4 0x00007f30bf2c2f03 in rb_call (klass=139847347388680, recv=139847347388720, mid=3769, argc=4, argv=0x7fff9c5bd970, scope=0, self=139847234679040) at eval.c:6176
View gist:943214
{"series":[{"refresh_changes":true,"refresh_chart":true,"success":true},{"growl":"Started Tracking Enform. Updates should appear on your dashboard shortly."},{"closemodal":false},{"replaceFrom":{"action":"/projects/2bukd1sbny18j7485xi/trackers/2bxqzjtzjepicuudkp0/tracked_projects/add","selector":"#maintain-a-tracker"}}]}
View gist:943721
def create_tracked_project(*xpids)
(xpids.flatten.each(&:strip!)).collect do |xpid|
xproject = authorization.ticketmaster.projects.detect {|xp| == xpid}
new_tracked_project = TrackedProject.create_from(xproject)
tracked_projects << new_tracked_project
rescue => exc
warn exc
raise exc
xn / gist:955633
Created May 4, 2011
View gist:955633
>> tm =, {:token => "this is a public gist", :account => "garbhoch"})
=> #<TicketMaster:0x7ff5cf87fc68 @provider=TicketMaster::Provider::Lighthouse, @symbol=:lighthouse, @authentication=<#TicketMaster::Authenticator account="garbhoch" token="this is a public gist">>
>> Lighthouse::Project.find(:all)
=> nil
>> Lighthouse.update_site(Lighthouse::Project)
=> ""
>> Lighthouse::Project.find(:all)
=> [#<Lighthouse::Project:0x7ff5cf6bbb70 @prefix_options={}, @attributes={"name"=>"Test", "permalink"=>"test", "closed_states_list"=>"resolved,hold,invalid", "created_at"=>Tue Apr 05 21:17:35 UTC 2011, "description_html"=>"<div><p>Monkies!</p></div>", "public"=>false, "default_ticket_text"=>nil, "updated_at"=>Fri Apr 29 07:40:33 UTC 2011, "closed_states"=>"resolved/6A0 # You can customize colors\nhold/EB0 # with 3 or 6 character hex codes\ninvalid/A30 # 'A30' expands to 'AA3300'", "default_milestone_id"=>nil, "license"=>nil, "open_states_list"=>"new,open"
View gist:971216
#!/usr/bin/env ruby
require 'rubygems'
gem 'soap4r' # The soap4r gem is actually an updated version of the built-in SOAP driver, so we need to override it.
require 'soap/wsdlDriver'
soap ='http://localhost:8080/rpc/soap/jirasoapservice-v2?wsdl').create_rpc_driver
# Login.
token = soap.login('admin', 'admin')
xn / billable.rb
Created May 24, 2011
braintree setup
View billable.rb
def add_credit_card_data(url)
:redirect_url => url + "/user/result",:credit_card => {
:customer_id => customer_id}})
rescue Exception => exc
warn exc.message
return exc