Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
jnunemaker / gist:3093898
Created July 11, 2012 21:58
RubyConf Brazil Talk

Addicted to Stable

Stable? In most developer communities, especially Ruby, stable seems nothing short of a curse word. Everyone seems to be addicted to new. I should know, as I once was. Heck, I even own addictedtonew.com.

Over the past few years, my sentiments have changed. Through my experience maintaining and growing a handful of applications, I have grown to respect and love stability.

This talk is jam packed with everything I have learned about building and growing a production application. Stories of mistakes and victories will abound.

@jnunemaker
jnunemaker / mongodb_slave_synced_time.rb
Created June 12, 2012 02:24
mogodb get last synced time for slave in master/slave setup
db.command(BSON::OrderedHash['serverStatus', 1, 'repl', 1])['repl']['sources'].first['syncedTo']['time']
@jnunemaker
jnunemaker / mind_blower_ruby19.rb
Created May 30, 2012 13:40
Mongo allows objects as _id. _id is always indexed and Mongo knows how to index complex objects.
require 'pp'
require 'rubygems'
require 'mongo'
conn = Mongo::Connection.new
db = conn.db('test')
col = db['test']
col.remove
oid = BSON::ObjectId.new
@jnunemaker
jnunemaker / null_object.rb
Created April 15, 2012 13:38
basic null object
# from http://avdi.org/talks/confident-code-rubymidwest-2011/confident-code.html
class NullObject
def method_missing(*)
self
end
def nil?
true
end
@jnunemaker
jnunemaker / fetch_as_assertion.rb
Created April 15, 2012 13:38
fetch as an assertion
# from http://avdi.org/talks/confident-code-rubymidwest-2011/confident-code.html
opt = {}.fetch(:required_option)
# IndexError: key not found
opt = {}.fetch(:required_option) do
raise ArgumentError, "Missing option!"
end
# ArgumentError: Missing option!
@jnunemaker
jnunemaker / two_dimentional_list.io
Created March 16, 2012 15:02
Two dimensional list prototype in Io
TwoDimensionalList := Object clone
TwoDimensionalList list := List clone
TwoDimensionalList dim := method(x, y,
for(i, 1, y,
self list push(List clone setSize(x))
self
)
)
@jnunemaker
jnunemaker / heroku_create_app.rb
Created January 30, 2012 22:08
Simple script that shows how to create heroku app without command line client
require 'rubygems'
require 'highline/import'
require 'heroku'
require 'pp'
email = ask('Email: ')
password = ask('Password: ') { |q| q.echo = false }
client = Heroku::Client.new(email, password)
class UserPresenterTest < Test::Unit::TestCase
def test_as_json
user = Factory(:user, {
:first_name => 'John',
:last_name => 'Nunemaker',
:email => 'john@doe.com',
})
json = UserPresenter.new(user).as_json
urls = json['urls']
@jnunemaker
jnunemaker / fu.md
Created July 12, 2011 23:20
FUN BUG?!

Posted to the REE Google Group as well: https://groups.google.com/forum/#!topic/emm-ruby/EBkMfFpk40A

A week back I innocently updated Sinatra on an app which in turn updated Rack. Since then, I've had crazy hung passenger processes that just gobble up CPU like it is going out of style.

After spending a few days trying everything I knew to to fix it, today I got help from a friend (Eric Lindvall) and dug in with strace, rbtrace, gdb, and gdb.rb and found the issue. Rack 1.3.0 tests a regex against a URL and it causes things to hang.

@jnunemaker
jnunemaker / gist:841656
Created February 24, 2011 02:38
all time views across system for http://gaug.es
# How we store all time views across the entire system for http://gauge.es.
# All in one document that gets incremented using MongoDB $inc modifier in
# every track. The $inc increments t, year.t, year.month.t, year.month.day.t
# so we get to the day numbers. These are in EST, as we are in EST and these
# stats are just for us. :) Nothing amazing, but thought I would share.
#
# >> pp View.all_time
{
"_id" => "all_time",
"t" => 502352,