Contas
March 26, 2008
Há coisas que nunca são demais mostrar. Mesmo que antigas. Sobre o programa novas oportunidades:
- 240 mil licenças de Microsoft Windows Vista Home BasicN Português DVD, 256,57€, resultam em mais de 61 milhões de Euros (61.576.800€)
- 240 mil licenças de Microsoft Office Home and Student 2007 Português OEM, 128,51€, resultam em mais de 30 milhões de Euros (30.842.400€)
Mesmo que existisse a oferta do software, seria um presente envenenado cobrado várias vezes à economia portuguesa no futuro a médio e longo prazo.
Em http://blog.softwarelivre.sapo.pt/2007/06/05/que-casamento-e-este/
Agora as mesmas contas usando uma qualquer distribuição Linux e Open-Office:
240 mil vezes zero = zero euros (linux)
240 mil vezes zero = zero euros (open-office)
total: zero euros
poupança possível do estado: 91 milhões de euros (dos vossos bolsos)
Eu até falei de como os portugueses são tão lorpas que são roubados quando compram estes computadores e nem sequer notam. Mas esqueci-me destes pormenores fantásticos, ainda são mais roubados nos impostos que pagam por causa de promaiores como este. Peço desculpa, é que usar qualquer palavra com menor quando estam envolvidos 91 milhões parece mal.
É de referir que a Microsoft – segundo consta – fez um descontinho. Obrigado Microsoft! ;) Sempre tão simpáticos. Portanto sim provavelmente as verbas são inflacionadas, mas isso é da responsabilidade do autor do artigo e não minha. Eu só fiz as contas – com alguma dificuldade admito – do linux!
[EDIT: Vi neste post o teste de literacia digital das novas oportunidades. Peço que o façam e constatem que são todos uns iliterados porque aposto que poucos vão conseguir acabar a avaliação. E vejam lá que alguns de vocês - como eu! - são engenheiros informáticos. Que vergonha! :(]
DB2 Rocks
March 26, 2008
qs = Question.find_by_sql
"select X.* from ots_schema.questions," +
"XMLTABLE (\'$d/question\' passing document as \"d\" " +
"COLUMNS question_text VARCHAR(200)" +
"PATH \'question_text\') as X"
qs.first.question_text.lstrip => "Which of the following is the correct syntax to set the DB2COMM variable to TCPIP?\n "
If DB2 was had a good DB2 driver and a ActivePureXML (or something adapter) it would so f*ckin rock. Just look at the sample. And the dynamic nature of ruby would enable the flexibility of xml documents.
Please IBM please. DB2 for mac and decent support on Ruby. Don’t make me write things like this no more:
# Once again fixing IBM_DB bugs the ugly way # with_scope anyone? add_index :'ots_schema.users', :login
or
t.column :document, :xml
Google reinvents the wheel
March 24, 2008
About porting Ruby on Rails to Javascript:
In an effort to increase developer productivity at Google, Steve tried to convince the company to adopt Rails (and consequently Ruby) as a programming language. When that fell on deaf ears (Google really does not want to increase the number of languages that must be supported by their infrastructure), Steve decided to do what any other frustrated programmer would do: he ported Rails to JavaScript. Line by line. In 6 months. Working 2000 hours. Steve is a coding stud.
From: Steve Yegge ported Rails to JavaScript
In this six months Steve could have contributed to the rails core and improved the framework to a great extent. If he found security issues like the article refers than he should have fixed them in rails. I cannot even begin to understand why he didn’t by the way. Or at least reported them.
My conclusion of seeing that google allowed a employee to waste 6 months of work because they don’t want to increase the number of languages that must be supported by their infrastructure is that Google is Dumb.
Steve seems like a smart guy so if I was told to rewrite Ruby on Rails by an employer I cannot understand why he didn’t – at the very least – refused to do so and pointed out how stupid it was to reinvent the wheel. I simply hate javascript and love ruby. I think javascript is the worst thing there is in the internet. That’s one of the reasons I decided to take a chance on XForms. Well but that’s a personal opinion and has nothing to do with the case!
The question is:
So will this bring something new to the web?
Yes! But it’s not that this wheel is great and the other was flat. It can bring something but just because Google has the power to do that, in any language they decide to use. They have the man power to go beyond what rails offer.
But does this make the decision less dumb?
No. They could do it in rails and improve a great open source product.
Or is it that hard for engineers at google to learn a new language??
has_one :through
March 24, 2008
Finally we will be able to refactor our ugly code when we have this situation (changeset 9067):
class User < ActiveRecord::Base has_many :channels end
class Channel < ActiveRecord::Base belongs_to :network belongs_to :user end
class Group < ActiveRecord::Base
has_many :channels
has_one :network,
:through => :channels,
:conditions => ['channels.alive? = ?', true]
end
Another good news is that the RubyForge place for the OTS project was finally approved. So guess I will be doing some work on it this afternoon.
links for 2008-03-23
March 23, 2008
-
module ActionView module Helpers module TextHelper module_function :pluralize, :truncate end end end
links for 2008-03-22
March 22, 2008
links for 2008-03-19
March 19, 2008
-
A very good post on ruby. If you haven’t tried Ruby yet just install it and test this.
If you don’t love it by the end of the article… Your mad :X
Valid and Well-formed XML Documents in Ruby on Rails
March 19, 2008
If your working with DB2 on Rails you probably need to check if the xml document is – at least – well formed.
I found a neat plugin called validates-xml that uses REXML to see if documents are well formed.
To install it simply
svn co http://validates-xml.googlecode.com/svn/trunk/ validates-xml-read-only
And copy that folder to vendor/plugins.
You can easily integrate schema validation with a validates_xml_with_schema method. But you should use REXML as it cames with the standard ruby bundle since version 1.8.
To use it simply restart your server and
validates_xml :xmldocument
That’s it!
Yet Another Ruby on Rails Web Application – Teaser
March 18, 2008

links for 2008-03-16
March 16, 2008
links for 2008-03-11
March 11, 2008
Integração entre RSpec & TextMate
March 10, 2008
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
be_kind_of(CouchDB::Server)
end
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://rubyforge.org/var/svn/rspec/trunk/RSpec.tmbundle
- 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.
CouchDB & Um Novo Semestre!
March 7, 2008

Bem todos os semestres faço um plano de acção do que vou fazer para além de o que é espectável de mim – ir as aulas, fazer os trabalhos, passar nos exames e ler pelo menos um livro de informática – de escolha livre – por mês.
Acredito na valorização pessoal e gosto muito de aprender coisas novas. E acredito que não existe melhor forma de o fazer que com projectos práticos!
Algumas das novidades do último semestre foram ter entrado no centro de apoio ao open-source do departamento de informática, ser eleito IBM DB2 Student Ambassador e ter entrado na melhor rede de bloggers de informática de portugal – prt.sc. Como projecto pessoal escolhi aprender – por sugestão do Ulisses Costa – Ruby & Ruby on Rails.
Dito isto resta uma dúvida: O que aprender este semestre?

Tenho que confessar que ando nas nuvens por terem aceite a minha colaboração no projecto CouchDB do rubyforge.
Como devem saber CouchDB é uma base de dados criada pelo Damien Katz (que trabalha agora na IBM), não relacional, desenvolvida em erlang que tem como objectivo guardar documentos e é RESTful. Os conceitos são excelentes e a forma de abordar o fault-tolerance e problemas de carga são daqueles conceitos que nos deixam a babar mortinhos por experimentar o brinquedo novo. Mas não se fica por aqui. Aconselho a lerem a wiki para terem uma noção do que é – e o que não é – o CouchDB. Só não gosto muito do facto de estar tão ligado a javascript e JSON – o primeiro porque nunca gostei muito de javascript e o segundo porque preferia yaml. Mas vá antes JSON que XML!
Outros tópicos que andam por aqui a passear – sendo que aqui é a minha cabeça – é a vontade de aprender um mínimo de Erlang e continuar o estudo de DB2 para tirar a certificação. Espero que quando acabar este semestre possa olhar para trás e sentir a mesma satisfação que sinto pelo semestre que já passou.
links for 2008-03-06
March 6, 2008
O Open-Source é mais barato
March 6, 2008
E ando eu a pagar propinas para isto. Mais um site feito em asp mais um belo not-so-blue-screen.
Eu sei, eu sei. Acontece em qualquer linguagem/framework. Mas a mim – como gajo de peculiar azar – acontece-me sempre com aspx à mistura.
links for 2008-03-05
March 5, 2008
-
Java, Ruby, Perl, Python, Erlang ?
links for 2008-03-04
March 4, 2008
links for 2008-03-03
March 3, 2008
Flores
March 2, 2008
Rails::ActiveRecord XQuery && DB2::Mac
March 1, 2008

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:
Languages
- ID, int
- DOCUMENT, XML
Imagine that the xml file is
<language isoname="pt-PT"> <hello>Olá</hello> <bye>Até a próxima!</bye> </language> (...)
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==?]",
session['language']]
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.





