Skip to content

Instantly share code, notes, and snippets.

View mateusg's full-sized avatar

Mateus Gomes mateusg

View GitHub Profile
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.before :suite do
DatabaseCleaner.clean_with :truncation
end
config.before :each do
if example.metadata[:js] || example.metadata[:truncation]
@mateusg
mateusg / script_column_search.sql
Created April 17, 2011 23:12
MySQL query to search for columns by name in a database
-- MySQL Query
-- Search all tables from a database for columns that the name matches 'user_id'.
SELECT table_name, column_name FROM information_schema.columns
WHERE table_schema = 'database_name' AND column_name LIKE '%user_id%';
@mateusg
mateusg / 1ntro.markdown
Created December 24, 2011 19:32 — forked from douglasmiranda/1ntro.markdown
Django + git + apache mod_wsgi na Kinghost

#Django + git + apache mod_wsgi na Kinghost

Apenas um lembrete para mim. Mas é legal compartilhar e ter a condição de melhorar com os comentários da galera :)

##Início

Talvez você não queira ficar digitando a senha toda vez que usar o ssh, então adicione sua chave pública ao seu host:

No servidor:

@mateusg
mateusg / ubuntu_nginx_rails_passenger
Created July 16, 2012 21:07
Ubuntu + Nginx + Passenger + Rails 3 setup
rails-nginx-passenger-ubuntu
============================
COPIED FROM: https://github.com/jnstq/rails-nginx-passenger-ubuntu
My notes on setting up a simple production server with ubuntu, nginx, passenger and mysql for rails.
Aliases
-------
@mateusg
mateusg / Preferences.sublime-settings
Created July 18, 2012 18:35
Sublime User preferences
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"color_scheme": "Packages/Railscasts.tmTheme",
"font_face": "Monaco",
"font_size": 12.0,
"tab_size": 2,
//"translate_tabs_to_spaces": true,
"indent_to_bracket": true,
"highlight_line": true,
@mateusg
mateusg / paperclip_file_input.rb
Created December 7, 2012 17:15
Paperclip input for Simple Form
class PaperclipFileInput < SimpleForm::Inputs::FileInput
def input
value = object.persisted? && object.reload.send(attribute_name)
current_image_tag = if value.present? && value.content_type =~ /image/
template.image_tag(value.url, :alt => "#{attribute_name}_image")
else
""
end
@mateusg
mateusg / labels2_simple_form_wrapper.rb
Created December 14, 2012 13:36
SimpleForm wrapper for http://attardi.org:81/labels2/ placeholder plugin.
config.wrappers :inline_form, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.wrapper :tag => 'label', :class => 'input' do |label|
label.use :label_text, :wrap_with => { :tag => 'span' }
label.use :input
end
end
@mateusg
mateusg / sample_deploy.rb
Created December 19, 2012 14:18
Clean Capistrano deploy file with bundler + rvm + permissions restore
# *** RVM CONFIGURATION ***
set :rvm_ruby_string, "ree-1.8.7-2012.02@#####"
set :rvm_type, :system
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset, or:
require 'rvm/capistrano'
require "bundler/capistrano"
set :application, "#######"
@mateusg
mateusg / disable_newrelic_agent_before_start_resque.rb
Last active December 12, 2015 00:49
Fixes the error caused by NewRelic that prevents Resque workers from dying (https://github.com/defunkt/resque/issues/578#issuecomment-12509400). When newrelic_rpm >= 3.5.6.48 is released, remove this hotfix and update the gem.
# deploy.rb
# Fixes the error that prevents resque workers from dying, caused by NewRelic (https://github.com/defunkt/resque/issues/578#issuecomment-12509400).
# FIXME: When newrelic_rpm >= 3.5.6.48 is released, remove this hotfix and update the gem.
task :set_newrelic_false, :roles => [:resque_worker, :resque_scheduler] do
default_run_options[:env] = { 'NEWRELIC_ENABLE' => false }
end
before('resque:start', 'set_newrelic_false')
before('resque:scheduler:start', 'set_newrelic_false')
# === Sem o inverse_of
c = Customer.first
o = c.orders.first
c.first_name == o.customer.first_name # => true
c.first_name = 'Manny'
c.first_name == o.customer.first_name # => false
# === Com o inverse_of
class Customer < ActiveRecord::Base
has_many :orders, inverse_of: :customer