nunojob:~ dscape/08$ echo The Black Sheep

Posts tagged ‘TextMate’

Integração entre RSpec & TextMate

Como já disse anteriormente ando a trabalhar no CouchDB-Ruby driver. Como a coisa tem o seu nível de exigência decidi usar rspec, algo que já andava para fazer a algum tempo, de forma a melhorar a testagem do software que produzo e reduzir o tempo de implementação. Já agora aproveito para sugerir o ZenTest a quem quiser que o rspec corra em background.

Continuando: rspec é uma forma descritiva – tipo cenários em Use Case – para descrever os nossos testes. Em Ruby claro, dai o R :P

O resultado final fica assim. É catita e prático, já que evita mais uma ida a consola para escrever ‘spec filename.rb’! E é bastante parecida com a linguagem natural. Por exemplo – um dos meus primeiros testes é:

it "should connect to server and return a Server object" do
  CouchDB.connect(HOST, PORT).should 

Não fiz commit de nada porque a implementaçao anterior do CouchDB-Ruby com JSON não está completa. Portanto não vale a pena ir espreitar que não está nada lá! Em breve, espero eu, podem ver os testes completos online.

De qualquer forma se estiverem interessados em experimentar o rspec basta:

  • Instalar o rspec
    sudo gem install rspec
  • Descobrir o path onde está o ruby e o rspec. Estes comandos são capazes de ajudar:
    which ruby
    gem environment
  • Com os meus paths basta correr:
    export TM_RUBY=/usr/bin/ruby
    export TM_RSPEC_HOME=/Library/Ruby/Gems/1.8/gems/rspec-1.1.3
    cd ~/Library/Application\ Support/TextMate/Bundles/
    svn co svn://
  • Como o (meu) terminal não gosta de exports. Caso não funcione façam:
    echo TM_RUBY=/usr/bin/ruby >> ~/.profile
    echo TM_RSPEC_HOME=/Library/Ruby/Gems/1.8/gems/rspec-1.1.3 >> ~/.profile
  • Actualizar os Bundles do TextMate
    Bundles > Bundle Editor > Reload Bundles

E pronto! Caso surjam dúvidas podem sempre consultar a documentação oficial do bundle rspec para TextMate. Que comece a diversão! Bem vá diversão é exagerar mas com rspec é pelo menos uma experiência mais agradável que o habitual quando se fala de testes.


Rails::ActiveRecord XQuery && DB2::Mac

Most rails developers use OS-X. Mostly because rails is built-in the latest release (Leopard) and TextMate offers a great IDE to use with Rails. Some could argue that it also works nicely on Windows but I really believe that Rails ain’t done to be used on a Windows Platform. Many articles and interviews with rails creator DHH second this statement. Rails is easy to develop in OS X and deploy in a Linux distro of your choice.

In my most recent screen-cast I explored an interesting technique of taking advantage of rails RESTful design and DB2 pureXML features to easily create a web-service that could query a relational databases with XML support (like DB2). As you must know DB2 Express-C is distributed freely and offers no limitation to home users/small companies. So it would be awesome to expand ActiveRecord to support xml elements, if a schema was provided to the database.

I’m aware that a pure xml database stategy would be a bad approach but there are situations when it simply makes sense. And in those situations one would profit greatly of two things wich are missing.

  • XML Support for ActiveRecord – in construction?
  • DB2 for Mac – will this ever exist?

Antonio Cangiano is creating a plugin that revolves around this concepts, but in a DB2 centered perspective. In my opinion it would be best if the rails plugin worked not only for DB2 but for any database adapter with XML support – as long as such is provided.

Let me give you a sample. Imagine that you have a database model for translating you rails application. It could be something like:


  • ID, int

Imagine that the xml file is

<language isoname="pt-PT">
  <bye>Até a próxima!</bye>

If this makes sense in your application then you could easily do something like register your model to observe (see observer design pattern) the session[‘language’] for changes and, if it’s changed, it would get all the XML for that language – it would fall back to default if such was not available – and create the hash with the values. The problem with this approach – besides making no sense for the internationalization problem! – is that in the observer model you would have to:

Language.find :first

And fetch the whole xml and then process it. If the XML document has 10MB, it would take some time. With XQuery support on ActiveRecord we could simply

