Skip to content

Instantly share code, notes, and snippets.

View rafaelp's full-sized avatar

Rafael Lima rafaelp

View GitHub Profile
@rafaelp
rafaelp / protect_attributes_matcher.rb
Created August 29, 2010 00:38
RSpec extension: matcher to test attr_protected
# Refactored from: http://snippets.dzone.com/posts/show/4712
Spec::Matchers.define :protect_attributes do |*attributes|
match do |target|
calculate_protected_methods(target)
perform_check(attributes)
end
failure_message_for_should do |target|
"expected #{@failed_attribute} to be protected"
end
@rafaelp
rafaelp / h.sh
Created September 6, 2010 17:22
Shell script to skip typing --app XXX on heroku commands when you have more than one enviroment like staging and production.
#!/bin/bash
set -eux
exec heroku "$@" --app "`basename $PWD`-staging"
#!/bin/bash
set -eux
exec heroku "$@" --app "`basename $PWD`-production"
@rafaelp
rafaelp / empreenda-1.txt
Created September 7, 2010 14:11
Notas sobre empreendedorismo
Vasculhando a papelada em casa encontrei este rascunho.
Acho que foi escrito na palestra pública pré-Empretec.
Não me preocupei em corrigir concordância, quis registrar como foi escrito na ocasião.
***
"Ideia de Negócio" é diferente de "Oportunidade de Negócio"
Empreender
@rafaelp
rafaelp / curriculo.doc
Created March 23, 2011 18:54
Currículo
CAVEIRA!
@rafaelp
rafaelp / deploy.rake
Created June 7, 2011 15:30
Rake task to deploy startupdev-ideas
namespace :heroku do
APP = 'startupdev-ideas'
def run(*cmd)
system(*cmd)
raise "Command #{cmd.inspect} failed!" unless $?.success?
end
def confirm(message)
print "\n#{message}\nAre you sure? [Yn] "
@rafaelp
rafaelp / gist:1013010
Created June 7, 2011 19:56
Stats do Startup DEV Ideas dia 1 às 5:00PM
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 63 | 53 | 2 | 7 | 3 | 5 |
| Helpers | 7 | 7 | 0 | 1 | 0 | 5 |
| Models | 12 | 10 | 1 | 1 | 1 | 8 |
| Libraries | 40 | 36 | 0 | 1 | 0 | 34 |
| Model specs | 33 | 27 | 0 | 1 | 0 | 25 |
| View specs | 0 | 0 | 0 | 0 | 0 | 0 |
| Controller specs | 148 | 121 | 0 | 1 | 0 | 119 |
@rafaelp
rafaelp / notification_spec.rb
Created June 8, 2011 13:32
Exemplo de como testar Mailers com RSpec
require "spec_helper"
describe Notification do
describe "idea created" do
before(:each) do
@idea = Idea.new({
:author_name => 'Nome do Usuario',
:author_email => 'emaildousuario@example.com',
})
@idea.stub(:id).and_return(98765)
@rafaelp
rafaelp / idea.rb
Created June 8, 2011 14:22
How to avoid duplicate entries on self generated hash (edit_code in this example)
# model
before_create :set_edit_code
def self.friendly_token
ActiveSupport::SecureRandom.hex(10)
end
def self.edit_code_exists?(edit_code)
!where(:edit_code => edit_code).first.nil?
@rafaelp
rafaelp / gist:1080310
Created July 13, 2011 13:43
Chat Startup DEV #2 - Dia 1
[09:18am] adams.freenode.net: [freenode-info] if you're at a conference and other people are having trouble connecting, please mention it to staff: http://freenode.net/faq.shtml#gettinghelp
[09:27am] mergulhao joined the chat room.
[09:31am] dannluciano joined the chat room.
[09:31am] dannluciano: bom dia pessoal
[09:34am] willian joined the chat room.
[09:34am] willian: bom dia!
[09:35am] willian: sobre o q será o projeto hj?
[09:35am] ChanServ made this room no longer a secret.
[09:35am] ChanServ changed this room to require operator status to change the topic.
[09:35am] rafael_lima: Bom Dia!
@rafaelp
rafaelp / flash_example.txt
Created July 13, 2011 15:58
Exemplo de uso de flash message em app Rails
# application.html.erb
<%= render_flash_messages %>
# application_helper.rb
def has_flash_messages?
flashes = [:alert, :notice, :warning, :message, :failure]
flash and flashes.find { |key| flash.has_key?(key) }
end