Skip to content

Instantly share code, notes, and snippets.

@weppos
weppos / capistrano_passenger_deploy.rb
Created July 29, 2008 14:59
Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# = Capistrano Passenger deploy tasks
#
# Provides tasks for deploying a Rails application with Passenger (aka mod_rails).
#
# Category:: Capistrano
# Package:: Passenger
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2008 The Authors
# License:: MIT License
# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
class Fixnum
hydra = Typhoeus::Hydra.new(3)
@responses = []
start_time = Time.now
request = Typhoeus::Request.new(:method => :get, :host => "localhost:3000", :path => "/first", :query_string => "delay=1")
request.when_complete do
@responses << request.response
YAML.load(request.response.body)[:path_info].should == "/first"
require 'rubygems'
require 'typhoeus'
require 'yajl/json_gem'
hydra = Typhoeus::Hydra.new
request = Typhoeus::Request.new('http://localhost:8089/?id=timeline', :method => :post, :body => stuff.to_json)
request.on_complete do |response|
response.code # http status
response.body
response.time # time taken in seconds
@EmmanuelOga
EmmanuelOga / r191.txt
Created December 26, 2009 22:42
curb, typhoeus, net:http, em-http quick benchmark
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
curb (0.6.2.1)
em-http-request (0.2.5)
eventmachine (0.12.10)
typhoeus (0.1.13)
user system total real Memory (Kb)
4kb std
0.000000 0.000000 3.010000 ( 22.408594) 24,484
@thinkerbot
thinkerbot / Gemfile
Created January 14, 2010 17:58
A bundler+gemspec setup for managing dependencies
#############################################################################
# Dependencies in this Gemfile are managed through the gemspec. Add/remove
# depenencies there, rather than editing this file ex:
#
# Gem::Specification.new do |s|
# ...
# s.add_dependency("sinatra")
# s.add_development_dependency("rack-test")
# end
#
@3dd13
3dd13 / batch_concurrent_requests_by_typhoeus.rb
Created April 22, 2010 09:00
example of using Typhoeus
def main
# urls is a hash containing url to retrieve statuses of items
get_csv(urls, items) { |response, item|
item_results = CSV.parse_line(response.body)
item.setStatus(item_results[0])
}
end
def process_response(urls, items)
@mborromeo
mborromeo / env.rb
Created May 14, 2010 23:03
My (working) mongoid + cucumber env.rb
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
# Set @@variable_name in a before(:all) block and give access to it
# via let(:variable_name)
#
# Example:
# describe Transaction do
# set(:transaction) { Factory(:transaction) }
#
# it "should be in progress" do
# transaction.state.should == 'in_progress'
# end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')