Skip to content

Instantly share code, notes, and snippets.

# 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
@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
#
@mattpodwysocki
mattpodwysocki / jsconf-eu-2011.md
Created October 1, 2011 13:40
JSConf.EU Slides
@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
@cowboy
cowboy / ba-backbone-module.js
Created September 9, 2011 18:05
Idea for a Backbone module system (allowing modules to be accessed across multiple files, possibly loaded out of order). Inspired by https://gist.github.com/1202511
/*!
* Backbone Module Manager - v0.1pre - 9/9/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
function ModuleManager(fn) {
@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

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
@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
@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
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"