Skip to content

Instantly share code, notes, and snippets.

View plugin_intializers.rb
Rails::Initializer.class_eval do
def load_application_initializers_with_plugin_initializers
if gems_dependencies_loaded
plugin_loader.load_plugin_initializers
end
load_application_initializers_without_plugin_initializers
end
alias_method_chain :load_application_initializers, :plugin_initializers
end
View git_prompt.sh
function __git_dirty {
local dirty RED NO_COLOR
RED="\033[0;31m"
NO_COLOR="\e[0m"
dirty=$(git diff-index --cached --quiet HEAD 2>/dev/null || echo "")
if [ ! -z "$dirty" ]; then
echo "${RED}${dirty}${NO_COLOR}";
return;
fi
dirty=$(git diff-index --quiet HEAD 2>/dev/null || echo "")
@svenfuchs
svenfuchs / gist:69538
Created Feb 24, 2009
super basic git workflow
View gist:69538
git clone [repo url] # checkout the codebase
git pull # to update your local copy, do that once in a while
[do your changes]
git add . # "stage" all changes for being committed
git commit -m "[msg]" # commit your changes, replace [msg] with a short description of your changes
git push # pushes your commit to the public repository
View rps.txt
# German version
# NOTE: We actually say "Scissors-Rock-Paper" ("Schere-Stein-Papier"), in this order
# see http://de.wikipedia.org/wiki/Schere,_Stein,_Papier
Stein
Papier
Schere
Los geht's!
@svenfuchs
svenfuchs / gist:79411
Created Mar 15, 2009
how do you test that form fields submit the parameters that you expect?
View gist:79411
# how do you test that form fields submit the parameters that you expect?
# the following works. is there any simpler way?
class ActiveSupport::TestCase
def params_from_form(html, id = nil)
id, html = 'test', %(<form id="test">#{html}</form>) unless html =~ /<form /
session = Webrat::Session.new
scope = Webrat::Scope.new(session) { @response_body = html }
Webrat::Locators::FormLocator.new(session, scope.dom, id).locate.send(:params)
end
View gist:79436
<form>
<select type="text" name="filters[body][][scope]"><option name="contains">contains</option></select>
<input type="text" name="filters[body][][query]" value="foo">
<select type="text" name="filters[body][][scope]"><option name="starts_with">starts_with</option></select>
<input type="text" name="filters[body][][query]" value="bar">
<input type="submit" id="submit" value="submit">
</form>
# when send through browser (safari, firefox)
{"body"=>[{"scope"=>"contains", "query"=>"foo"}, {"scope"=>"starts_with", "query"=>"bar"}]}
View cldr_pluralization_rules.rb
{
:af => { :_plural => lambda { |n| n == 1 ? :one : :other } },
:am => { :_plural => lambda { |n| (0..1).include?(n) ? :one : :other } },
:ar => { :_plural => lambda { |n| n == 0 ? :zero : n == 1 ? :one : n == 2 ? :two : (3..10).include?(n % 100) ? :few : (11..99).include?(n % 100) ? :many : :other } },
:az => { :_plural => lambda { |n| :other } },
:be => { :_plural => lambda { |n| n % 10 == 1 && n % 100 != 11 ? :one : (2..4).include?(n % 10) && !(12..14).include?(n % 100) ? :few : n % 10 == 0 || (5..9).include?(n % 10) || (11..14).include?(n % 100) ? :many : :other } },
:bg => { :_plural => lambda { |n| n == 1 ? :one : :other } },
:bh => { :_plural => lambda { |n| (0..1).include?(n) ? :one : :other } },
:bn => { :_plural => lambda { |n| n == 1 ? :one : :other } },
:bo => { :_plural => lambda { |n| :other } },
View gist:122274
# in a library
class MyClass
def initialize(*args)
# whatever
end
end
# in an extension
class << MyClass
def new(*args)
View What makes you a Twitter spammer?
Blocky (@blocky_bot, http://blocky.elliottkember.com) is a crowdsourcing
solution for Twitter spam. Blocky does not define what a "spammer" is,
so let's discuss.
What makes you a Twitter spammer?
- You follow me just to make me follow you.
There's a good chance this applies when you start following me even though
you already are following 500+ people.
View return.rb
module Enumerable
def return(*)
if block_given?
each do |i|
value = yield(i)
return value if value
end
nil
else
super