Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
@airblade
airblade / config.ru
Created December 15, 2011 09:08 — forked from mislav/config.ru
Shortest simplest sweetest web "hello {NAME}" in Ruby
run ->(e){ p=Hash[*e['QUERY_STRING'].split(/[&=]/)]; [200, {'Content-type'=>'text/html'}, ["Hello #{p['name']}!"]] }
@airblade
airblade / gist:1218752
Created September 15, 2011 07:37
Passenger 3.0.9: failure to compile Apache2 module
sudo passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v3.0.9.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
Here's what you can expect from the installation process:
1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
@airblade
airblade / new-git.sh
Created June 9, 2011 17:50 — forked from topfunky/new-git.sh
Create a new git repository on a remote server. Assumes that you're sitting in an initialized Git repo.
function new-git () {
ssh git@example.com "mkdir $1.git && cd $1.git && git --bare init"
git remote add origin git@example.com:$1.git
git push origin master
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git config push.default current
}
@airblade
airblade / gist:990699
Created May 25, 2011 09:58
Taxonomy names matching "streptococcus pneumonia"
1313 | Streptococcus pneumoniae | | scientific name |
1313 | Streptococcus pneumoniae (Klein 1884) Chester 1901 | | authority |
10728 | Streptococcus pneumoniae bacteriophage HB-3 | | synonym |
10728 | Streptococcus pneumoniae phage HB-3 | | scientific name |
12402 | phage EJ-1 #note host Streptococcus pneumoniae | | misspelling |
120574 | Streptococcus pneumoniae bacteriophage MM1 | | synonym |
170187 | Streptococcus pneumoniae TIGR4 | | scientific name |
171101 | Streptococcus pneumoniae (strain ATCC BAA-255 / R6) | | synonym |
171101 | Streptococcus pneumoniae R6 | | scientific name |
171101 | Streptococcus pneumoniae str. R6 | | synonym |
<MedlineCitation Owner="NLM" Status="MEDLINE">
<PMID Version="1">19663746</PMID>
<DateCreated>
<Year>2009</Year>
<Month>08</Month>
<Day>11</Day>
</DateCreated>
<DateCompleted>
<Year>2010</Year>
<Month>03</Month>
@airblade
airblade / application_helper.rb
Created April 7, 2011 10:55
Nested layouts with HAML in Rails 3
module ApplicationHelper
def inside_layout(layout = 'application', &block)
render :inline => capture_haml(&block), :layout => "layouts/#{layout}"
end
end
def reify_has_manys(model, lookback)
model.class.reflect_on_all_associations(:has_many).each do |assoc|
# Get live children.
children = model.send assoc.name
# Ensure child models are using PaperTrail.
if children.first.respond_to? :version_at
# Handle updated children, and children created since the parent's version.
children_then = []
children.each do |child|
if (child_as_it_was = child.version_at(created_at - lookback.seconds))
class PublicationsController < ActionController::Base
def show
@publication = Publication.find params[:id]
# If you need a specific version, get that from the URL.
version_id = ...
@publication = @publication.versions.find version_id
keywords = [] # the keywords belonging to @publication at the time
keywords_versions = Version.all :item_type => 'Keyword', :publication_id => @publication.id
keywords = [] # the keywords belonging to @publication at the time
keywords_versions = Version.all :item_type => 'Keyword', :publication_id => @publication.id
keywords_versions.group_by(&:item_id).each do |item_id, versions|
v = versions.first :conditions => ['created_at > ?', (@publication.created_at - 3.seconds)]
keywords << (v ? v.reify : Keyword.find(item_id))
end
variables = keywords.map do |keyword|
$ rake test
(in /Users/andy/business/open_source/paper_trail)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/paper_trail_controller_test.rb" "test/paper_trail_model_test.rb" "test/paper_trail_schema_test.rb" "test/thread_safe_test.rb"
/Library/Ruby/Site/1.8/rubygems.rb:233:in `activate': can't activate actionpack (= 2.3.8, runtime) for [], already activated actionpack-3.0.0 for [] (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:35:in `require'
from ./test/test_helper.rb:8
from ./test/paper_trail_controller_test.rb:1:in `require'
from ./test/paper_trail_controller_test.rb:1
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5