This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function(){ | |
// http://webreflection.blogspot.com/2008/10/subclassing-javascript-native-string.html | |
function MyString(__value__) { | |
this.length = (this.__value__ = __value__ || "").length; | |
}; | |
with(MyString.prototype = new String) | |
toString = valueOf = function() { return this.__value__ }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class MRISC | |
def run(code) | |
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';') | |
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0 | |
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact! | |
while @vars[:_pc] < tokens.size-1 | |
@vars[:_pc] += 1 | |
@vars[:_oc] += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crickets: "hears crickets chirping" | |
drama: "https://123.campfirenow.com/images/drama.jpg" | |
greatjob: "https://123.campfirenow.com/images/greatjob.png" | |
live: "is DOING IT LIVE" | |
pushit: "https://123.campfirenow.com/images/pushit.gif" | |
rimshot: "plays a rimshot" | |
secret: "found a secret area :key:" | |
tada: "ta-da! :flags:" | |
tmyk: ":sparkles: :star: The More You Know :sparkles: :star:" | |
trombone: "plays a sad trombone" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Upgrade PostgreSQL from 9.0 to 9.1 | |
# | |
# by David Sommers | |
# | |
brew update postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CachedSequence | |
extend ActiveSupport::Memoizable | |
def initialize(cache_key) | |
@cache_key = cache_key | |
ensure_value | |
end | |
def next | |
Rails.cache.increment(cache_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CachedHash | |
extend ActiveSupport::Memoizable | |
def initialize(cache_key) | |
@cache_key = cache_key | |
end | |
def [](key) | |
fetch[key] | |
end |
OlderNewer