Skip to content

Instantly share code, notes, and snippets.

View alainravet's full-sized avatar

Alain Ravet alainravet

  • Braine l'Alleud, Belgium
View GitHub Profile
@alainravet
alainravet / print_stacktrace.rb
Created January 24, 2009 21:12
How to print the stacktrace in Ruby
# How to print the stacktrace from anywhere :
# 1°
#------------------------------------------------------------------------------
module Kernel
def print_stacktrace
raise
rescue
puts $!.backtrace[1..-1].join("\n")
end
@alainravet
alainravet / gist:79077
Created March 14, 2009 14:11
benchmark your ruby tests
# modified version of http://github.com/gittobi/tobi_test_timer
# differences :
# - prints all the tests
# - adds a counter and a bargraph
#
# output :
#. 336 2222222 : 2.584 - test_create_an_image_with_some_participations_in_one_go(ImageAdvancedTest)
#. 337 ++ : 0.173 - test cleanup_user_picture_path() does not translate proper upload
#. 338 ++ : 0.135 - test cleanup_user_picture_path() translates tmp upload path(ImagePathRepairTest)
#. 339 : 0.005 - test shorten_image_url() clears 1 level(ImagePathRepairTest)
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
@alainravet
alainravet / smtp_tls.rb
Created July 20, 2009 17:46
lib/smtp_tls.rb
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
check_auth_args user, secret, authtype if user or secret
@alainravet
alainravet / .autotest
Created August 4, 2009 18:43
~/autotest config file
#autotest configuration
#
require 'redgreen/autotest'
require 'autotest/timestamp'
# ####################
# GROWL CONFIG
# ####################
require 'rubygems'
require 'parallel' #http://github.com/grosser/parallel
$stdout.sync = true # Auto-flush for interactive I/O
def slow_action
def fibo(n)
0 == n ? 0 :
1 == n ? 1 :
@alainravet
alainravet / setup_once.rb
Created November 30, 2009 18:33
test-unit setup_once/teardown_once
# Usage :
# --------
# require 'setup_once'
# class MyTest < Test::Unit::TestCase
# include SetupOnce
#
# def self.setup_once
# puts "doing one-time setup"
# end
#
@alainravet
alainravet / .bash_profile
Created March 21, 2010 20:41 — forked from bcardarella/.bash_profile
git completion
source ~/.git-completion.sh
alias gco='git co'
alias gci='git ci'
alias grb='git rb'
# with Daemons, extract the params. for the daemonized process
#
# Input :
# ["run", "--", "--source=/tmp/sour", "--archive=/tmp/arch"]
# ^ ^^^^^^^^^ ^^^^^^^^^
# | :source :archive
# the separator
#
# Output :
# {:source=>"/tmp/sour", :archive=>"/tmp/arch"}
@alainravet
alainravet / bug_or_pending_test_case.rb
Created May 5, 2010 21:22
add pending tests to TestCAse
require 'test_helper'
module ActiveSupport
class TestCase < Test::Unit::TestCase
# Correct Usage :
# def test_ok_pending_1
# pending "feature 1 should do this ..."
# end