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, ...

7c45f63f61e478233f0c2ad3006b178c Talk
# 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...

376dc89f458bb3b9ac3fd4d559098645 Talk
keys = {
  "a" => %w(q w s z),
  "b" => %w(v n g h),
...

Ruby Getting QWERTY misstypes

by slaskis, October 23, 2007 13:17, 3 refactorings

This is not really a refact...

Ad2ffc6b05fb4390643f36a258b86362 Talk
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...

3092831491e0e9f9d654fbc080ceca91 Talk
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...

B87cf29c05d9ce7a26588d6c48e5d988 Talk
# 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...

376dc89f458bb3b9ac3fd4d559098645 Talk
# String#to_proc
#
# See http://weblog.raganwald.com/2007/10/stringtoproc.html ( Subscribe in a reader)
...

Ruby String#to_proc (by Reginald...

by webmat, October 28, 2007 06:27, 3 refactorings, tagged with functional

Reginald Braithwaite has a ...

A908bf6680c4fa7279dd85d5012f7ed8 Talk
require 'spec_statistics'
...

Ruby rake stats for RSpec

by Ben Burkert, October 17, 2007 19:47, 2 refactorings

I want to get some statisti...

4d1c9dad17af98e55cb65b4efce27c42 Talk
def new
  @course  = Course.new
...

Ruby Using partials for a golf s...

by rpheath, October 24, 2007 05:21, 2 refactorings

I'm building a golf applica...

E635ccff7389d9070f5e7e9fe8b36beb Talk
namespace :migrations do
  
  desc 'reverts, renames and re-executes uncommitted migrations that conflict with already committed migrations'
...

Ruby Rails migration conflict re...

by danielharan, October 26, 2007 18:25, 1 refactoring, tagged with rails

Explained here: http://www....

880cbab435f00197613c9cc2065b4f5a Talk
def args_eval(line)
  tokens = []
  while(data = line.match(/\[.*\]/))
...

Ruby Argument eval

by Ben Burkert, October 22, 2007 19:56, 1 refactoring

this code evaluates a strin...

4d1c9dad17af98e55cb65b4efce27c42 Talk
has_attachment :content_type => :image
...

Ruby attachment_fu integration

by Dominik, October 24, 2007 19:58, 1 refactoring

I have used the attachment_...

567298f59cff5f985ac7e502983dbf1e Talk
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...

880cbab435f00197613c9cc2065b4f5a Talk
$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...

7c45f63f61e478233f0c2ad3006b178c Talk
class TreeNode
  def TreeNode.action(action)
    @@action = action
...

Ruby Changing contexts in a DSL ...

by claymccoy.myopenid.com, October 18, 2007 20:31, No refactoring

I use this code in a blog p...

Ad4d43ea62451b22882744a9f392b9d7 Talk
def preview
...

Ruby Ajax form Preview

by Cedric, October 05, 2007 16:24, No refactoring

This is my first bit of Aja...

D329280c04406af1e2e010a8c0ccd092 Talk
# Note: Kuwait does not use DST.  
# See how the utc_offset value represents 
...

Ruby A DST-adjusted UTC offset

by Barry Hess, October 25, 2007 14:09, No refactoring

I need to get the Daylight-...

0218fde3a78fadbadb566bdb40d7b0dd Talk
(1..10).each do |i|
  puts i
end

Ruby Ruby simple loop

by macournoyer, September 11, 2007 20:14, 39 refactorings

How to make this shorter ?

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
def random_pronouncable_password(size = 4)
  c = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
  v = %w(a e i o u y)
...

Ruby Random pronouncable password

by macournoyer, September 16, 2007 20:30, 12 refactorings

Method that returns a rando...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
?

Ruby Integer puzzle

by macournoyer, September 19, 2007 10:39, 10 refactorings

If the integers from 1 to 9...

Bfec5f7d1a4aaafc5a2451be8c42d26a Talk
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...

4d1c9dad17af98e55cb65b4efce27c42 Talk
before_filter :login_required
...

Ruby restful_authentication role...

by jamesgolick, September 27, 2007 10:40, 7 refactorings

This is a couple of lines t...

F6eddf2f983d23c2d031e407852625e9 Talk
def sum_string_sizes(units)
  units.inject(0) {|memo, unit| memo + unit.size }
end
...

Ruby Sum string sizes

by danielharan, September 19, 2007 19:18, 7 refactorings

This code is functional, bu...

880cbab435f00197613c9cc2065b4f5a Talk
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 ...

62c433a96de9da99d09afedcded5de76 Talk
# 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...

880cbab435f00197613c9cc2065b4f5a Talk