Skip to content

Instantly share code, notes, and snippets.

@ryana
ryana / error
Created January 11, 2011 23:05
Errors running mongo_mapper on 1.9.2
ra:mongomapper ryan$ rvm use 1.8.7@mongo_mapper && rake test
info: Using ruby 1.8.7 p302 with gemset mongo_mapper
(in /Users/ryan/code/mongomapper)
--- Active Support Version: 3.0.0 ---
Loaded suite /Users/ryan/.rvm/gems/ruby-1.8.7-p302@mongo_mapper/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
@ryana
ryana / methods.rb
Created March 2, 2011 20:32
WTF is Ruby1.9 doing this to us?
ra:~ ryan$ rvm list
rvm rubies
=> ree-1.8.6-20090610 [ x86_64 ]
ree-1.8.7-2010.01 [ i386 ]
ree-1.8.7-2010.02 [ x86_64 ]
ruby-1.8.7-p249 [ i386 ]
ruby-1.8.7-p302 [ x86_64 ]
ruby-1.9.1-p243 [ ]
@ryana
ryana / gist:957555
Created May 5, 2011 18:08
nerdrage
ruby-1.9.2-p180 :013 > false.to_json
=> "false"
ruby-1.9.2-p180 :014 > JSON.parse(false.to_json)
JSON::ParserError: 737: unexpected token at 'false'
from /Users/ryan/.rvm/gems/ruby-1.9.2-p180@4seg/gems/json-1.5.1/lib/json/common.rb:148:in `parse'
...
from script/rails:6:in `<main>'
ruby-1.9.2-p180 :015 >
@ryana
ryana / example.rb
Created May 27, 2011 20:33
mulligan - a concept for dealing with things that can fail frequently
Mulligan.initialize
puts "BEGIN"
#succeeding
mulligan(:times => 4) do
puts "mulligan!"
end.on_failure do
puts "fail"
Connection Times (ms)
min mean[+/-sd] median max
Connect: 51 57 4.5 55 72
Processing: 60 71 7.9 70 158
Waiting: 53 62 7.3 61 150
Total: 111 127 8.3 126 210
Percentage of the requests served within a certain time (ms)
50% 126
66% 128
@ryana
ryana / presenter_example.rb
Created June 19, 2011 23:53
doing hayzoos' job :P
class Vid < AR::Base
after_save :encode
private
def encode
VidEncoder.go(self)
end
end
class VidEncoder
@ryana
ryana / my_model.rb
Created June 29, 2011 01:45
A simple fragment caching example in Rails 3
class Conversation
#...
after_create :expire_dash_cache
def add_new_comments(comments)
# Do stuff w/ the new comments...
save
expire_dash_cache
@ryana
ryana / dada_memcache_reloads.rb
Created July 7, 2011 00:16
Thoughts on reloading github.com/trada/dada.git configs w/ a memcache triggers
# Note: not tested at all
module Dada
attr_accessor :config_reload_timestamp
def dalli
@dalli ||= Dalli::Client.new(client_args)
end
def check_config_timestamp
@ryana
ryana / Gemfile.rb
Created July 8, 2011 17:13
FourthSegment Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'jquery-rails', '0.2.7'
gem 'uuid'
gem 'bson_ext'
gem 'mongo_ext'
gem 'mongo_mapper', '0.9.1'
gem 'devise'
gem 'mm-devise'
@ryana
ryana / url_regex.rb
Created August 8, 2011 19:23
@gruber's improved regex for matching URLs written in Ruby
# From @gruber http://daringfireball.net/2010/07/improved_regex_for_matching_urls
UrlRegex = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\`!()\[\]{};:\'\".,<>?«»“”‘’]))/i