Skip to content

Instantly share code, notes, and snippets.


Chamnap Chhorn chamnap

View GitHub Profile
Burgestrand / download-progress.rb
Created Jun 27, 2010
Ruby HTTP file download with progress measurement
View download-progress.rb
require 'net/http'
require 'uri'
def download(url) do
thread = Thread.current
body = thread[:body] = []
url = URI.parse url, url.port).request_get(url.path) do |response|
View shared_connection.rb
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
karmi / workers.rake
Created Jul 22, 2010
Rake taks to launch multiple Resque workers in development/production with simple management included
View workers.rake
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
View JSON Testing
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"password_confirmation\":\"12345678\", \"password\":\"12345678\", \"email\":\"\"}}" \
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"remember_me\":\"0\", \"password\":\"12345678\", \"email\":\"\"}}" \
View activerecord-3-skip_callbacks.rb
require 'active_support/basic_object'
ActiveRecord::Base.class_eval do
class WithoutCallbacks < ActiveSupport::BasicObject
def initialize(target, types)
@target = target
@types = types
def respond_to?(method, include_private = false)
dnagir / rspec-syntax-cheat-sheet.rb
Created Nov 5, 2010
RSpec 2 syntax cheat sheet by example
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
aermolaev / kill-frozen-passenger-instances
Created Dec 4, 2010
Inspecting Phusion Passenger's status and killing frozen apps
View kill-frozen-passenger-instances
#!/usr/bin/ruby -w
# for passenger 3.0
# cron
# */15 * * * * root /root/bin/kill-frozen-passenger-instances
require 'rubygems'
require 'net/http'
require 'uri'
mrrooijen / deploy.rb
Created Jun 26, 2011
Capistrano with Foreman Capfile
View deploy.rb
# encoding: utf-8
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :application, "hirefireapp"
set :repository, ""
set :branch, "develop"
set :rvm_ruby_string, "1.9.2"
benedikt / rails.rb
Created Jul 30, 2011
Capistrano task to open a rails console on a remote server. Require this file in your deploy.rb and run "cap rails:console"
View rails.rb
# encoding: UTF-8
Capistrano::Configuration.instance(:must_exist).load do
namespace :rails do
desc "Open the rails console on one of the remote servers"
task :console, :roles => :app do
hostname = find_servers_for_task(current_task).first
exec "ssh -l #{user} #{hostname} -t 'source ~/.profile && #{current_path}/script/rails c #{rails_env}'"
yuki24 / gist:1187574
Created Sep 1, 2011 — forked from travis/gist:1084767
testing facebook connect with capybara and rspec
View gist:1187574
require 'mogli'
module FacebookIntegrationHelpers
shared_context "with unconnected facebook user" do
let(:fb_user) { create_test_user(installed: false) }
after { fb_user.destroy }
def app_client, AppConfig.facebook.app_id)