My thesis short article

Hey there. I've closed college (finally) and for the last project we had to built an extensive conclusion work and an article on this work.
The full length work is in portuguese, so it's a bit inaccessible to most readers, but I've tried to write the article in english, since it was permitted and it increased the potential reader base.
So here it is. It's about using the Getting Real philosophy as a way to be competitive in an ever increasingly competitive and integrated world. Hope you guys enjoy it, and any grammar mistakes, please point them out, english is not my first language, and mistakes do happen :P

Hugs

Export the database models to YML fixtures

Hi Sirs,

Many tutorials over the web shows how to load data from fixtures. But, if you want to migrate your mysql data to a postgresql database?

We can export our data to fixtures, and after that we can load the fixtures to every database management system we wish.

Let's go to the rake task:

desc "export the database models to YML fixtures"
task(:models_to_fixtures => :environment) do
  ActiveRecord::Base.establish_connection(
    :adapter => 'postgresql', # mysql, sqlite3
    :encoding => 'utf8',
    :database => 'cnxs_development',
    :username => 'username',
    :password => 'secret'
  )
  ActiveRecord::Base.connection

  if ENV['MODELS'].nil? || ENV['MODELS'].blank?
    raise "Please enter valid models names separated by coma. Ex: MODELS=User,Account"
  end

  models = ENV['MODELS'].split(',').collect { |arg| arg.camelize.constantize }

  models.each do |model|
    output = {}
    collection = model.find(:all)
    collection.each do |object|
      output.store(object.to_param, object.attributes)
    end
    file_path = "#{RAILS_ROOT}/tmp/#{model.table_name}.yml" # /tmp/
    File.open(file_path, "w+") { |file| file.write(output.to_yaml) }
  end
end

Here you need to fill your database attributes like you do in the /config/database.yml.

You will call the command line:

$ rake models_to_fixtures MODELS=<your model names separated by coma>

All your model data will be stored on /tmp/ directory.

Download this rake task here.

See you.

Better than grep? You bet!

Well, long time no post here.

I'm going to talk about a tool that changed the way I do search on the programming front.

Since I really don't like grep for common searches (it's a great tool but it's interface is a bit clunky) I used to use the Regexxer for those kind of project searches (it's a great GUI tool, I recommend it to anyone).

But since I'm more of a minimalist command line kind of guy, I was happy as a bonobo when I found ack, a grep like program hat has a interface for human beings (yeah, ubuntu reference, sue me). To give a little example on how simple is to search in a ruby project for example:

cd ~/project/path

ack-grep --ruby string_to_be_searched

And that's it, if you want any more details, the ack home page has a great little tutorial.

Hugs everyone.

Windows in Ubuntu 8.04 with VirtualBox

I have a Windows on my machine, cause for some stuff I still need it, (MS Visio, MindMaps and couple of others application that doesn't run fine with Wine). It's a pain in the ass to always boot machine to access 2 or 3 files and stay 15 minutes on Windows.

A couple of years ago I was a big fan of VMware (old times that I virtualize ubuntu on windows), and I felt a lack of OSS on this area. So the solution it's virtualization, with VirtualBox it all comes easy!

VirtualBox, was recently bought by Sun, has 2 licenses: one commercial and one open source. I use OSE and to install it you have to follow these steps:

$ sudo apt-get install virtualbox-ose virtualbox-ose-modules-generic

Then add your current user on 'vboxusers'  group

$ sudo adduser someuser vboxusers

Go to applications > system tools > VirtualBox

Now create your Windows VM with the almost NNF (next, next,finish) wizard. It's a piece of cake!

RSpec view test for render :partial with :locals?

I was working on some rspec views tests and I've noticed that partial renderization can be tricky.
For example, if we have an index page that renders the objects list in a partial template.
In my case I was testing using a 'GivingClub' list:

describe "giving_clubs" do
  before do
    @giving_clubs = [mock_model(GivingClub)]
    assigns[:giving_clubs] = @giving_clubs
  end

  it "expect render giving clubs list" do
    template.expect_render(:partial => "/giving_clubs/list", :locals => { :giving_clubs => @giving_clubs })
    render "/giving_clubs/index"
  end
end


Do not forget the assigns before call template.expect_render. Locals works fine in this way.

HP Acquired EDS

Well another big player buying other big player. Big acquisitions in the last couple of months! For around $13 billion ($25 per share). HP said that they could double their service revenue. Well seems that market doesn't believe too much in HP since their shares are down on 6% now... 

Source: market watch

Clean Objects with find method

Hi Sirs,
an important trick on the famous ActiveRecord::Base find method.
When you are in development time of your application, and you do some query on your database query editor, is a good practice to use the limit clauses and selects just the columns you want.
In the find method we can do it with the :limit and :select arguments.
For example in our code when we try to authenticate some user we got it like:
find(:first, :conditions => [query, hash], :select => "id, email, login")
The returned object contains just the id, email and login attributes. Clean object.
Password and other attributes do not appears in the returned object =]
Simple development practice, but very important too.
See you.