Skip to content

Instantly share code, notes, and snippets.

View fred's full-sized avatar

Frederico Araujo fred

  • Thailand
View GitHub Profile
louisgillies / paperclip_migration.rake
Created October 26, 2010 11:36
Quick and dirty one off migration task for paperclip plugin to move files from local filesystem to Amazon S3.
# First configure your models to use Amazon s3 as storage option and setup the associated S3 config.
# Then add the classes your want to migrate in the klasses array below.
# Then run rake paperclip_migration:migrate_to_s3
# Should work but this is untested and may need some tweaking - but it did the job for me.
namespace :paperclip_migration do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
klasses = [:model_1, :model_2] # Replace with your real model names. If anyone wants to this could be picked up from args or from configuration.
klasses.each do |klass_key|
expired: 'expirou, por favor solicite um novo'
not_found: 'não encontrado'
already_confirmed: 'já foi confirmado, por favor tente fazer login'
not_locked: 'não estava bloqueado'
one: "1 erro impediu que %{resource} fosse salvo:"
other: "%{count} erros impediram que %{resource} fosse salvo:"
grantr / gist:1105416
Created July 25, 2011 22:31
Chef mysql master/slave recipes
## mysql::master
ruby_block "store_mysql_master_status" do
block do
node.set[:mysql][:master] = true
m ="localhost", "root", node[:mysql][:server_root_password])
m.query("show master status") do |row|
row.each_hash do |h|
node.set[:mysql][:master_file] = h['File']
node.set[:mysql][:master_position] = h['Position']
fnando / gist:2420869
Created April 19, 2012 13:10
My JavaScript Guidelines
skamithi / application_controller.rb
Created April 25, 2012 14:53
Adding Opensearch to my Rails 3.2 app
class ApplicationController < ActionController::Base
def opensearch
response.headers['Content-Type'] = 'application/opensearchdescription+xml; charset=utf-8'
dblock / mongoid_criteria.rb
Created May 24, 2012 19:38
Mongoid::Criteria each_by iterator
module Mongoid
class Criteria
def each_by(by, &block)
idx = 0
total = 0
set_limit = options[:limit]
while ((results = ordered_clone.limit(by).skip(idx)) && results.any?)
results.each do |result|
return self if set_limit and set_limit >= total
pithyless / char_converter.rb
Created September 5, 2012 16:00
Rails middleware to encode characters and avoid exploding controllers
# config/initializers/char_converter.rb
require 'uri'
module Support
class CharConverter
"HTTP_COOKIE", # bad cookie encodings kill rack:
ndbroadbent / deploy.rake
Created September 28, 2012 22:18
Rake task for precompiling assets locally before deploying to Heroku
require 'fileutils'
# Warning: The following deploy task will completely overwrite whatever is currently deployed to Heroku.
# The deploy branch is rebased onto master, so the push needs to be forced.
desc "Deploy app to Heroku after precompiling assets"
task :deploy do
deploy_branch = 'heroku'
remote = 'heroku'
deploy_repo_dir = "tmp/heroku_deploy"
vigo /
Last active July 20, 2016 02:32
Bash completion for bundle
if [[ ! `which bundle` ]]; then
local cur prev commands
commands="help install update package exec config check list show outdated console open viz init gem platform"
fred / clockwork_celluloid.rb
Created June 28, 2013 17:16
Running clockwork inside a Sidekiq Thread using Celluloid
### Rails.root/lib/scheduler.rb
require 'celluloid/autostart'
module AwesomeRailsApp
class ClockworkScheduler
include Celluloid
include Clockwork
def run