Skip to content

Instantly share code, notes, and snippets.

View rinaldifonseca's full-sized avatar

Rinaldi Fonseca rinaldifonseca

View GitHub Profile
@rinaldifonseca
rinaldifonseca / gist:1781970
Created February 9, 2012 18:49 — forked from jittuu/gist:792715
Test Omniauth Facebook Callback Controllers in Devise with rspec
require 'spec_helper'
describe Users::OauthCallbacksController, "handle facebook authentication callback" do
describe "#annonymous user" do
context "when facebook email doesn't exist in the system" do
before(:each) do
stub_env_for_omniauth
get :facebook
@rinaldifonseca
rinaldifonseca / config.ru
Created March 2, 2012 14:03
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
require "rails"
@rinaldifonseca
rinaldifonseca / gist:1974802
Created March 4, 2012 21:12 — forked from wisq/gist:1507733
Why I love zsh (and hate being forced to use bash)

Why I love zsh (and hate being forced to use bash)

  • Smarter completion:
  • cd tab completion -- directories only
  • bash can do this, but needs the bash-completion package, usually comes separately
  • zsh always comes with completions, why doesn't bash?
  • Filename correction during completion
  • if dir1/x exists and dir2 exists, then "dir/x<TAB>" completes to dir1/x
  • if name1 is a file and name2 is a directory with files in it, "name/<TAB>" completes to "name2/"
@rinaldifonseca
rinaldifonseca / resque.rake
Created March 7, 2012 21:27 — forked from denmarkin/resque.rake
My rake task for clearing Resque queues and stats
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."
@rinaldifonseca
rinaldifonseca / gist:2232387
Created March 29, 2012 01:52 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

@rinaldifonseca
rinaldifonseca / osx_homebrew_rvm_rails_unixodbc_sqlserver.md
Created April 3, 2012 02:06 — forked from sixfeetover/osx_homebrew_rvm_rails_unixodbc_sqlserver.md
Setup OS X 10.6.4 w/ homebrew, rvm, rails, unixodbc, freetds and SQL Server

Setup new mac from scratch

These commands are good as of 2010-11-18.

ruby -e "$(curl -fsS http://gist.github.com/raw/323731/install_homebrew.rb)"

Install xcode (download, or on the OS X install DVD)

http://developer.apple.com/technology/xcode.html
@rinaldifonseca
rinaldifonseca / s.rb
Created April 11, 2012 02:17 — forked from jacksonwillis/s.rb
Sentences as Ruby code
class S;def initialize *w;@s=w;end;def method_missing *w;@s<<w;self ###########
end;def to_ary;[@s.map{|e|e=~/[\,\.\:\-\(\)\/\'\"]/?[e]:[" ",e]}.join.strip] ##
end;end;def Object.const_missing(c);S.new c;end ####### gist.github.com/2354740
puts This.is.a.sentence.represented.by.a.Ruby.expression(".") #################
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
@rinaldifonseca
rinaldifonseca / multi-threaded-http-client-rails.rb
Created April 28, 2012 13:57 — forked from arp/multi-threaded-http-client-rails.rb
Multi-threaded HTTP requests that help utilize multiple CPU cores in Rails by requerying the app itself
# This way we re-query the app itself in order to avoid sequential execution for CPU-intensive tasks
# that can (and should) be executed in parallel.
#
# Pros: decent scalability can be achieved by assigning path=some.load.balancer.com (i.e. Amazon ELB)
# and putting a bunch of multicore machines behind it.
#
# Cons: we lose some fraction of time on JSON encoding/decoding and HTTP traffic.
# Load-balanced fault-tolerant DRb could be a better choice, but would require more work and provide only
# minor performance improvement in situation where JSON/HTTP aren't the main CPU consumers.
@rinaldifonseca
rinaldifonseca / links.textile
Created May 27, 2012 20:45 — forked from lucashungaro/links.textile
Links de referência utilizados em minha palestra