I’m a Mac (again)

Almost three years ago my boss sent me an iBook G4 to work with. It was an absolutely awesome machine: fast, great battery life, beautiful hardware, beautiful OS. I loved it, but after 1,5 years using it some problems arise.

First, the battery just died - it just worked when connected to the charger. Second, I work(ed) with Zope and Plone on a daily basis, and things like running the entire gocept.zeoraid test suite took about 40 minutes. Even PloneTestCase with some functional tests was painfully slow. A Macbook was too expensive for me at that time, but I needed a new laptop.

Linux

Before using that iBook I used Linux for almost 4 years, so I brought an inexpensive laptop to run Linux. The laptop has an Intel Core 2 Duo 1.66GHz, 2 GB of RAM and 120 GB of disk space - a reasonably good machine, except for the video and the wireless card. It took me almost 6 hours to install Ubuntu on that laptop (which came with Satux Linux installed by default) and much, much more time to get everything right.

I was reasonably happy with that setup, but every now and then I needed to fix something in the OS. One day I decided to buy a second monitor, and so I did it. Big mistake.

Windows

It seems that the SiS Mirage 3 video card is a Windows fanboy and I couldn’t get the new monitor to work with Linux. It worked out of the box with an Asus eeePC running eeeBuntu, but not on my laptop. Damn it. After that and some other minor annoyances I decided to give Windows Vista a try, following some advice from Sidnei.

Windows Vista surprised me. It’s a good OS, every piece of hardware on my machine worked without “serious” configuration. As I can’t live without a Unix I installed andLinux, but it was not enough: using Linux to manipulate a NTFS filesystem is a PITA.

Mac OS X - Again

After so much trouble I realized I was losing time with all these annoyances; then I saved money, did some freelance work on my spare time and voilà: last week I brought a white Macbook.

I can’t tell you how much I’m happy with it. It took me less than 1 hour to download and install every application that I need - well, almost all of them, since XCode is really big and the download took almost 2 hours itself.

One good surprise is XCode / iPhone Simulator. XCode is a very good IDE and it’s been a lot of fun to learn Objective-C and how to develop iPhone applications.

If you need to buy some tool (be it hardware or software), buy the best tool your money can buy. Some programmers hesitate to spend some money on a good chair, on a good editor or on a good computer (like me, before all this) but damn, we spend 8-12 hours a day using these things! Every single thing that can save you time or give you more comfort is worth it.

I have a profile on iUseThis that shows the apps that I have on my Mac. If you have any recomendations please leave a comment!

Usando Emacs

gnu-and-penguin-color-300x276Desde que comecei a programar eu pulei de editor para editor (sempre usando com mais frequência o VIm), mas nunca parei para me aprofundar de verdade no uso de nenhum deles. Alguns meses atrás eu decidi me dedicar a resolver esse problema e desde então tenho usado diariamente o Emacs.

Por que o Emacs? Pelo mesmo motivo que me levou a aprender Zope e Plone: tem muita gente realmente boa usando o Emacs, o que significa que algo de bom ele tem. Além disso o Emacs é multiplataforma, o que é importante pra mim, já que pretendo voltar a usar Mac OS X em breve.

Logo que voltei a estudar o Emacs eu assisti o screencast Meet Emacs, do PeepCode.com (altamente recomendado, aliás), o que me ajudou muito. O screencast apresenta os principais comandos, major / minor modes, color modes, eshell, ido-mode, textmate.el, vc-mode (para controle de versão), magit (para usar git) e vários outros recursos interessantes.

A coisa mais útil do screencast, na verdade, foi apresentar o Emacs Starter Kit. O ESK é um diretório de configuração para o Emacs (.emacs.d) cheio de major e minor modes muitos úteis e vários defaults melhorados. Vale a pena testar.

No github existe uma grande variedade de forks do Emacs Starter Kit; eu mesmo mantenho meu .emacs.d como um fork desse projeto. O meu fork adiciona algumas coisas interessantes como o yasnippet (com snippets variados para Python, Ruby e outras linguagens) e o whitespace.el (muito útil pra programar em Python).

O Emacs é muito flexível. Abrir diversos buffers lado a lado, fazer commits, verificar sintaxe, fazer diffs e funções como a jump-to-symbol do ido-mode sem dúvida me proporcionaram uma maior produtividade. O contraponto disso é que é fácil ficar “perdendo tempo” personalizando o .emacs.d e brincando com elisp :-).

No geral estou bastante satisfeito com a minha escolha de editor. Pretendo me aprofundar mais e assim melhorar minha produtividade - afinal de contas um dos requisitos para entrar no estado de “flow” é usar bem e intuitivamente as ferramentas que mais usamos.

