Skip to content

Instantly share code, notes, and snippets.

View rinaldifonseca's full-sized avatar

Rinaldi Fonseca rinaldifonseca

View GitHub Profile
@rinaldifonseca
rinaldifonseca / config.rb
Created July 15, 2012 20:42
EM-Mongo with Goliath
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('muisco')
end
@rinaldifonseca
rinaldifonseca / gist:3102335
Created July 13, 2012 02:32
Ruby SuperSimpleCallbacks
require 'observer'
module SuperSimpleCallbacks
include Observable
def self.included(klass)
klass.extend ClassMethods
klass.initialize_included_features
end
@rinaldifonseca
rinaldifonseca / gist:3101121
Created July 12, 2012 21:27 — forked from viniciusteles/gist:556029
Sete Atitudes para Hackear a Indústria de Software
Sete Atitudes para Hackear a Indústria de Software
By Klaus Wuestefeld
1) Torne-se excelente.
Seja realmente bom em alguma coisa. Não fique só choramingando ou
querendo progredir às custas dos outros. Não pense q pq vc sentou 4
anos numa faculdade ouvindo um professor falar sobre software q vc
sabe alguma coisa. Jogador de futebol não aprende a jogar bola tendo
@rinaldifonseca
rinaldifonseca / Plea.markdown
Created July 11, 2012 03:41 — forked from justinko/Plea.markdown
Am I doing it wrong?

Dear Rubyists,

I just lost a contract because of my code in a Rails project.

The specific code in question is related to a "posting a comment" feature. Here are the details:

In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.

The "senior developer", whom is the stake holder's right hand man, said this:

@rinaldifonseca
rinaldifonseca / sketch.rb
Created July 9, 2012 04:00 — forked from mikegehard/sketch.rb
Responders implemented using a block instead of another class
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@rinaldifonseca
rinaldifonseca / gist:3049976
Created July 4, 2012 23:03
A better git log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
@rinaldifonseca
rinaldifonseca / mt.rb
Created June 26, 2012 03:27 — forked from alanq/mt.rb
DCI in ruby without injection - MoneyTransfer example
-----------------------------------------
Boilerplate code (in rails_app_root/lib)
-----------------------------------------
module ContextAccessor
def context
Thread.current[:context]
end
end
class DashboardPresenter < ClassicPresenter::Base
def navigation
if context.controller_name == 'vendors'
context.render 'shared/dashboard/vendor_navigation'
end
end
end

#include and #extend have same effect on instances as inheritance

Let's say we have this

module A; end
module B; end
class C; end
class D < C; end

Then we modify instance