This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DefaultValues | |
def has_default_values(default_values = {}) | |
cattr_accessor :default_values | |
self.default_values = default_values | |
after_initialize :assign_default_values | |
include InstanceMethods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
require 'database_cleaner' | |
connection_info = YAML.load_file("config/database.yml")["test"] | |
ActiveRecord::Base.establish_connection(connection_info) | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------- | |
# Library code: | |
class BasicServiceObject | |
attr_reader :object | |
def initialize(o) | |
@object = o | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def RPN(*data) | |
stack = [] | |
data.each do |el| | |
case el | |
when :+, :-, :*, :/, :&, :|, :<< # 1,2,3,:*,:+ == 1 + 2 $ 3 | |
a, b = stack.pop(2) | |
stack.push a.send(el.to_sym, b) | |
when Class # 3,Float == Float(3) | |
stack.push send(el.name, stack.pop) | |
when Symbol # '1+2',:eval == eval('1+2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to print the stacktrace from anywhere : | |
# 1° | |
#------------------------------------------------------------------------------ | |
module Kernel | |
def print_stacktrace | |
raise | |
rescue | |
puts $!.backtrace[1..-1].join("\n") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#autotest configuration | |
# | |
require 'redgreen/autotest' | |
require 'autotest/timestamp' | |
# #################### | |
# GROWL CONFIG | |
# #################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : |
OlderNewer