Skip to content

Instantly share code, notes, and snippets.

View kmayer's full-sized avatar

Ken Mayer kmayer

View GitHub Profile
@kmayer
kmayer / maybe_migrate.rb
Created April 22, 2009 01:21
An example of how to handle migrations that *might* fail because they've already happened.
# An example of how to handle migrations that *might* fail because they've already happened.
class FixUpMigrations < ActiveRecord::Migration
def self.up
say_with_time %{
If you are transitioning from 0.6.9 to 0.7.1, these migrations
were lost. We're not worried if the columns already exist.
} do
maybe_add_column 'duplicate column name',
:pages, :is_preview, :boolean, :default => false
maybe_add_column 'duplicate column name',
@kmayer
kmayer / Extending Highrise gem
Created April 30, 2009 19:08
Sample how to extend Highrise::Person
Highrise::Person.class_eval do
class << self
def lookup(id, list, item, location)
module_eval <<-EOT
def #{id}
contact_data.#{list}.each do |i|
return i.#{item}.strip if i.location == "#{location}"
end
''
end
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@freesailquotes.unfuddle.com:freesailquotes/site.git master"
* executing "if [ -d /var/www/freesailquotes.com/shared/cached-copy ]; then cd /var/www/freesailquotes.com/shared/cached-copy && git fetch origin && git reset --hard a25dc8d1b4ededb3cbfb14d41ff61dbb5660b7c4 && git submodule init && git submodule update; else git clone --depth 1 git@freesailquotes.unfuddle.com:freesailquotes/site.git /var/www/freesailquotes.com/shared/cached-copy && cd /var/www/freesailquotes.com/shared/cached-copy && git checkout -b deploy a25dc8d1b4ededb3cbfb14d41ff61dbb5660b7c4 && git submodule init && git submodule update; fi"
servers: ["li82-69.members.linode.com"]
D, [2009-06-20T19:49:15.628964 #47194] DEBUG -- net.ssh.transport.session[d2f91a]: establishing connection to li82-69.members.linode.com:22
D, [2009-06-20T1
while true do
RefineryQueue.stats_update
sleep 60
end
/var/log/nginx/*.log { daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
@kmayer
kmayer / gist:326016
Created March 9, 2010 00:58
/etc/proxy.pac
// Matches all hosts that start with "local."
// The funky regex matches the port number (if include in the URL)
function FindProxyForURL(url, host) {
if (shExpMatch(host,"local.*")) {
port = url.match( /\w+:\/\/[^:]+(:\d+)\// );
if (port) {
return "PROXY localhost" + port[1];
} else {
return "PROXY localhost";
}
@kmayer
kmayer / RSpec support for holygrail
Created April 1, 2010 23:07
rspec support for holygrail
# spec/support/holygrail.rb
require 'holygrail'
class Spec::Rails::Example::ControllerExampleGroup
include ::HolyGrail::Extensions
end
class Spec::Rails::Example::FunctionalExampleGroup
include ::HolyGrail::Extensions
end
@kmayer
kmayer / gist:447836
Created June 22, 2010 02:25 — forked from aeden/gist:447835
cucumber.example.yml
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "#{rerun_opts} --format rerun --out rerun.txt --strict --tags ~@wip --tags ~@pending --color --require features/"
all_opts = "--format progress --strict --tags ~@wip --tags ~@pending --color"
%>
autotest: --format pretty --tags @wip --wip --tags ~@spreedly features
autotest-all: --format progress --tags ~@pending --tags ~@spreedly features
default: <%= std_opts %>
all: <%= all_opts %>
@kmayer
kmayer / mocha integration with cucumber
Created June 28, 2010 22:17
mocha integration with cucumber
# For mocha integration, add this file into features/support folder
require "mocha"
World(Mocha::API)
Before do
mocha_setup
end
@kmayer
kmayer / brand_sweeper.rb
Created March 31, 2012 18:53
TDD Action Caching in Rails 3
class BrandSweeper < ActionController::Caching::Sweeper
observe Brand # Observers will introspect on the class, but Sweepers don't
def after_update(brand)
expire_action :controller => "brand", :action => :preview, :brand_id => brand.to_param
end
...