Skip to content

Instantly share code, notes, and snippets.

View tommeier's full-sized avatar

Tom Meier tommeier

View GitHub Profile
@tommeier
tommeier / seqeul.rake
Created May 13, 2011 05:30
Close postgres open connections before running test suite
task 'db:test:prepare' => :close_postgres_connections
task :close_postgres_connections => :environment do
#Kill any other open connections on the test db
db_adapter = defined?(::ActiveRecord::Base) ? ActiveRecord::Base.connection : nil
db_adapter ||= defined?(::Sequel::Model) ? ::Sequel::Model.db : nil
if Rails.env.test? && db_adapter
db_config = Rails.configuration.database_configuration[Rails.env].symbolize_keys
begin
@tommeier
tommeier / save_screenshots_snippets.rb
Created May 18, 2011 02:06
Save screenshots when using Selenium, Capybara and Ubuntu server
#WIP
#spec/spec_helper.rb
RSpec.configure do |config|
#Only for selenium based tested filtered with :js => true on tests
#eg: describe "Some test", :js => true do
# end
config.around(:each, :js => true) do |example|
@tommeier
tommeier / launchy.rb
Created August 5, 2011 00:43
Load launchy with Google chrome
gem 'launchy'
ENV["LAUNCHY_BROWSER"] = `which google-chrome`.strip
save_and_open_page
@tommeier
tommeier / money_model.rb
Created November 25, 2011 02:23
Money model
class MoneyModel < ActiveRecord::Base
# ===============
# = Composition =
# ===============
composed_of :amount, :class_name => 'Money', :mapping => [[:amount_in_cents, :cents]]
composed_of :gst, :class_name => 'Money', :mapping => [[:gst_in_cents, :cents]]
composed_of :amount_including_gst, :class_name => 'Money', :mapping => [[:amount_including_gst_in_cents, :cents]]
end
@tommeier
tommeier / comma_example.rb
Created December 1, 2011 01:50
comma use example
class CommaModel < ActiveRecord::Base
# =======
# = CSV =
# =======
comma do
some_column
native_column
association :to_s => 'Custom Label'
column_with_lambda 'Custom Header' do |p| p && Money.new(p) end
association_2 { |s| "'#{s.to_s(:csv)}" }
@tommeier
tommeier / irc_hubot_password.sh
Created December 12, 2011 05:59
Hubot IRC variables with password protected rooms
HUBOT_IRC_PORT="6667" HUBOT_IRC_SERVER="irc.freenode.net" HUBOT_IRC_ROOMS="#room_name room_password" HUBOT_IRC_NICK="hubot" bin/hubot
@tommeier
tommeier / core_extensions.rb
Created December 15, 2011 00:38
Add methods for Hash to deep_stringify_keys or deep_symbolize_keys
#Load in rails via:
# config/initializers/core_extensions.rb
#Forcibly require our core extensions after rails has loaded
Dir.glob(Rails.root.join('lib', 'core_ext', '*.rb')).each { |extension| require extension }
@tommeier
tommeier / Rakefile
Created February 27, 2012 05:20
Add SimpleCov coverage groups based on rake spec tasks
Rake::Task.class_eval do
#Required to ensure SimpleCov doesn't overwrite coverage shared values
alias :execute_without_simplecov_command :execute
def execute_and_set_simplecov_command args=nil
ENV['COV_COMMAND'] = "rspec:#{name}" if ENV['COVERAGE']
execute_without_simplecov_command(args)
end
alias :execute :execute_and_set_simplecov_command
end
@tommeier
tommeier / resque.monitrc
Created February 28, 2012 02:10
Resque monit file
#!/bin/sh
#
# This script starts and stops the Resque daemon
# This script belongs in /engineyard/bin/resque
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
CURDIR=`pwd`
usage() {
@tommeier
tommeier / resque.rb
Created February 28, 2012 02:11
Resque recipe for Engineyard
#
# Cookbook Name:: resque
# Recipe:: default
#
# Install resque on app_master rather than utility server so outbound traffic is routed via the Elastic IP
#
app_name = node[:engineyard][:environment][:apps][0][:name]
if ['app_master', 'app', 'util', 'solo'].include?(node[:instance_role])