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 / OrderedSet
Created April 10, 2011 03:28
OrderedSet leveraging ActiveSupport::OrderedHash to get predictable behavior across 1.8.x, 1.9.x
# Force the underlying store for a Set to be an OrderedHash.
class OrderedSet < Set
def initialize(enum = nil, &block)
@hash ||= ActiveSupport::OrderedHash.new
super
end
end
@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]