Skip to content

Instantly share code, notes, and snippets.

View xn's full-sized avatar

Christian Trosclair xn

View GitHub Profile
@xn
xn / concise_transfers_controller.rb
Created January 3, 2013 08:26
The book `Clean Ruby` talks about locus of attention then offers this controller at the end of Chapter 1. To me, my eyes just roll off the create method. There is simply too much going on there to get everything in one gestalt. Here's my refactor:
class ConciseTransfersController < ApplicationController
respond_to :html
def create
respond_with account do |format|
format.html { redirect_to account_transfers_path(account) }
end
end
protected
@xn
xn / 0-readme.md
Created February 21, 2012 11:24 — forked from mickm/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p125 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p125 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@xn
xn / pathy.rb
Created December 28, 2011 23:55 — forked from krainboltgreene/pathy.rb
class Hash
#this is pseudocode
def locate_and_find_all(nodes*, &block)
enum = self
while !nodes.empty?
node = nodes.pop
if enum.has_key? node
enum = enum[node]
else
development:
adapter: postgresql
encoding: unicode
database: igb_development
pool: 5
username: some_user_name
password: some_password
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
@xn
xn / gist:1153733
Created August 18, 2011 09:25
active_admin error
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.1.1/lib/new_relic/rack/browser_monitoring.rb:42:in `autoinstrument_source'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.1.1/lib/new_relic/rack/browser_monitoring.rb:21:in `call'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/bundler/gems/barista-0d85a193da9c/lib/barista/server.rb:33:in `call'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/warden-1.0.5/lib/warden/manager.rb:35:in `block in call'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/warden-1.0.5/lib/warden/manager.rb:34:in `catch'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/warden-1.0.5/lib/warden/manager.rb:34:in `call'
2011-08-18T09:02:49+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/bundler/gems/rails-4b411c80cc96/actionpack/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
2011-08-18
- if hidden
%section#account_settings_profile.hidden
%h1
%span Profile
= form_for @user, :url => registration_path(@user) do |form|
%p
= form.label :first_name, 'First:'
= form.text_field :first_name
@xn
xn / gist:1061991
Created July 3, 2011 06:05
Speeding up the asset pipeline
gem 'rails', '3.1.0.rc4', :git => "git://github.com/rails/rails", :branch => "3-1-stable"
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
# Asset template engines
gem 'sass', :git => "git://github.com/nex3/sass.git"
gem 'sprockets', :git => "git://github.com/xn/sprockets.git"
@xn
xn / billable.rb
Created May 24, 2011 19:28
braintree setup
def add_credit_card_data(url)
begin
Braintree::TransparentRedirect.create_credit_card_data({
:redirect_url => url + "/user/result",:credit_card => {
:customer_id => customer_id}})
rescue Exception => exc
warn exc.message
return exc
end
end
#!/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 = SOAP::WSDLDriverFactory.new('http://localhost:8080/rpc/soap/jirasoapservice-v2?wsdl').create_rpc_driver
# Login.
token = soap.login('admin', 'admin')
@xn
xn / gist:955633
Created May 4, 2011 17:39
ticketmaster-lighthouse
>> tm = TicketMaster.new(:lighthouse, {: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)
=> "http://garbhoch.lighthouseapp.com:"
>> 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"