Skip to content

Instantly share code, notes, and snippets.

View jgn's full-sized avatar
☂️
Messing around.

John Norman jgn

☂️
Messing around.
View GitHub Profile
@jgn
jgn / memoizable_with_mc.rb
Created February 3, 2011 19:34
Memoization to memcache
# Memcache wrapping in a declarative fashion.
#
# Usage example:
#
# class << self
# extend Utils::MemoizableWithMC
#
# def get_host_details(id)
# select('host_first_name, host_last_name, host_email').find(id)
# end
@jgn
jgn / radix50.rb
Created November 20, 2010 02:14
rad50
#!/usr/bin/env ruby
# http://en.wikipedia.org/wiki/RADIX-50
class String
R50_CHARS = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.%0123456789"
R50_LOOKUP = {}.tap { |h| String::R50_CHARS.split(//).each_with_index { |c, i| h[c] = i } }
R50_CLEAN = /[[:upper:]|[:digit:]| |.|$|%]/
def radix50
[].tap do |r|
self.upcase.scan(R50_CLEAN).inject([]) do |m, c|
m << R50_LOOKUP[c]