Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / .gitconfig
Last active August 29, 2015 14:14
.gitconfig
[user]
email = tiagopog@gmail.com
name = Tiago Guedes
[alias]
co = checkout
lg = log --all --graph --decorate --oneline --abbrev-commit
cm = commit
ac = !git add -A && git commit
st = status -sb
tags = tag -l
@tiagopog
tiagopog / .zlogin
Created January 29, 2015 02:13
.zlogin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
@tiagopog
tiagopog / monkey_patching.rb
Created January 31, 2015 15:07
Monkey Patch example (Ruby).
puts "--- Example 1:"
class Foo
def bar; "bar" end
end
a = Foo.new
puts "a.bar: #{a.bar}"
puts "--- Example 2:"
@tiagopog
tiagopog / agb_blog_team.rb
Created March 31, 2015 19:20
Select authors for Agb's tech blog.
class Agb
@@team = %w(Barreto Douglas Fabio Giovanni Paulo Raphael Tiago)
def sort
team, i = @@team, 1
while team.length > 0
puts "| #{i} - #{team.delete_at(rand(team.length))} |"
i += 1
end
end
@tiagopog
tiagopog / sti.rb
Created March 31, 2015 22:13
STI example.
class Vehicle < ActiveRecord::Base
attr_accessor :direction
validates :name, presence: true
end
class Car < Vehicle
def turn_wheel(direction)
@direction = direction
puts "wheel was turned to the #{direction}"
end
@tiagopog
tiagopog / gist:56ed29bcebed00c852c7
Last active August 29, 2015 14:18
Polymorphic association example with "belong_to".
class Vehicle < ActiveRecord::Base
validates :name, presence: true
end
class Car < ActiveRecord::Base
belongs_to :vehicle
accepts_nested_attributes_for :vehicle
delegate :name, to: :vehicle
end
@tiagopog
tiagopog / .gitconfig
Last active August 29, 2015 14:18
Git config file.
[user]
email = tiagopog@gmail.com
name = Tiago Guedes
[alias]
co = checkout
lg = log --all --graph --decorate --oneline --abbrev-commit
cm = commit
ac = !git add -A && git commit
st = status -sb
tags = tag -l
@tiagopog
tiagopog / marshaling.rb
Last active August 29, 2015 14:18
Marshal/Unmarshal example in Ruby.
require 'base64'
# Let's first create a non primitive class that will be dumped.
class People
POSSIBLE_NAMES = %w(foo bar)
@@count = 0
def initialize(*attrs)
@@count += 1
@tiagopog
tiagopog / jsonb.rb
Last active August 29, 2015 14:18
JSONB example with Rails
# db/migrate/*_create_authentications.rb
class CreateAuthentications < ActiveRecord::Migration
def change
create_table :authentications do |t|
t.references :user, index: true
t.integer :provider, default: 0, null: false
t.jsonb :access_data, null: false, default: '{}'
t.timestamps
end
@tiagopog
tiagopog / avatar.rb
Created April 9, 2015 14:53
Avatar concern.
# rails g paperclip {{model_name}} avatar && rake db:migrate
module Avatar
extend ActiveSupport::Concern
included do
avatar_options = WMR::Constants::AVATAR_OPTIONS
if Rails.env.production?
avatar_options.merge!(WMR::Constants::S3_CREDENTIALS)
end