Skip to content

Instantly share code, notes, and snippets.

" Automatically align multiline hashes in Ruby (Ruby 1.9 syntax only).
function! AlignRubyHashes()
" Only look for lines that start with a simple keyword, colon, space, and
" ending in a comma.
let p = '^\s*\w\+:\s.*,$'
" Don't do anything if there is no Tabularize, or there is no surrounding
" line that can be aligned with.
if exists(':Tabularize') && (getline(line('.')) =~# '^\s*\w\+:\s$') && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
" save current position because later command moves the cursor
(defn ack [m n]
(if (= m 0)
(+ n 1)
(if (= n 0)
(ack (- m 1) 1)
(ack (- m 1) (ack m (- n 1))))))
@iain
iain / gist:7819
Created August 28, 2008 20:45 — forked from svenfuchs/gist:7818
activerecord.errors.models.content.attributes.topic.invalid
activerecord.errors.models.content.invalid
activerecord.errors.messages.invalid
# with STI
activerecord.errors.models.post.attributes.topic.invalid
activerecord.errors.models.post.invalid
activerecord.errors.models.content.attributes.topic.invalid
activerecord.errors.models.content.invalid
activerecord.errors.messages.invalid
humans do:
errors.add(:topic, :custom_invalid)
rails does:
errors.add(:topic, :invalid, :default => :custom_invalid)
@iain
iain / bench.rb
Created January 10, 2009 14:08 — forked from wycats/bench.rb
I want this for my own :P
require "rubygems"
require "rbench"
RBench.run(500) do
report("memoed") do
Foo.memoed("hello")
end
report("unmemoed") do
Foo.unmemoed("hello")
end
@iain
iain / gist:45111
Created January 9, 2009 14:12
quotes terwijl arieslet down was
Marcel: "Ja, we willen graag dat jullie een huis bouwen. Het moet met hout, stenen of een voordeur!"
Iain: "We gebruiken dezelfde versie van WordPress als Hannibal toen hij blogde over hoe hij olifanten gebruikte om de Alpen door te trekken"
@iain
iain / gist:63953
Created February 13, 2009 15:31
First try Rails template
# File management
run "rm README"
file "README.rdoc", "TODO add readme content"
run "cp config/database.yml config/database.example.yml"
run "rm public/index.html"
# RSpec as plugin, because it won't freeze easily as gem
plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git"
plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git"
#!/bin/bash
# Unattended REE/Passenger installation
# Source: http://weblog.brightlight-ict.nl/2008/12/unattended-passenger-ruby-enterprise-installation-on-ubuntu-8/
# 15/03/09 Updated to use latest r.e.e. and passenger 2.1 and rewrote bits thanks to the comments left on my blog. Thanks guys
if [ "$(whoami)" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
@iain
iain / gist:87691
Created March 30, 2009 08:45
Dutch version of default webrat steps
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
# Commonly used webrat steps
# http://github.com/brynary/webrat
# Dutch webrat steps translated by Iain
# http://iain.nl/
Stel /^ik ben op (.+)$/ do |page_name|
visit path_to(page_name)
end
@iain
iain / Rake spec with normal Remarkable procedure
Created May 24, 2009 09:56
Remarkable 3.1.2 on Ruby 1.9.1
$ rake spec
/home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant Remarkable::ActiveRecord (NameError)
from /home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing_with_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/remarkable_rails-3.1.2/lib/remarkable_rails/active_orm.rb:17:in `<top (required)>'
from /home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require'
from /home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/remarkable_rails-3.1.2/lib/remarkable_rails.rb:25:in `<top (required)>'
from /home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require'
from /home/iain/code/sail/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in `require'
from /home/iain/code/sail/spec/spec_helper.r