Skip to content

Instantly share code, notes, and snippets.

View mattsoutherden's full-sized avatar

Matt Southerden mattsoutherden

View GitHub Profile
def foo([head | *something*]) when head * 2 < *last* do
some return value
end
# /home/bob/env
# USER=bob
# PASS=secret
docker run --env-file /home/bob/env -p 80:80 some/image
# Which is equivalent to:
docker run -e USER=bob -e PASS=secret /path/to/file -p 80:80 some/image
@mattsoutherden
mattsoutherden / gist:2701324
Created May 15, 2012 12:18
Wait for delayed job to stop
# Run DelayedJob
namespace :delayed_job do
def wait_for_process_to_end(process_name)
run "COUNT=1; until [ $COUNT -eq 0 ]; do COUNT=`ps -ef | grep -v 'ps -ef' | grep -v 'grep' | grep -i '#{process_name}'|wc -l` ; echo 'waiting for #{process_name} to end' ; sleep 2 ; done"
end
desc "Restart the delayed_job process"
task :restart, :roles => :app do
stop
wait_for_process_to_end('delayed_job')
@mattsoutherden
mattsoutherden / hello.rb
Created February 3, 2012 15:55 — forked from urfolomeus/hello.rb
Class level privates
class Hello
def self.first
puts "Boo!"
end
private
def self.second
puts "Buh!"
end
@mattsoutherden
mattsoutherden / gist:1664389
Created January 23, 2012 17:29
Mountable App Partial
In a mounted engine with
isolate_namespace Foo
A Foo::BarController#index action looks for it's template in app/views/foo/bar/index.html.erb
However if I'm in that index template and do
render :partial => 'bar/baz'
@mattsoutherden
mattsoutherden / routes.rb
Created December 14, 2011 12:37
Rails 3 Routing
# Rails 2 routing
#
map.resource :city, :as => ":city" do |city|
city.login 'login', :controller => 'cities', :action => 'login'
city.resources :orders, :only => [ :show, :update ]
end
# city_login /:city/login {:controller=>"cities", :action=>"login"}
#
# city_order GET /:city/orders/:id(.:format) {:controller=>"orders", :action=>"show"}
@mattsoutherden
mattsoutherden / gist:1200438
Created September 7, 2011 12:29
Strange Ruby Behaviour
>> d.wordpress_deal.merchant_value
=> 37.05
>> d.wordpress_deal.merchant_value * 100
=> 3705.0
>> (d.wordpress_deal.merchant_value * 100).to_i
=> 3704
>>
<p>
<span class="black-txt"><b>Programme Benefits</b></span><br />
<span class="black-txt">• High conversion rate and average spend (£77) per customer</span><br />
<span class="black-txt">• Fantastic widget feeds and creatives to display on your website</span><br />
<span class="black-txt">• Comprehensive Affiliate management from 7thingsmedia</span><br />
</p>
<p>
<span class="black-txt">• £2.50 fixed fee commission for first customer sales</span><br />
<span class="black-txt">• 10% commission of sale value on first customer sales</span><br />
class InviteController < ApplicationController
helper :google_optimizer, :content, :competitions, :deals
include ContentHelper
skip_before_filter :invitation_or_login_required, :only => [ :index, :invite_deal, :invite_competition]
def index
#########################################
## Generic links
class FbappController < ApplicationController
helper :google_optimizer
skip_before_filter :invitation_or_login_required, :only => [:index]
layout 'fb_app'
def index
if @user
return redirect_to '/fb_error'
end