Skip to content

Instantly share code, notes, and snippets.

@raul
raul / configuration.rb
Created April 7, 2011 10:51
exercise from Charity Tutorial at Scottish Ruby Conf: configuration DSL
class AppServerConfiguration
attr_accessor :port, :admin_password
end
class Configuration
attr_accessor :tail_logs, :max_connections, :admin_password
def initialize(block)
block.call(self)
shared_context 'user' do
before :all do
@user = User.create( :name => "Bob", :password => "foo", :admin => false )
end
def login
visit( url( :login ) )
fill_in :name, :with => "Bob"
fill_in :password, :with => "foo"
click_button "Login"
@javier
javier / jazzfonica.rb
Created June 14, 2011 11:29 — forked from ace/jazzfonica.rb
jazzfonica
#!/usr/bin/env ruby
# jazzfonica.rb for Mac OS X
# Scans the visible networks for JAZZTEL_XXXX or WLAN_XXXX and calculates the password
# Ported from PHP example at http://kz.ath.cx/wlan/codigo.txt
# Download and execute with ruby (e.g. ruby jazzfonica.rb) from a Terminal
#ported to ubuntu from https://gist.github.com/1024587
#it will ask for sudo privileges.
#if your wlan card is not "wlan0" change the "my_wifi_card" variable
@guillermo
guillermo / download_song.rb
Created August 3, 2011 20:04
Little script to download and convet music
#!/usr/bin/env ruby
=begin
README
======
Download any youtube video, in the original format ogg without
loosing quality, and also convert a mp3 from the ogg.
You have to decide if the mp3 quality is enough for you. Or you
can adjust the parameters of the conversion if you need the mp3

Running exactly two test files

With just ruby:

$ ruby -Ilib:test -e'require "test1"; require "test2"'

Via your rake task:

$ rake TEST=test/test[1,2].rb
@karmi
karmi / tire_http_clients_benchmark.rb
Created September 8, 2011 18:15
Benchmark Tire gem with RestClient and Curb HTTP Clients
#
# A basic, synthetic benchmark of the impact HTTP client has
# on the speed of talking to ElasticSearch in the Tire gem.
#
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does.
#
# Run me with:
# $ git clone git://github.com/karmi/tire.git
# $ cd tire
@mislav
mislav / _readme.rb
Created September 23, 2011 21:09
Browser history with Capybara: implementing "go_back"
# Usage (works only with default Rack::Test driver):
page.go_back
@mattpodwysocki
mattpodwysocki / jsconf-eu-2011.md
Created October 1, 2011 13:40
JSConf.EU Slides
@raul
raul / retry_upto.rb
Created October 7, 2011 06:42
retry_upto.rb
# Ruby `retry` with steroids:
#
# - retry up to 5 times without waiting between them and retrying after any exception
#
# retry_upto(5) do ... end
#
# - retry up to 5 times, waiting 2 seconds between retries
#
# retry_upto(5, :wait => 2) do ... end
#
# This allows to use a numeric or a lambda
def retry_upto(max_retries = 1, options = {})
begin
return yield if ((max_retries -= 1) > 0)
rescue (options[:rescue_only] || Exception)
if options[:patience]
if options[:patience].is_a?(Numeric)
options[:wait] = options[:wait] * options[:patience]
else