Skip to content

Instantly share code, notes, and snippets.

View hoverlover's full-sized avatar

Chad Boyd hoverlover

View GitHub Profile
@hoverlover
hoverlover / pg_locking.rb
Last active November 26, 2019 08:57
PG::LockNotAvailable rescue woes
def save_with_lock
r = Record.first
# This will raise PG::LockNotAvailable if already locked
#
r.with_lock("FOR UPDATE NOWAIT") do
# do stuff
end
# This rescue block isn't executed for some reason??
@hoverlover
hoverlover / add_fieldset.js
Created August 31, 2012 14:00
Dynamically add fieldset to sencha FormPanel
App.views.creditCardForm.items.items[0].up('form').insert(1, {
xtype: 'fieldset',
id: 'customerInfoFormFieldset',
title: 'Name and Address Details',
instructions: 'Please enter your name and address.',
defaults: {
xtype: 'textfield',
labelAlign: 'left',
labelWidth: '40%',
required: false,
@hoverlover
hoverlover / faking_it_with_savon.rb
Created April 20, 2012 20:09
Faking it with Savon. Returns a fake response instead of hitting the soap service.
require 'spec_helper'
describe "Faking it with Savon" do
before do
Savon.hooks.define "Fake Response", :soap_request do
HTTPI::Response.new(200, {}, "<Envelope><Body><response>Success!</response></Body></Envelope>")
end
after do
Savon.hooks.reject! "Fake Response"
@hoverlover
hoverlover / savon_client.rb
Created March 19, 2012 14:45
Using my forks of Akami and Savon to sign a request with a X.509 certificate. See https://github.com/genuitytech/akami and https://github.com/genuitytech/savon.
client = Savon::Client.new do
# This can be a URL also
wsdl.document = "/Path/to/your.wsdl"
# These are optional, only if your WSDL sucks :)
wsdl.endpoint = "https://your_endpoint"
wsdl.namespace = "http://your_namespace"
certs = Akami::WSSE::Certs.new :cert_file => "/path/to/cert.crt", :private_key_file => "/path/to/private/key.pem", :private_key_password => "password"
wsse.sign_with = Akami::WSSE::Signature.new certs
@hoverlover
hoverlover / auto_save_and_open_page.rb
Created February 16, 2012 21:18
Auto save_and_open_page on failure for Capybara
module Capybara
def Capybara.auto_save_and_open_page=(val)
@auto_save_and_open_page = !!val
end
def Capybara.auto_save_and_open_page?
@auto_save_and_open_page ||= false
end
end
@hoverlover
hoverlover / install-ruby-debug-ruby-1.9.3.sh
Created November 23, 2011 18:24 — forked from boriscy/install-ruby-debug-ubuntu-ruby-1.9.3
ruby-debug in ruby-1.9.3 and rbenv
# These instructions are for Ruby 1.9.3 under rbenv.
# To install ruby-debug19 for ruby-1.9.3 you need to download the following gems from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
@hoverlover
hoverlover / routes.rb
Created October 25, 2011 04:47
Map a scoped resource to a controller with an unrelated namespace
Sample::Application.routes.draw do
# Route /a/b -> Foo::BarsController. This is useful
# when you need to conform to a certain url structure
# while using a controller that doesn't match that structure,
# eg. a controller supplied by a Rails engine.
scope '/a' do
resources :b, controller: 'bars', module: 'foo'
end
end
@hoverlover
hoverlover / active_admin_heroku.rb
Created June 7, 2011 16:35
Rails initializer for using ActiveAdmin with Sass on Heroku
if Rails.env.production?
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets", "admin"))
template_path_one = "#{Gem.loaded_specs['activeadmin'].full_gem_path}/app/assets/stylesheets"
template_path_two = "#{Gem.loaded_specs['activeadmin'].full_gem_path}/lib/active_admin/sass"
old_compile_path = "#{Rails.root}/public/stylesheets/admin"
new_compile_path = "#{Rails.root}/tmp/stylesheets/admin"
Sass::Plugin::remove_template_location template_path_one
@hoverlover
hoverlover / spec_helper.rb
Created March 4, 2011 21:19
Place this somewhere that gets loaded when RSpec starts and your browser will automatically show the contents of the webpage when an acceptance spec fails.
# Somewhere in the file
Capybara.auto_save_and_open_page = true if 'true' == ENV['CAPYBARA_AUTO_SAVE_AND_OPEN_PAGE']
module Travis
class Builder
@@ -29,9 +30,18 @@ module Travis
host = rails_config['url'] || 'http://127.0.0.1'
url = "#{host}/builds/#{build['id']}#{'/log' if data.delete(:append)}"
uri = URI.parse(host)
- data = { :body => { :_method => :put, :build => data }, :head => { :authorization => [uri.user, uri.password] } }
- # stdout.puts "-- post to #{url} : #{data.inspect}"
- register_connection EventMachine::HttpRequest.new(url).post(data)
+ data = {