No meu delicious tem alguns links interessantes sobre Emacs: http://delicious.com/dirceu/emacs.

Why you should switch to Git

Over the last few months I’ve switched from Subversion and Bazaar to Git. I’m using Git on a daily basis now and I’m much happier with it than I was when using Subversion. In this post I’ll try to explain why and provide some useful links.

You can work offline

How cool is that? You can clone a repository (which is similar to doing a “checkout”), go offline and then change what you want, commit, merge, branch and whatever. When you go back online you can push your commits to the origin server - if you want.

When using Git you don’t work on a “working copy” of the last revision (as you do with Subversion) - using “git clone URL” you clone the *entire repository*: all commits, merges, branches, everything.

It’s fast as hell

Git is fast. Really fast. Doing commits, branches, merging and even cloning a remote repository: everything is (way) faster than Subversion. I didn’t do any benchmarks on my own, but it’s what I can see.

It will make you want to try new things

Branching and merging in Git are trivial tasks. In Subversion these operations are kind of troublesome; you need to interact with the remote copy, merging is not so easy and you need write access to the remote repository. This - the need of write access - is actually the main problem with it.

With Git I can clone a remote repository, create branches, try things out and never ever send anything back to the origin repository. I can do pretty much everything without getting permission, without bureaucracy.

Github

Github - Social Code Hosting

Github is a really cool social network for programmers. It allows you to share and manage Git repositories in a very easy way; with a few clicks one person can fork, say, httparty, branch, merge and do whatever with it.

Also it allows you to make “pull requests” (a way to poke someone and let them know you’ve got some code they may want) and  get your code on the main repository.

Some useful links about Git

So this is why I’m using Git. The following links are tutorials and explanations about how and why Git works and more reasons to use it. Enjoy.

Creating RSS feeds with rssifier

Two of my favorite webcomics doesn’t have official feeds - Malvados and The Order of The Stick (this one actually *have* a feed, but the images aren’t shown in the feed items). I didn’t like to visit these sites manually, so I quickly wrote a script (which is now a very simple Ruby lib) to create these feeds for me: rssifier.

The lib code is ugly at some points, but it’s working for me. Here is an example script (malvados.rb) that uses rssifier to create a feed:

(Link of the Gist).

And this is the result; I have a cronjob calling the malvados.rb periodically, so this XML gets updated from time to time.

Any contributions via github are obviously welcome :-).

Quick Tip: Testing Django send_mail

I’ve been working on a Django project lately and I had the need to send some emails from my application. I was trying to figure out how to write a mocked version of django.core.mail.send_mail when I read about django.core.mail.outbox, which apparently is a new feature of Django 1.0.

django.core.mail.outbox is a list of all instances of emails sent with django.core.mail.send_mail that is available only in the testing framework. With it you can do things like these:


(Link of the Gist)

Browsers gone wild!

Dois lançamentos recentes estão deixando o povo que ‘mexe com web’ agitado: o Mozilla Ubiquity e o Google Chrome.

Ubiquity

O Ubiquity é um ‘Quicksilver-do-Firefox’, uma ferramenta que permite que usuários manipulem diversas ferramentas web usando uma interface de texto simples. Por exemplo, clicando Ctrl+Space (para abrir a interface de comando) e digitando ‘map criciuma,brazil’ verá um google map mostrando a cidade onde eu moro. Essa é uma *excelente* ferramenta para agilizar o uso de diversas ferramentas da web - além do google maps do exemplo acima, na versão 0.1 do Ubiquity já existem comandos para fazer buscas na Amazon, no Flickr, definir termos, fazer cálculos e fazer muitas outras coisas.

Uma das coisas que eu mais achei interessante é a facilidade de manipular conteúdo; você pode, por exemplo, selecionar um texto qualquer em uma página, abrir o ubiquity e digitar ‘email this to fulano’ - isso irá abrir uma tela do gmail já com um email parcialmente preenchido para o ‘fulano’ (que deve estar nos seus contatos).

Chrome

O Chrome é o novo browser do google. É um browser que usa o engine Webkit para renderizar as páginas e um novo engine javascript (o v8), bem mais rápido que o dos browsers atuais. O Chrome foi pensado na web atual, não na web de tempos atrás: a web atual é uma plataforma de aplicações. GMail, GDocs, Basecamp, Twitter, Github, GReader, GCalendar, Facebook… parando pra pensar, eu praticamente não entro mais em ’sites’ - mesmo os blogs que leio são sempre via RSS.

