Skip to content

Instantly share code, notes, and snippets.

View jamiecobbett's full-sized avatar

Jamie Cobbett jamiecobbett

View GitHub Profile
@jamiecobbett
jamiecobbett / Google.feature
Created June 18, 2009 23:00
Use Cucumber and Culerity to run Celerity (a headless browser with JS support)
Feature: Google
In order to test a remote site
I surf to google
And take a look
Scenario: Trying Google
When I go to the homepage
And I fill in "Aslak Hellesoy" for the field named "q"
And I press "Google Search"
Then I should see "So little to do - so much time"
require 'webrat'
require 'webrat/mechanize'
include Webrat::Methods
include Webrat::Matchers
Webrat.configure do |config|
config.mode = :mechanize
end
@jamiecobbett
jamiecobbett / app_ctl
Created September 30, 2009 13:46
Shell script to daemonise a ruby process
#!/bin/sh
#
# Script: app_ctl
# Description: Starts and stops a Ruby script
#
die()
{
echo "$*"
exit 1
@jamiecobbett
jamiecobbett / Rakefile
Created November 30, 2009 11:42
Run a rake task for each rakefile in directories under the current one
# Adapted from http://stackoverflow.com/questions/1686779/multifile-rake-build
# Runs a task (in this case the default task) for each Rakefile nested in the current directory
task :default do
FileList["*/**/Rakefile"].each do |project|
next if project =~ /^admin_console/
next if project =~ /^logging/
# clear current tasks
Rake::Task.clear
#load tasks from this project
load project
@jamiecobbett
jamiecobbett / ruby_file_run_directly.rb
Created December 1, 2009 19:45
Ruby - is the file being run directly
# http://stackoverflow.com/questions/582686/should-i-define-a-main-method-in-my-ruby-scripts/582694#582694
# Detect if the file is being run directly.
#if __FILE__ == $PROGRAM_NAME
if __FILE__ == $0
x = SweetClass.new(ARGV)
x.run # or go, or whatever
end
@jamiecobbett
jamiecobbett / gist:301673
Created February 11, 2010 16:32 — forked from uniglam/gist:268497
Bundler/capistrano task
after "deploy:update_code", "bundler:bundle"
namespace :bundler do
task :bundle do
run "mkdir -p #{%w(cache doc gems specifications).map { |x| "#{shared_path}/bundler_gems/#{x}" }.join(' ')} #{release_path}/vendor/bundler_gems; rm -R #{release_path}/vendor/bundler_gems/*; ln -s #{shared_path}/bundler_gems/* #{release_path}/vendor/bundler_gems/; cd #{release_path}; gem bundle"
end
end
@jamiecobbett
jamiecobbett / Gemfile
Created February 15, 2010 08:26 — forked from indirect/Gemfile
Rails 2.3.5 and bundler 0.9.3
# include at least one source and the rails gem
source :gemcutter
gem 'rails', '~> 2.3.5', :require => nil
group :development do
# bundler requires these gems in development
gem 'rails-footnotes'
end
group :test do
before "deploy:rollback:revision", "deploy:rollback_database"
desc "Rolls back database to migration level of the previously deployed release"
task :rollback_database, :roles => :db, :only => { :primary => true } do
if releases.length < 2
abort "could not rollback the code because there is no prior release"
else
rake = fetch(:rake, "rake")
rails_env = fetch(:rails_env, "production")
migrate_env = fetch(:migrate_env, "")
@jamiecobbett
jamiecobbett / cap_db_password.rb
Created February 19, 2010 15:00
cap task to hide production db password
# http://github.com/thoughtbot/suspenders/blob/4d9c29a1dfe14a591ac461d5ea8e660f1a642d5b/config/deploy.rb#L40
namespace :db do
desc "Create database password in shared path"
task :password do
set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") }
run "mkdir -p #{shared_path}/config"
put db_password, "#{shared_path}/config/dbpassword"
end
end
@jamiecobbett
jamiecobbett / running_as_a_rake_task.rb
Created February 19, 2010 15:47
Is the command being used to run this code rake with a specific task?
if ( File.basename($0) == "rake" && ARGV.include?("gems:install") )
# do stuff
end