Skip to content

Instantly share code, notes, and snippets.

View svenfuchs's full-sized avatar

Sven Fuchs svenfuchs

View GitHub Profile
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
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 February 24, 2009 12:10
super basic git workflow
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
@svenfuchs
svenfuchs / rps.txt
Created March 3, 2009 10:25 — forked from practicingruby/rps.txt
german
# 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 March 15, 2009 13:09
how do you test that form fields submit the parameters that you expect?
# 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
<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"}]}
@svenfuchs
svenfuchs / cldr_pluralization_rules.rb
Created May 4, 2009 08:02
cldr pluralization rules
{
: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 } },
# in a library
class MyClass
def initialize(*args)
# whatever
end
end
# in an extension
class << MyClass
def new(*args)
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.
@svenfuchs
svenfuchs / return.rb
Created June 18, 2009 17:05 — forked from lifo/return.rb
module Enumerable
def return(*)
if block_given?
each do |i|
value = yield(i)
return value if value
end
nil
else
super