Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@leobessa
leobessa / spec_helper.rb
Created October 20, 2011 06:44
How to define example group run order in RSpec 2
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
module ChurnLogger
# include Loggable
alias info puts
alias error puts
def perform_with_log(*args)
info 'starting new payments importing'
perform_without_log(*args)
rescue => exception
error exception.to_s
@leobessa
leobessa / brew_install.sh
Created June 5, 2011 21:40
Brew install on a virgin macbook
brew install mongo yuicompressor git git-flow git-extras git-multipush git-utils gist libxml2 libiconv imagemagick wget
module RaiseExit
def raise(msg_or_exc, msg=msg_or_exc, trace=caller)
warn msg.to_s
exit!
end
end
class Object
include RaiseExit
end
require 'fiber'
class Bot
def initialize(color)
@position = 1
@color = color
@fiber = Fiber.new do |buttons|
while next_button = buttons.find{ |c,p| c == @color }
if buttons.first == [@color,@position] && !$pushed
push_button(@position)
@leobessa
leobessa / ruby_19_encoding_fix.rb
Created March 15, 2011 00:47
Fixes for ruby 1.9 encoding issues
# encoding: utf-8
module ActionView
module Renderable #:nodoc:
private
def compile!(render_symbol, local_assigns)
locals_code = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
source = <<-end_src
def #{render_symbol}(local_assigns)
@leobessa
leobessa / rvm_iconv_provisioner.rb
Created March 3, 2011 19:55
Problem: no such file to load -- iconv
#Using RVM and Ruby 1.9.2 and getting the error: “no such file to load — iconv”
rvm package install readline
rvm package install iconv
rvm remove 1.9.2
rvm install —trace 1.9.2 -C —with-iconv-dir=$HOME/.rvm/usr
#Check it works with irb: require ‘iconv’ should return true
#!/usr/bin/env rspec
require "spec_helper"
describe "The library itself" do
def check_for_tab_characters(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
failing_lines << number + 1 if line =~ /\t/
end
True = lambda { |a,b| a }
False = lambda { |a,b| b }
display = lambda { |boolean| boolean['true','false']}
display[True] # => "true"
display[False] # => "false"
And = lambda{ |b1,b2| b1[b2,b1] }
Or = lambda{ |b1,b2| b1[b1,b2] }
module SQLGrowler
class Subscriber < ActiveRecord::LogSubscriber
def sql(event)
super
g = Growl.new("localhost", "ruby-growl", ["ruby-growl Notification"], ["ruby-growl Notification"], nil)
g.notify('ruby-growl Notification',application_name,'%s (%.1fms) %s' % [event.payload[:name], event.duration, event.payload[:sql].squeeze(' ')],1,true)
end
def application_name