This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "⚡") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
: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 } }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in a library | |
class MyClass | |
def initialize(*args) | |
# whatever | |
end | |
end | |
# in an extension | |
class << MyClass | |
def new(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def return(*) | |
if block_given? | |
each do |i| | |
value = yield(i) | |
return value if value | |
end | |
nil | |
else | |
super |