Skip to content

Instantly share code, notes, and snippets.

Avatar

Chamnap Chhorn chamnap

View GitHub Profile
@Burgestrand
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)
Thread.new do
thread = Thread.current
body = thread[:body] = []
url = URI.parse url
Net::HTTP.new(url.host, 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
end
end
@karmi
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
SIGN UP
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"password_confirmation\":\"12345678\", \"password\":\"12345678\", \"email\":\"test5@test.com\"}}" \
http://your_server.com/users
SIGN IN
curl -H "Content-Type:application/json" -H "Accept:application/json" \
-d "{\"user\":{\"remember_me\":\"0\", \"password\":\"12345678\", \"email\":\"test5@test.com\"}}" \
http://your_server.com/users/sign_in
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
end
def respond_to?(method, include_private = false)
@dnagir
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 http://ApproachE.com
# 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
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
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, "git@codeplane.com:meskyanichi/myapp.git"
set :branch, "develop"
set :rvm_ruby_string, "1.9.2"
@benedikt
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}'"
end
end
@yuki24
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 }
end
def app_client
Mogli::AppClient.new(AppConfig.facebook.access_token, AppConfig.facebook.app_id)