require 'spec_statistics' ...
Ruby rake stats for RSpec
by Ben Burkert,
October 17, 2007 19:47,
2 refactorings
def add_phone_link(name) ...
Ruby Combining add/remove links
by Etandrib,
October 16, 2007 21:41,
7 refactorings
I've got a bunch of add and...
def phone_attributes=(phone_attributes)
phone_attributes.each do |attributes|
...
Ruby Combine contact attributes ...
by Etandrib,
October 16, 2007 20:34,
5 refactorings
We have a model where a per...
# Merges two sets of condition options for ActiveRecord::Base find calls def merge_conditions(base_conditions, new_conditions, boolean_operator="AND") return base_conditions if new_conditions.blank? ...
Ruby Merging two sets of conditions
by Barry Hess,
October 15, 2007 21:10,
6 refactorings
I found myself in a situati...
$c = []
def fork_reality(*l)
callcc {|c| $c << c }
...
Ruby Combinatorial explosion wit...
by michiel,
October 14, 2007 10:57,
1 refactoring
This code tries to find all...
require 'erb' class ClientMigrator def self.create(fields) ...
Ruby Dynamic migrations for rails
by danielharan,
October 12, 2007 04:27,
1 refactoring
How do you create a rails p...
def remove_insults(input) ctr = 0 input.each do |word| ...
Ruby Rubyize this : 3rd edition
by FrankLamontagne,
October 11, 2007 15:21,
10 refactorings
This snippet is coming from...
def preview ...
Ruby Ajax form Preview
by Cedric,
October 05, 2007 16:24,
No refactoring
This is my first bit of Aja...
# Converts:
# {:hash => [{:foo => 1}, {:foo => 2}]}
#
...
Ruby Recursively convert multidi...
by Jarrod,
October 05, 2007 08:02,
3 refactorings
there has got to be a bette...
def self.find_left_sibling( parent_id, cat_name )
parent = Category.find( :first,
:conditions => [ "id = ?", parent_id] )
...
Ruby Looking for alphabetized pl...
by midas,
October 04, 2007 07:39,
3 refactorings
Set in array is in alpha or...
x < lower ? lower : x > upper ? upper : x # Or should I just go this way: ...
Ruby Enforcing bounds
by michiel,
October 04, 2007 04:55,
4 refactorings
Given a value and a range, ...
# this method returns a default when the object does not exist or the value given in the block does not exist. # # Example: ...
Ruby Show a default value if obj...
by JohnnyBusca,
October 03, 2007 00:48,
5 refactorings
Often in the view you want ...
chars="1234567890" #only numbers random_code="" ...
Ruby Random number generator
by khillabolt.myopenid.com/,
October 02, 2007 18:38,
18 refactorings
I am a total newbie when it...
SUPPORTED_LANGUAGES = [["English", "en"], ["German", "de"]]
# request.env["HTTP_ACCEPT_LANGUAGE"] = "en-us,us;q=0.5"
@languages = request.env["HTTP_ACCEPT_LANGUAGE"].split(';')[0].split(',')
...
Ruby Accept Language Array
by anshkakashi,
October 02, 2007 12:47,
3 refactorings
This is some rails code whe...
#!/usr/bin/ruby require 'benchmark' include Math ...
Ruby is_prime?
by trappist3.myopenid.com/,
October 01, 2007 14:50,
10 refactorings
This is as fast as I could ...
# given this structure:
array_of_hashes = [
{:callid => '1', :foo => '1', :created_at => '2007-09-21 11:45:15'},
...
Ruby Grouping an array of hashes
by Jarrod,
October 01, 2007 14:15,
3 refactorings
This chunk of code takes an...
cap_growth = 5 v = (@property.current_value / 100 * cap_growth) + @property.current_value ...
Ruby compound interest
by nootopian,
September 30, 2007 12:50,
6 refactorings
there must be a better way ...
before_filter :login_required ...
Ruby restful_authentication role...
by jamesgolick,
September 27, 2007 10:40,
7 refactorings
This is a couple of lines t...
def parse_line
if line_is_parsable?
if line_is_nested?
...
Ruby Arrow Code
by Ben Burkert,
September 26, 2007 17:00,
9 refactorings
I hate arrow code. It's ug...
task :extract_style do
css = File.read 'public/stylesheets/code.css'
css.gsub! "{\n", '{'
...
Ruby Extracting style from a CSS...
by macournoyer,
September 25, 2007 21:18,
2 refactorings
Here's a Rake task I use to...
class CodeFormatter cattr_reader :syntaxes @@syntaxes = Uv.syntaxes.sort ...
Ruby [FEATURE] Sections in code!
by macournoyer,
September 22, 2007 08:44,
No refactoring
Introducing a new feature: ...
# Behave like +link_to_remote+, but shows a spinner while the request is processing. # link_to_remote_with_spinner 'Hi', :url => hi_path # You can specify the spinner and the container to hide ...
Ruby link_to_remote_with_spinner
by danielharan,
September 20, 2007 14:17,
5 refactorings
We use this utility interna...
def test_should_create_image_if_necessary_before_trying_to_give_it_data
file = mock()
file.expects(:content_type).returns('jpg')
...
puts `find test/ -name "*_test.rb" | wc -l`.to_f / `find app/ -name "*.rb" | wc -l`.to_f
Ruby Test file to code file ratio
by macournoyer,
September 20, 2007 09:19,
3 refactorings
Hackish script to get the t...
I want to get some statisti...