1
2
3
4
# The idea is that each morse code is encoded as a number: 
# "a" is mapped to 19, which in base 3 is 201, the 2 works as a dummy to keep leading 0's in place, so the real value is "01" which maps to the morse code ".-"
# "b" is mapped to 189, which in base 3 is 21000, remove the 2 and the real value is "1000" which maps to the mores code "-..."
...

Ruby On Morse Code Encoder/Decoder

by lel, October 18, 2008 15:25

Juggling ascii-numbers, bas...

2fa67a053f1bb83dca069df3c9f51a8a Talk
1
2
3
4
a ||= Hash.new([])  # default value for non-existing keys is now an empty array, unless a was already defined

a[:k] # => []
...

Ruby On Assignment from array

by lel, July 22, 2008 14:15

The above Hash.new can be m...

2fa67a053f1bb83dca069df3c9f51a8a Talk
1
2
3
4
def self.find_by_url_like(url)
  # make sure url has a scheme before URI parses
  uri = url.match(/^https?:\/\//) ? URI.parse(url) : URI.parse("http://#{url}") 
...

Ruby On Find a URL in a database

by lel, July 18, 2008 23:54

Naming the method find_by_u...

2fa67a053f1bb83dca069df3c9f51a8a Talk