Entries from June 2008 ↓

Off-Topic: Sobre o hino e a bandeira do Brasil

Bandeira do BrasilInterrompemos a nossa programação para a publicação de um aviso de utilidade pública:

Quarta-feira fiz algo que não fazia há anos: Assisti a um jogo do Brasil. E o que me surpreende até hoje, mesmo sabendo que sempre acontece (e que provavelmente sempre acontecerá) é o fato da galera no estádio aplaudir o hino nacional. Já discuti bastante com “os mais velhos”, dizendo que não se deve aplaudir o hino, o que até me rendeu fama de não-patriota!

Então vamos lá, o link para o site do planalto é esse, mas o resumo está aqui:

Art . 24. A execução do Hino Nacional obedecerá às seguintes prescrições:

§ 4º Nas cerimônias em que se tenha de executar um Hino Nacional Estrangeiro, este deve, por cortesia, preceder o Hino Nacional Brasileiro.

Art . 30. Nas cerimônias de hasteamento ou arriamento, nas ocasiões em que a Bandeira se apresentar em marcha ou cortejo, assim como durante a execução do Hino Nacional, todos devem tomar atitude de respeito, de pé e em silêncio, o civis do sexo masculino com a cabeça descoberta e os militares em continência, segundo os regulamentos das respectivas corporações.

Parágrafo único. É vedada qualquer outra forma de saudação.

A página fala ainda mais um monte de coisa que eu acho que podem ser violadas, pelo fato de ser um jogo, todo mundo estar animado e tudo mais. Mas o que eu quero frisar está aí, em negrito. Não custa nada se levantar, tirar o boné|chapéu|toca, e não aplaudir. E não é feio nem “pagação de pau” executar o hino do outro país antes. Feio é perder o jogo.

Obrigado à todos pela atenção, e agora voltamos com a nossa programação normal.

Permalinks no Wordpress e mod_rewrite

Ontem à noite (na verdade quase hoje de manhã) eu terminei de subir os posts e comentários do blog. Daí quando eu tentei ativar os permalinks do WordPress eu tive uma surpresa: Comecei a tomar 404s na cara toda vez que clicava em qualquer permalink.

Eu não podia ficar sem eles, já que eram utilizados desde a encarnação Mephisto. Assim as URLs ficam parecidas e menos links por aí quebrariam. Daí, depois de pesquisar um pouquinho no google vi que o .htaccess precisava de algumas regras e o WordPress não conseguia escrever nele. Ok, touch mais chmod no .htaccess no diretório raiz do blog e… nada!

Com mais buscas, vi que todo mundo fala que o mod_rewrite deve estar habilitado, mas que ninguém fala como! Olhando no site do apache, vi que ele vem instalado por default.

Mais um pouco de fuçadas e, do nada, lembrei que assim como os sites os mods também se dividem entre available e enabled. Um simples ls em /etc/apache2/mods-enabled/ mostrou que o rewrite.load não estava lá. a2enmod rewrite, sudo /etc/init.d/apache2 reload e voilá!

Moral da história: VPS é legal, você tem uma máquina pra usar do jeito que bem entender, mas qualquer coisa que fuja do padrão é por tua conta.

Rise from your grave!

Na terça eu tentei entrar no blog, mas ele saiu do ar. Tentei de tudo, mas voltei pro trabalho na quarta, e o tempo ficou curto pra mim. Após tentar de tudo um pouco, fiz backup da base que o Mephisto usava e formatei o meu vps. Acabei de configurar o Apache e instalei o Wordpress.

Ainda vou subir os posts antigos, e daí ver algum tema bonito pro blog.

Desculpem o inconveniente, se tiver alguém lendo isso aqui fora o Wilerson.

The Brainfuck Quest

One of my study resources for learning new languages is SPOJ. Actually, I’ve used it only to learn Ruby so far, but I’ll use it for any one to come (Python?, LISP?).

Although SPOJ international has a much bigger user base and challenge level, I’m giving more attention to SPOJ Brazil, and BRAIN, one of its problems, is giving me much more headache then it should do.

I decided to give it another try, but the code was big enough for me to try to fix it. But this time I will make it different by adding unit tests.

The old testing process

The testing process consisted of running the tests given in the problem site. But my code pass them and still fails in the tests given when the code is submitted.

The new testing process

I put some unit tests (thanks for embedding unit tests, Matz) to test individual commands of my interpreter, and I found the first problem with it. The # command was printing the first ten bytes of the input, instead of the first ten bytes of the vector. The tests given in the problem site didn’t cover this case.

Then I added tests for the four basic math operations. The divide test is quite good, since the loop nesting stack is something that goes seven levels up in the stack!

My code just blowed up when I tried to run it. After some search, I found nothing. After a lot of more searching, I found a little bug: When the interpreter read the ] command, it wasn’t appending the following code in the right order. The other tests didn’t find this error because the loops were quite simple, with just one nested loop.

Then again I tried to upload it, but it failed once more. Now, I let it there for a couple of days, and then, I found another problems with the whole nesting system. Now I have to say that what saved my life was a piece of paper and a pen. I drawn the whole nesting process, making arrows for variables names and arrays, and it all became clear to me. After a little brainstorming (and more drawing), I re-wrote it all and all my tests passed!

I was already screaming bad words when I realized it had to pass SPOJs tests too, and then it all came to ruins when I got a TLE in my face. The problem has a 1 second time limit. The problem became performance.

Profiling

I really, really thought about re-writing everything in C and upload it just to prove my algorithm works. I decided to give Ruby’s profiler a try, by running the code with the -r profile option.

The results

At the beginning I thought the Range#each method was the cause of my problems, but it isn’t because all relevant code runs inside one of them. I thought about whining about the language too, but for sure, the problem is with my algorithm.

Now I have a apparently functional brainfuck interpreter who does not run fast enough for SPOJs tests. The source is here. I don’t want to give up on it. My plans were to post it when it passes, but I just can’t see any solution in the near future, and I don’t want to abandon the blog either.

I’ll make more posts anytime this issue evolves. Or not.

@Railsconf \’08: Phusion Passenger

Between other things, the Phusion folks just announced Passenger now has rack and Django support. And Ruby Enterprise Edition is just announced too.

By the way, some of the licensees (me included) were asked to go up on the stage and received applauses. Awesome.

As soon as Kenji stops making fun of me and hand me the picture, I’ll upload it here.