Skip to content

Instantly share code, notes, and snippets.

View mateusg's full-sized avatar

Mateus Gomes mateusg

View GitHub Profile
@carloslopes
carloslopes / database_cleaner.rb
Last active August 29, 2015 13:56
DatabaseCleaner configuration
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.use_transactional_fixtures = false
config.before :suite do
DatabaseCleaner.clean_with :truncation
end
@major
major / commitdiff.sh
Created March 14, 2012 04:15
Differences in commits between two branches (on rackerhacker.com)
MASTER=`git log --pretty=format:'%H' master | sort`
DEV=`git log --pretty=format:'%H' development | sort`
for i in `diff <(echo "${MASTER}") <(echo "${DEV}") | grep '^>' | sed 's/^> //'`;
do
git --no-pager log -1 --oneline $i;
done
@rchampourlier
rchampourlier / google_bot_aware.rb
Created May 3, 2012 22:32
Rack middleware to make Rails deal correctly with GoogleBot's '*/*;q=0.6' Accept header
# This Rack middleware helps solving the issue with some Rails versions which do not accept
# a '*/*;q=0.6' and their variants 'Accept' request header. This header is particularly used
# by Google Bot, and if Rails doesn't like it, it will return a 500 or 406 error to Google Bot,
# which is not the best way to get your pages indexed.
#
# References:
# - http://stackoverflow.com/questions/8881756/googlebot-receiving-missing-template-error-for-an-existing-template
# - https://github.com/rails/rails/issues/4127
#
class GoogleBotAware
@brennovich
brennovich / stubbed_sign_in.rb
Created May 15, 2013 21:14
Warden stubbed sign in
def stubbed_sign_in user
request.env['warden'].stub :authenticate! => user
controller.stub :current_user => user
end
@stevenharman
stevenharman / _compose_query_objects.md
Last active December 19, 2017 21:33
Build compose-able query objects by delaying query execution and delegating to the underlying `ActiveRecord::Relation` for everything else. #ruby #rails

Compose-able Query Objects in Rails

Example usage:

old_accounts = Account.where("created_at < ?", 1.month.ago)
old_abandoned_trials = AbandonedTrialQuery.new(old_accounts)

old_abandoned_trials.find_each do |account|
 account.send_offer_for_support
@klauswuestefeld
klauswuestefeld / gist:1595701
Created January 11, 2012 17:22
O Ciclo Vicioso Do Software Retranqueiro
We couldn’t find that file to show.
@mitio
mitio / deploy.rb
Created August 23, 2013 15:38
Sidekiq + Capistrano + Ubuntu Upstart
# config/deploy.rb
namespace :upstart do
desc 'Generate and upload Upstard configs for daemons needed by the app'
task :update_configs, except: {no_release: true} do
upstart_config_files = File.expand_path('../upstart/*.conf.erb', __FILE__)
upstart_root = '/etc/init'
Dir[upstart_config_files].each do |upstart_config_file|
config = ERB.new(IO.read(upstart_config_file)).result(binding)
@jherdman
jherdman / README.md
Last active January 11, 2022 05:49 — forked from ankane/README.md
A Gem loading benchmark script

Benchmark Bundler

Because loading gems can take longer than you think

$ curl -fsSL https://gist.github.com/jherdman/5025684/raw/a3ccd4b5308723245706b4ae315845fe951b4473/benchmark.rb | ruby
............................................................[DONE]

Gem                            Time(sec)     Pct %
--------------------------------------------------
@agnellvj
agnellvj / friendly_urls.markdown
Created September 11, 2011 15:52 — forked from jcasimir/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.