Language.find :first, 
  :xcondition => ["//language[@isoname==?]", 

Or, if we simply wanted to say hello in many languages – like flickr in their first page – we could simply

Language.find :first, :xcondition => '//hello'

There are just two problems that prevent rails developers from being able to do this kind of things. And those are the lack of XQuery abilities in ActiveRecord and the fact that Mac developers cannot use DB2.

Imagem do dia

Atenção: Esta ilustração mostra como limpar as preferências do TextMate. É apenas um devaneio geek, que mostra como se pode complicar até a mais simples das coisas. A próxima versão será em base-64, para piorar ainda mais o cenário. Contudo quero deixar claro que o uso ilícito de software proprietário é crime. Se através deste exemplo descobrirem como se faz e o fizerem estão a vossa própria responsabilidade.

From Ubuntu/Windows to Mac OS-X Leopard

I just got my first brand new MacBook and, as one would expect, some problems emerged by leaving my usual OS combo (Ubuntu/Windows) for Mac OS X Leopard. I’m still undecided whether to install Ubuntu or use VMWare Fusion to use Linux. As for Microsoft Windows as long as I don’t need to use .NET I don’t think I’ll install it. Not even with the free licenses Microsoft provides University of Minho students.

First I had to decide what to install:

The question you are probably asking is why Firefox instead of Safari!? Because the damn unsafe add-on for is just that:! I just can’t live without it. Maybe if the guys over there worked the basics of security we could say that it’s both excellent and safe! And don’t say there’s a add-on for Safari as well. I’ll only accept it if the add-on is as good as the one provided by Yahoo.

Now we go for the fun part. The problems and solving them. Your attention please, this is only fun for me when I do it on my computer so it won’t be pleasure if you ask me to fix your computer! Joana this one is for you, I know how your mind thinks.. Almost as badly as mine. Oh well, we are related aren’t we? :\ Please release those crazy Christmas photos to the world! :X

I’ll start with a small OS free tip and then go for the Q/A part. If you are Portuguese like myself you just hate all the results that google gives you from .br domains. Most of the results are overrated and most of the times you just wish that they weren’t there. If this is the case just do your normal search in google but write -br in the end. Just test this, go to google and type governo brasileiro -br. It works ;)

  1. How do I get my mouse to behave like a normal one by removing this dreadful acceleration?

    Easy. Check Rúben’s blog @

  2. What’s wrong with the encoding on TextEdit? The automatic descovery does not work and even when I specifically tell him to use this encoding it won’t work. The Where is ISO 8859-15 dilemma.

    Still don’t know. Anyone? If you want to test the bug just do this (from here):

    $ echo é > ~/a.txt
    $ cat ~/a.txt
    Open a.txt with TextEdit and get:

    Cracked it! At least I have a partial fix for Migrating documents from Ubuntu to Mac OS X Leopard:

    cmd + space terminal enter

    {go to the directory where the file is}

    bash$ iconv -f ISO-8859-15 -t UTF-8 {filename} > UTF8-{filename}

    For me it was:

    bash$ iconv -f ISO-8859-15 -t UTF-8 Pam.tex > UTF8-Pam.tex

    And yes PAM is as in Pluggable Authentication Modules. So I have a latex work on that :P

  3. Where is type-a-name application? It’s not on the dock.

    Just press cmd + space and type what you are looking for. This is called spotlight. Either this or open Finder and go to applications.

  4. Why doesn’t it show my dashboard when I go to the left/whatever corner?

    Have you even configured your mac? Common.. Click the apple on the top left corner and go to System Preferences. Exposé and Spaces. And now that you are there take a look around and configure all the other things that you neglected.

  5. This computer is always underlining the words in red. (when the spelling is right :P If not you are a dumbass for asking this!)

    Just press cmd + mouse and change the language. Thanks Nuno Veloso from Apple Tech Team for this tip.

  6. How can I see the right mouse button menu?

    crtl + mouseclick

  7. PageUp/PageDown!?

    fn+ up
    fn + down

If after this you still feel like reading about Mac OS for rookies – like myself – you can check this section in Arun Gupta’s Blog or check this extensive list of Keyboard Shortcuts. Have fun!

Now let’s get back to work, something almost impossible when your doing a report on LaTeX and the encodings are never right.

One final touch: ctrl + alt + cmd + 8. Merry Christmas! :)