O Chrome foi desenhado pensando nessa ‘nova web’: entre outras coisas, cada aba é um processo. Isso faz com que esse navegador seja mais seguro (uma aba não consegue acessar os dados das outras), mais rápido (uma aba lenta não afeta as outras) e trave menos (se uma aba travar, é só ela que vai travar). A interface é minimalista: a idéia é que o navegador seja ‘invisível’, que o usuário só preste atenção no conteúdo que está acessando.

Mas como assim p*rra? O Google e a Mozilla não tinham um ‘caso’?

Pois é. Como bem disse o Sidnei, o Chrome tem tudo pra ‘roubar’ usuários do Firefox. De qualquer forma, a bagaça é open source - se a Mozilla quiser pode ‘deitar e rolar’ com o código do Chrome - inclusive pode aproveitar e começar a usar a engine javascript do novo browser, que é bem mais rápida que a do Firefox.

Qro nstala n Linx comofas/

Perdeu, preibói. Por enquanto o Ubiquity só roda em Windows e Mac OS X, enquanto o Chrome só em Windows.

E vejam que beleza: migrei do OS X de volta pra Linux há menos de uma semana. O jeito é usar o VirtualBox.

*sigh*

Usando o git-svn

Nos últimos dias venho trabalhando em uma app Django e, como sou iniciante no uso desse framework, todos os dias aprendo algum feature novo para melhorar meu código (como generic views, por exemplo). Para testar esses features o ideal é criar um branch, usar os features no código e, se valer a pena, fazer o merge. O problema: usamos svn na empresa, e fazer branches no svn é bem chatinho (principalmente se comparado ao git). Para resolver isso estou usando o git-svn.

Segue abaixo meu fluxo de trabalho no git-svn:

Link do Gist, para quem não consegue ver no feed.

Enfim, esse é um post pra que eu mesmo não esqueça como fazer isso. Alguns links e tutoriais interessantes sobre o git e o git-svn estão no meu del.icio.us: http://delicious.com/dirceu/git.

GSoC Summary

As the Google Summer of Code coding period comes to an end, I must write about what I have done, so here we go. My proposed tasks were:

  1. Invalidation processing optimization: test if ZEORaid is processing validations from the backend storages too often. This should be proven and maybe optimized.
  2. Allow defining/removing new backend storages while running using the client tool or reloading the config.
  3. Define a transaction rate limit / recovery ration to ensure that recovery can always be faster than new transactions that are flowing in.
  4. Currently requests to multiple backends are run in sequence. This should be done in parallel, to speed up.
  5. Single requests to backends should be distributed (randomly or round robin) over the available backends.
  6. Implement `off-site` backends which are written to as a kind of secondary backend which don’t have to respond to write requests synchronously to allow replication over slow links to a different site.

Task 1

The first two weeks were used on this task and on getting myself familiar with gocept.zeoraid codebase. As I said in my first report, I didn’t found anything wrong with the invalidation proccess when doing my tests, so I moved to another task.

Task 5

This was a reasonably easy one. My main problem was getting an automated test to prove the implementation. It’s hard to test a distributed system, and doing the setup is a little problematic; anyway, with help from my mentor, Christian Theune, I got a working test. My work is on this branch.

Task 4

This one was tricky. I had no “real world” experience on writing threads, so I stepped into many obvious bugs - joining threads, dealing with exception handling and such things. I’ve spent almost four weeks working on this task, but in the end I got it right. My work is on this branch.

Task 3

I started researching a bit about this task, but Christian said that task 2 was much more important, so I stopped working on it.

Task 2

My final task over the GSoC period. I started by writing a “add” command to the ZEORaid command-line tool, as I described in this report. It was easy to get this working for ClientStorage objects, but I needed to get it working with other types of storages too; some time later Christian said that it was only a “helper” for me to understand better the way that ZEORaid handles storages and openers.

I dropped this implementation and started working on reloading the entire config file. I got it working in a couple of days, but spent *much* more time than that working on an automated test for it. My work is on this branch.

GSoC Report - Week 12

Quick report: this week I’ve finished the ‘reloading’ task - now with automated tests, thanks to the help of Christian, my mentor. Now I need to document my branches and write a post about what I’ve done on the coding period. I need to do this on this weekend, because next monday is ‘pencils down’ date, when all mentors must submit a final evaluation of the work done by their students.

GSoC report - week 11

I’ve nearly finished the ‘reloading’ task described in my last report; now we’re able to reload the config file without modifications. The code is quite simple: we open and parse the config file, using the list of storages defined there to see what storages needs to be removed (and then we disable them) and what storages needs to be added (and then we add and ‘recover’ them). I’m now working on a automated test to prove the implementation is right.

Published on August 9, 2008.