1
grep -o  regexp filename

Ruby On Print out the Regex Capture

by michiel, November 06, 2007 01:48 Star_fullStar_fullStar_full
7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
SIXTYTWO = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a

def to_s_62(i)
...

Ruby Base 62 Encoding

by michiel, November 01, 2007 01:42, 2 refactorings, tagged with speed

Base WHAT??? Well, 62 is th...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
class String
  unless ''.respond_to?(:to_proc)
    def to_proc(&block)
...

Ruby On String#to_proc (by Reginald...

by michiel, October 28, 2007 18:35 Star_full

Ok, I've removed the nested...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
require 'rubygems'
require 'active_support'

...

Ruby On Rubyize this : 4th edition

by michiel, October 24, 2007 11:15

Building on Mark Van Holsty...

7c45f63f61e478233f0c2ad3006b178c Talk

Ruby On Argument eval

by michiel, October 23, 2007 11:33

And you don't use "eval" be...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
$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
1
2
3
4
# in helper 

  TIME_REMAINING_TODAY =  {
...

Ruby On Iffy

by michiel, October 12, 2007 01:37

YAML solutions break down w...

7c45f63f61e478233f0c2ad3006b178c Talk
1
primes = Array.new(nil, ceiling + 1)

Ruby On is_prime?

by michiel, October 07, 2007 16:28

Looks good, David! One nitp...

7c45f63f61e478233f0c2ad3006b178c Talk
1
(1..500).map {rand(10 ** 16).to_s.rjust(16,'0')}

Ruby On Random number generator

by michiel, October 05, 2007 13:43 Star_fullStar_fullStar_fullStar_fullStar_full

You know, rand(x) doesn't r...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
# Converts:
# {:hash => [{:foo => 1}, {:foo => 2}]}
# 
...

Ruby On Recursively convert multidi...

by michiel, October 05, 2007 09:31 Star_fullStar_fullStar_fullStar_full

In your inner loop, i == a[...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
def self.find_left_sibling( parent_id, cat_name )
    parent = Category.find( :first, 
                            :conditions => [ "id = ?", parent_id] )
...

Ruby On Looking for alphabetized pl...

by michiel, October 04, 2007 15:47

The previous refactoring is...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
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
1
2
3
4
def show_value_or_default(object, default = "-")
  return default if object.nil?
  tmp = yield(object)  
...

Ruby On Show a default value if obj...

by michiel, October 03, 2007 18:52 Star_fullStar_fullStar_fullStar_fullStar_full

The original solution is fi...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
class Integer
  PR = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
  def is_prime?
...

Ruby On is_prime?

by michiel, October 01, 2007 19:55

This is a concise implement...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
require 'benchmark'
include Math

...

Ruby On is_prime?

by michiel, October 01, 2007 19:40

This is equally long, and 2...

7c45f63f61e478233f0c2ad3006b178c Talk
1
2
3
4
class Array
  def pick
    at rand(size)
...

Ruby On Random pronouncable password

by michiel, October 01, 2007 13:18 Star_fullStar_fullStar_fullStar_fullStar_full

There is duplication in the...

7c45f63f61e478233f0c2ad3006b178c Talk