Skip to content

Instantly share code, notes, and snippets.

View rinaldifonseca's full-sized avatar

Rinaldi Fonseca rinaldifonseca

View GitHub Profile

Using ActiveSupport::Dependencies outside of rails seems just as fast as doing manual requires. I've found this out by replacing hundreds of requires in a unit tested code base with ActiveSupport::Dependencies without any change to the time it takes to run the test suite.

Using ActiveSupport::Dependencies also allows you to have circular depedencies like class Foo::Bar in foo/bar.rb and class Foo in foo.rb that points to Foo::Bar in it's class definition (like in a rails validation).

The classical way of solving this without ActiveSupport::Dependencies is to do:

# foo/bar.rb
class Foo
 class Bar
require './interface'
puts to_strings(->(limit) {
->(lst) {
->(f) {
->(f) {
->(g) {
->(n) {
f.(g.(g)).(n)
}
}.(->(g) {

Install Postgresql on Mountain Lion

Based on: http://coderwall.com/p/1mni7w

brew install postgresql
initdb /usr/local/var/postgres -E utf8
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'machinist/active_record'
require 'machinist/caching/active_record'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
spec_support = Rails.root.join("spec/support/**/*.rb")
source :rubygems
gem 'sinatra'
@rinaldifonseca
rinaldifonseca / Gemfile
Created November 21, 2012 22:19
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
class CardData
def initialize(node)
@card_data = node
end
def name
@card_data.search("name").text
end
def image
c = XmlImport.new("path", CockatriceXmlParser).process!
c.each { |card_attributes| Card.create!(card_attributes, :without_protection => true) }
def transfere(to, valor)
to.link("transfer").post(:valor => valor)
end
def processa_pagamento(pessoa, aulas, consultorias, opensource, bank)
parcelas = []
total = 0
aulas.each do |a|
aula.verify do |v|
@rinaldifonseca
rinaldifonseca / dijkstras_dci.rb
Created September 2, 2012 18:53 — forked from MitinPavel/dijkstras_dci.rb
Dijkstra's algorithm in DCI -- Example in Ruby
#!/usr/bin/env ruby
#
######################################################################################################################################
# Taken here http://fulloo.info/Examples/RubyExamples/Dijkstra/DijkstraListing.html and carefully corrected to be more ruby idiomatic.
######################################################################################################################################
#
# Example in Ruby -- Dijkstra's algorithm in DCI
# Modified and simplified for a Manhattan geometry with 8 roles
#
#