Posted on May 20, 2008 at 3:44 pm

Globalize versus PDF-Writer, round one!

If you ever needed to generate PDFs dinamically on a Rails app, one of the easiest (and possibly more elegant) PDF generation Rails options you’ll find is using the PDF-Writer combo. The good thing with that combo is that you can go and define your PDFs as views using a different extension (.rpdf is suggested). [...]

Posted on March 28, 2008 at 3:59 pm

Geolocate yourself with Graticule

Graticule is an interesting piece of Gem that puts together a bunch of geocoding services available over the Internets in one concise and easy to use package. Using it is a snap:

require ‘graticule’

coder = Graticule.service(:yahoo).new “api_key”
locale = coder.locate “New York, NY 10003″
=> #<Graticule::Location:0×2c1dc14 @latitude=40.73236, @precision=:city, @locality=”Manhattan”, @country=”US”, @postal_code=”10003″, @longitude=-73.989089, @warning=”The exact location could not be [...]

Posted on March 24, 2008 at 3:28 pm

Ruby Haiku

A very clever usage of Ruby’s “almost natural” language style!

question = !!(:to_be or not :to_be)

- Shakespeare.rb
More Haikus on the reddit comments page

Posted on March 17, 2008 at 5:53 pm

Ruby on Rails and the newbie phenomenon

It’s hard to find good C++ developers. Being such a relatively hard language to start with, it’s even hard to find lousy C++ developers, sometimes. It’s interesting to notice that such curve clearly changes as programming languages get ‘easier’ to grasp: cleaner syntaxes, garbage collection facilities, less build/link/compile/deploy steps, more openly available libraries - the [...]

Posted on September 17, 2007 at 5:00 pm

Relative Roots in Rails

One thing I noticed on each and every single PHP application out there is that they all resort in some kind of global variable defined in an include file to determine what is the application’s root. Something like:

$root = ‘http://www.bla.com/my_site’

and then all the links are generated like:

$root.’/something’

That makes all the urls absolute, and pretty much [...]

Posted on September 14, 2007 at 6:30 pm

Mister Percent Saves the Day

Ruby has some very funny syntax, when it comes to execute some supposedly simple operations.
Once upon a time, I had the seemingly simple task of representing an hexadecimal string in binary format. As a seasoned Java dev, I soon began looking for some toBinaryString, or formatted_str, or whatever. I even considered implementing some hex2binary in [...]

Posted on August 30, 2007 at 9:09 am

Improving Ruby

So, after some experience with Ruby’s dirty syntax, I finally feel confident enough to propose some deep changes to it. I hope Mr. Matz reads this blog, so he can incorporate some of my ideas on Ruby 2.0!
1 - elsunless
I love unless. It’s very neat, and although it’s a lot more typing than [...]

Posted on August 26, 2007 at 10:21 pm

Singletons no Rails

Se você já precisou alguma vez utilizar objetos singleton em seu projeto Rails, você deve ter percebido que os Singletons não são exatamente… Singletons. Suponha que você crie a seguinte classe em seu diretório /app/model:

class MySillySingleton
include Singleton
end

SEMPRE que um novo request for feito, uma nova instância da classe será retornada:

puts MySillySingleton.instance
=> #

E no [...]

Posted on August 4, 2007 at 3:53 pm

yahoo-finance: uma RubyGem minimalista para download de dados financeiros do Yahoo! Finance

O yahoo-finance é o meu primeiro RubyGem publicado: trata-se de uma ferramentinha muito, muito simples, que foi desenvolvida enquanto montava o site CanalFinancas para download de preços de ações em tempo real. Depois de tudo pronto, por que não tornar essa belezinha pública? E cá está ela!
O uso é simples:

gem install yahoo-finance

E a partir daí:

require [...]

Posted on August 4, 2007 at 11:49 am

yahoo-finance: A minimalistic Ruby Gem for Yahoo! Finance market data

yahoo-finance is my first published RubyGem: it’s a very very simple tool I used while developing CanalFinancas to retrieve real-time prices of Brazilian stocks. So after having it done, why not making it public?
Usage is dead simple:

gem install yahoo-finance

And then:

require ‘yahoo_finance’

quotes = Yahoo::Finance.quotes(["VALE5.SA"], [:last_trade_price_only, :trade_date])
puts “#{quotes[0].symbol}: #{quotes[0].last_trade_price_only} on #{quotes[0].trade_date}”

Couldn’t be possibly easier…