Skip to content

Instantly share code, notes, and snippets.

View fellix's full-sized avatar

Rafael Felix fellix

View GitHub Profile
@fellix
fellix / demeter.rb
Created November 26, 2012 13:14
Sample Demeter
class A
attr_accessor :b
delegate :c, :to => :b
def do_things
c.do_things
end
end
@fellix
fellix / gist:4132182
Created November 22, 2012 17:11
my bash profile
source /usr/local/Cellar/git/1.7.11.3/etc/bash_completion.d/git-completion.bash
function git_branch_name(){
git branch 2>/dev/null | grep -e '^*' | sed -E 's/^\* (.+)$/(\1) /'
}
function show_colored_git_branch_in_prompt(){
#PS1="\[\033[01;32m\]\u@\h:\[\033[01;34m\]\w\[\033[31m\]\$(git_branch_name)\[\033[m\]$ "
#PS1='\[\033[32m\]\u \033[34m\][\w]\[\033[00m\]:\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '
PS1='\[\033[32m\]\u \033[01;34m\][\w]\[\033[31m\]$(__git_ps1)\[\033[00m\] \$ '
}
@fellix
fellix / script.rb
Created October 23, 2012 16:51 — forked from manfe/script.rb
Recuperando Cidades de Estados Brasileiros
require 'nokogiri'
require 'htmlentities'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.ibge.gov.br/cidadesat/includes/ac.inc'))
doc = doc.xpath('//p')
doc.each do |c|
@variables = c.text
@fellix
fellix / some_controller.rb
Created October 11, 2012 01:57
Custom token authenticable
class SomeController < ApplicationController
before_filter :authenticate_with_public_token!
private
def authenticate_with_public_token!
if params[:key] && user = User.find_by_public_token(params[:key])
sign_in("user", user)
else
authenticate_user!
@fellix
fellix / using_rspec_stuff.rb
Created October 3, 2012 13:25
test approach
context 'order' do
let :first_payment do
Payment.create
end
let :last_payment do
Payment.create
end
let :payments do
@fellix
fellix / gist:3643749
Created September 5, 2012 20:07
Receita de pao de queijo
3 ovos
3 xícaras de polvilho (preferencia azedo, mas pode usar o doce também)
1 xícara de azeite
100g de queijo (qualquer um)
sal a gosto.
bata no liquidificador tudo, despeje em formas de empadinha coloque assar no forno, espere dourar, e pronto.
@fellix
fellix / person.js
Created May 11, 2012 20:00
js prototype
var Nohup;
Nohup = {};
Nohup.Person = function Person(){
var init = function(name, age){
this.name = name;
this.age = age;
};
var Person = function(){
init.call(this, arguments[0], arguments[1]);
class SomethingController < ApplicationController
respond_to :html, :json
def show
@something = Something.find(params[:id])
respond_with(@something) do |format|
format.html { render :layout => 'report' }
end
end
end
@fellix
fellix / delegate.rb
Created April 13, 2012 19:52
Delegate them all
class Child < ActiveRecord::Base
belongs_to :parent
def method_missing method_name, *args, &block
return super unless parent.respond_to? method_name
parent.__send__ method_name
end
end
@fellix
fellix / routes.rb
Created March 6, 2012 00:15
config devise url
devise_scope :admins do
post '/sign_in', :to => "devise/sessions#create", :as => :admin_session
delete '/sign_out', :to => "devise/sessions#destroy", :as => :destroy_admin_session
end