Skip to content

Instantly share code, notes, and snippets.

View fred's full-sized avatar

Frederico Araujo fred

  • Thailand
View GitHub Profile
@fred
fred / paperclip_migration.rake
Created November 3, 2011 16:58 — forked from louisgillies/paperclip_migration.rake
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|
@fred
fred / daily_update_diaspora.sh
Created January 8, 2012 14:55
Script to update Diaspora as a cron job. Install as a daily cron.
#!/bin/bash
# Assuming that Diaspora is deployed to $HOME/diaspora/master
HOME_FOLDER="/home/diaspora"
cd $HOME_FOLDER/diaspora/master
source "${HOME_FOLDER}/.rvm/environments/ruby-1.9.3-p0@diaspora"
rvm use "ruby-1.9.3-p0@diaspora"
# RUBY GC HEAP
@fred
fred / sunspot_resque.rb
Created April 22, 2012 07:58 — forked from nz/sunspot_resque.rb
Sunspot with Resque
# app/models/post.rb
class Post
searchable :auto_index => false, :auto_remove => false do
text :title
text :body
end
after_commit :resque_solr_update
@fred
fred / application_controller.rb
Created April 29, 2012 07:20 — forked from skamithi/application_controller.rb
Adding Opensearch to my Rails 3.2 app
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def opensearch
response.headers['Content-Type'] = 'application/opensearchdescription+xml; charset=utf-8'
end
@fred
fred / active_admin.rb
Created May 2, 2012 08:10
extend active admin to prettier boolean values
# It extends activeadmin to show pretty boolean values
#
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class TableFor
def bool_column(attribute)
column(attribute){ |model| model[attribute] ? '&#x2714;'.html_safe : '&#x2717;'.html_safe }
end
## mysql::master
ruby_block "store_mysql_master_status" do
block do
node.set[:mysql][:master] = true
m = Mysql.new("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']
end
@fred
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
@fred
fred / gist:6017861
Created July 17, 2013 05:13
bundle install -j8 on jRuby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM 1.7.0_25-b30 [linux-amd64]
[ubuntu@solr jruby-1.7.4 (master)] ~/rails $ bundle install -j8
Updating git://github.com/FernandoEscher/sql_funk.git
Fetching from: http://rubygems.org/api/v1/dependencies
HTTP Success
Fetching source index from http://rubygems.org/
Resolving dependencies.......................................................Fetching from: http://rubygems.org/quick/Marshal.4.8/pg-0.15.1-x86-mingw32.gemspec.rz
HTTP Redirection
Fetching from: http://production.cf.rubygems.org/quick/Marshal.4.8/pg-0.15.1-x86-mingw32.gemspec.rz
HTTP Success
........................................................................................................................................................................................................Fetching from: http://rubygems.org/quick/Marshal.4.8/foreman-0.63.0-mingw32.gemspec.rz
@fred
fred / .gitconfig
Created August 11, 2013 15:19
my nice .gitconfig, to put on your home directory
[color]
branch = auto
diff = auto
status = auto
interactive = auto
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
@fred
fred / gist:6248817
Created August 16, 2013 10:28
ruby script to clone/copy Iron IO cache (using celluloid pool)
require 'celluloid'
class IronQueueWorker
include Celluloid
def initialize
@token = "your-token"
@old_project_id = "source-project-id"
@new_project_id = "source-project-id"
@old_iron_cache = IronCache::Client.new(token: @token, project_id: @old_project_id)
@new_iron_cache = IronCache::Client.new(token: @token, project_id: @new_project_id)