Skip to content

Instantly share code, notes, and snippets.

View chamnap's full-sized avatar

Chamnap Chhorn chamnap

View GitHub Profile
@Burgestrand
Burgestrand / download-progress.rb
Created June 27, 2010 13:55
Ruby HTTP file download with progress measurement
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|
# 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 July 22, 2010 15:58
Rake taks to launch multiple Resque workers in development/production with simple management included
# 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.
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
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 November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# 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 December 4, 2010 00:45
Inspecting Phusion Passenger's status and killing frozen apps
#!/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 June 26, 2011 02:37
Capistrano with Foreman Capfile
# 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 July 30, 2011 13:16
Capistrano task to open a rails console on a remote server. Require this file in your deploy.rb and run "cap rails:console"
# 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 September 1, 2011 23:36 — forked from travis/gist:1084767
testing facebook connect with capybara and rspec
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)