Sistema de cotas, mentiras e covardia

Olá, gostaria de discutir uma questão que é muito relevante para os brasileiros em geral. O sistema de cotas que acaba de ser aprovado na câmara. Aqui tem um bom texto para saber mais sobre o assunto.

A questão real é de eficiência da solução. Cotas, ao meu ver, serviriam mais para prejudicar o mercado alvo (índios, negros, excluídos sociais, etc), pois retiraria pressão do governo em providenciar aquilo que é responsável, um ensino médio de qualidade, compromissado com o aprendizado técnico, social e crítico da população, sem distinções.

Cotas em suma, não contribuiriam em nada para o alívio da dívida moral (que existe e realmente precisa ser paga), econômica e política que a sociedade brasileira e mundial tem com suas parcelas mais fracas e historicamente exploradas, e sim contribuiriam para os políticos terem desculpas, ao apontar para a "realização" da "justiça" com as cotas, sendo que nada realmente justo foi realizado, e a solução verdadeira que só viria com sacrifício e mudança real é empurrada para as próximas gerações realizarem.

Ou seja, é a solução de covardes que se escondem atrás de um escudo de mentiras politicamente corretas.

How to get better error messages for an associated model.
Hey there. Let's assume you have some set like this
class User < ActiveRecord::Base
  has_one :profile , :dependent => :destroy
end


class Profile < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :first_name, :last_name
end

And you create the profile in the same view as your user. How do you validate those first_name and last_name fields with a friendly message for your user?
Well, you could use validates_associated, but you would end up with a message like "Profile is invalid". Now, how friendly is that?

To obtain a more precise message, use this on you user.rb

def validate
  if self.profile
    self.profile.errors.each do |error|
      self.errors.add_to_base error.join(' ')
    end
  end
end
Security idea for banking cards

I'm a brazilian, and on our big cities we have a type of crime known as flash kidnap ("sequestro relâmpago" in portuguese), which is a crime that consists in one kidnapper taking a hostage and cruising around with him (probably on the hostage's own car) and forcing the victim to release his banking account numbers so money can be drawn from his banking account.

This type of crime is basically a problem that was induced by the introduction of a technology (bank credit cards). But this technology could be made safer by the introduction of an emergency number. This number would work just as the normal one, so there is plausible deniability for the victim, so money could be drawn and all, but if ever used it would raise alarms on the credit central, and the authorities could be immediately called. Since close to 100% of the ATM machines have cameras around them, and there is the location of the drawn, it would be easy to check where criminals are.

For example:

Bob uses a banking card and has 2 passwords (pass A and pass B). Bob uses pass A on his day-to-day, without a hassle. Some day Eve kidnaps Bob, and forces him do release his card and a password. Bob releases pass B. Eve uses Bob's card with pass B without a problem, but doing so warns Alice that there is an emergency happening with Bob (possibly a kidnap). Alice warns the authorities.

I'm not interested in making money at all with this idea, but I would like to see it implemented, so it perhaps could save some property and lifes, so I'm asking for some directions as to what the heck I should do with it, and also some criticism.

This idea is registered under CC Attribution-Noncommercial 2.5 Brazil

Startup school 2008

Quick link to some valuable resource...

Startup school 2008!

Ahhh, we here at cnxs are busy learning some new exciting technology, so keep you heads up for some fresh new content soon....

Difference between is_a? and instance_of?

Hi Sirs.

There is a difference between a bunch of methods that appear that they to the same job, but they won't.

The methods instance_of?, is_a? and kind_of? do related jobs, but not the same job.

For example is_a? and kind_of? do the same job, they return true if the caller is an instance of the method argument, if the caller is an instance of every superclass in his inheritance tree or if the argument method is a module included in the caller.

The instance_of? is more specific, it returns true just if the caller is an instance of the method argument.

Let me show some examples:

module Hand
end

class Animal
end

class Mamal < Animal
  include Hand
end

class Dog < Mamal
end

dog = Dog.new

puts dog.instance_of?(Dog)    # true
puts dog.instance_of?(Mamal)  # false
puts dog.instance_of?(Animal) # false
puts dog.instance_of?(Hand)   # false

puts dog.is_a?(Dog)    # true
puts dog.is_a?(Mamal)  # true
puts dog.is_a?(Animal) # true
puts dog.is_a?(Hand)   # true 

Remember that is_a? and kind_of? do the same job.

See you.

Rails Summit Latin America 2008 - Review Day 2

Second Day of Rails Summit, started hot. Phusion guys talked about Scaling Applications, what are the problems, bottlenecks, solutions, how's the possibilities to face it. Was very good and entertaining, specially when Darth Vader come into it. Slides were good with funny animations.

After that comes Charles Nutter e Thomas Enebo talkin on JRuby and because the technical problems during the virtual presentation, left an impression that could be better. They gave an overview of the status of JRuby, how it runs on hotspot, and also presented some (strange) numbers of memory usage in JRuby comparing to MRI.

Jay Fields talking was about testing and some testing frameworks. Well in general was a good presentation but for him almost all solutions are imature, which I disagree and when he was questioned on what makes a framework mature, he said time, years...

David Chelimsky did 2 great talkings one about RSpec and the other about Cucumber, much more for newbies (with all respect to newbies it's just a stage). I liked a lot because he seem to be very confident on his arguments, this is a thing that I appreciate on speakers.

David Chelimsky and CNXS Team

The others between Chelimsky's and Obie I didn't payed too much attention so I'll skip my review on them.

Obie Fernandez closed the event with a great keynote, telling about how his software consultancy deals with the agile manifesto. It's great to hear that you apply the techniques that he says that's a key of success of his company. He presented a full stack of the way his company develop software, since the first contact to the client.

Rafael Souza and Obie Fernandez

Rails Summit for me was a great event, that I've met good mates from the brazilian and latin america Rails community. I will be waiting for the next one on 2009!

Carlos Brando, Fábio Akita and CNXS Team

Diff entre respond_to? e respond_to

Um pequeno tutorial em português pra diferenciar melhor respond_to? e respond_to. Não parece ter muita não? Mas o tio Chuck Norris vai me ajudar a esclarecer melhor isso aqui.

respond_to? é um método do Ruby Core como você pode ver, e não do Ruby On Rails, ele basicamente verifica se determinado objeto responde a um método, como o nome sugere mesmo.

Por exemplo:

class Chuck < Object
  def norris
    puts "the man"
  end
end
chuck_norris = Chuck.new
p chuck_norris.respond_to?("norris") # true
p chuck_norris.respond_to?("mr_t") # false

Já o respond_to, sem o ponto de interrogação (eles fazem parte do nome do método) faz parte do ActionController do Ruby On Rails. Ele coloca suporte a Web Service na sua aplicação, isso quer dizer que ele consegue resolver o tipo do recurso que você deseja.

respond_to do |format|
  format.html # render por default nome_da_acao.html.erb
  format.js # render o nome_da_acao.rjs
  format.xml { render :xml => @chuck.to_xml } # coloca o chuck pra xml e envia
end

Com esse código na action você poderia usar, por exemplo:

http://localhost:3000/nome_da_acao.html
http://localhost:3000/nome_da_acao.xml

Ou realizar uma chamada JS unobstrusive usando AJAX.

Isso ai, espero ter ajudado.