Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@leobessa
leobessa / worker.rb
Last active August 29, 2015 14:01
sidekiq dynamodb parallel scan
module Sidekiq
module Apns
class Worker
include Sidekiq::Worker
sidekiq_options :queue => :apns_dts
def perform(*args)
# p args
end
end
end
@leobessa
leobessa / Gemfile
Created July 20, 2012 20:56
Heroku Cedar static file server with rack
source :rubygems
gem "rack", "~> 1.4"
gem "rack-rewrite", "~> 1.2.1"
gem "thin"
@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