Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@leobessa
leobessa / gitchangelog.sh
Created October 18, 2010 15:27
Git changelog
git log --pretty='format:(%cr) - %s %d' | tail -r
git log --pretty='format:%Cblue(%cr) %Cred%s %Cgreen %d %Creset' | tail -r
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
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] }
#!/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
@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
@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)
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)
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
@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 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