<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Carlan+Calazans &#187; aprendizado</title>
	<atom:link href="http://carlancalazans.com/tag/aprendizado/feed/" rel="self" type="application/rss+xml" />
	<link>http://carlancalazans.com</link>
	<description>{ Às vezes eu sonho com códigos }</description>
	<lastBuildDate>Thu, 22 Apr 2010 03:20:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rapidinha: instalando o MicroXP no VirtualBox</title>
		<link>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/</link>
		<comments>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 00:19:32 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=288</guid>
		<description><![CDATA[Resolvi escrever (ou tirar do draft) sobre algo que faz parte do meu dia-a-dia no trabalho, ou seja, lidar com máquinas virtuais. A pouco tempo atrás quando se falava em máquina virtual o que me vinha na mente era o aplicativo VMWare. De lá pra cá, eu só tinha lido sobre o assunto e feito somente [...]]]></description>
			<content:encoded><![CDATA[<p>Resolvi escrever (ou tirar do draft) sobre algo que faz parte do meu dia-a-dia no <a href="http://www.highlan.com.br">trabalho</a>, ou seja, lidar com <a href="http://en.wikipedia.org/wiki/Virtual_machine">máquinas virtuais</a>. A pouco tempo atrás quando se falava em máquina virtual o que me vinha na mente era o aplicativo <a href="http://www.vmware.com">VMWare</a>. De lá pra cá, eu só tinha lido sobre o assunto e feito somente 01 único teste. Até por que o VMWare é pago.</p>
<p>Pesquisando sobre o assunto e procurando uma solução livre, um ex-chefe me sugeriu dar uma olhada no <a href="http://www.virtualbox.org">VirtualBox</a>. Sem dúvidas ele me pareceu bem melhor do que o <a href="http://www.qemu.org">Qemu</a>, por exemplo. Não que este último seja ruim, mas uma das facilidades que eu precisava era acesso a rede e a configuração da interface do hospedeiro não era nada simples. Por outro lado, no VirtualBox, através da documentação encontrei as informações que precisava e tudo funcionou corretamente. Comecei a gostar desse aplicativo.</p>
<p>No início do ano passado a <a href="http://www.sun.com">Sun</a> comprou a <a href="http://www.virtualbox.org/wiki/innotek">Innotek</a>, empresa que criou o VirtualBox. O aplicativo melhorou muito desde que a Sun assumiu. As atualizações ficaram mais frequêntes, a configuração de rede se faz com dois cliques do mouse, a documentação ficou mais clara e objetiva, dentre outras coisas.</p>
<p>Abaixo se encontra o vídeo de instalação, veja como o processo é simples <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="mvcontainer"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
<p><script src="https://media.dreamhost.com/mp4/swfobject.js" type="text/javascript"></script> <script type="text/javascript">// <![CDATA[
var s1 = new SWFObject("https://media.dreamhost.com/mp4/player.swf","ply","470","320","9","#FFFFFF");
s1.addParam("allowfullscreen","true");
s1.addParam("allowscriptaccess","always");
s1.addParam('wmode','opaque');
s1.addVariable('bufferlength','10');
s1.addVariable("file","http://files.carlancalazans.com/videos/microxp.mov");
s1.write("mvcontainer");
// ]]&gt;</script><br />
<a href="http://files.carlancalazans.com/videos/microxp.mov">Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://files.carlancalazans.com/videos/microxp.mov" length="170352813" type="video/quicktime" />
		</item>
		<item>
		<title>Trapaceando no Monkey Kick Off</title>
		<link>http://carlancalazans.com/trapaceando-no-monkey-kick-off/</link>
		<comments>http://carlancalazans.com/trapaceando-no-monkey-kick-off/#comments</comments>
		<pubDate>Mon, 11 May 2009 23:30:23 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=222</guid>
		<description><![CDATA[Monkey Kick Off é um game em desenvolvido em flash pela Totebo Interactive. O objetivo do game é ajudar um macaco a chutar a bola o mais longe possível ou pelo menos até a vila dos macacos a 4000 metros de distância. Para chutar a bola basta clicar com o botão esquerdo do mouse ou [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.totebo.com/monkey-kick-off.php">Monkey Kick Off</a> é um game em desenvolvido em flash pela <a href="http://www.totebo.com">Totebo Interactive</a>. O objetivo do game é ajudar um macaco a chutar a bola o mais longe possível ou pelo menos até a vila dos macacos a 4000 metros de distância. Para chutar a bola basta clicar com o botão esquerdo do mouse ou pressionar qualquer tecla no teclado. </p>
<div id="attachment_236" class="wp-caption aligncenter" style="width: 410px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/picture-1.png" alt="Monkey Kick Off" title="Monkey Kick Off" width="400" height="300" class="size-full wp-image-236" /><p class="wp-caption-text">Monkey Kick Off</p></div>
<p>Simples, não? A quem diga que até um macaco consegue <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Análise do problema</h4>
<p>É necessário um pouco de tempo até perceber que existem algumas variantes para conseguir chutar a bola a uma certa distância. Primeiro, há um momento, randômico, em que o macaco consegue levantar a bola até a altura máxima. Outra variante importante é o momento do chute. É preciso entender que existe um momento certo para se dar o chute. Este ponto fica entre a altura da cabeça e barriga do macaco.</p>
<p>Como a altura máxima da bola é randômico, esperar pelo momento certo pode levar muito tempo. O mesmo vale para a hora do chute, mas este é menos complicado, pois, pode ser calculado medindo o tempo gasto para a bola chegar no momento do chute.</p>
<p>Há outros fatores que também devem ser levados em consideração quando estamos jogando. As cores do game prejudicam a visão, se ficarmos olhando durante muito tempo os marcadores (os coqueiros ou a placa indicando que a vila dos macacos fica a 4000m) no plano de fundo começam a desaparecer. Se ficarmos muito tempo olhando para a tela, a visão pode ficar cansada e embaralhada.</p>
<h4>A solução (ou a trapaça)</h4>
<p>Depois de analisar o problema cheguei a conclusão que o meu computador pode fazer todo o trabalho por mim. Cheater, preguiçoso, eu? <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Resolvi criar um bot afim de monitorar o game, mais precisamente a minha tela, processar as variantes e chutar a bola. Seria mais ou menos assim, acesso a página do game e inicio o jogo. Logo após, inicio o bot em um console, lembrando de minimizar todas as janelas menos o navegador e posso ir tomar um café enquanto o aplicativo fica rodando.</p>
<p>Como mencionado acima, não existe um tempo correto para a bola chegar no ponto mais alto. É possível abordar este problema de várias formas que vão desde análise de imagens (screenshots) a redes neurais. A técnica mais simples é a análise de imagens e é nela que vou implementar o bot.</p>
<p>Para registro, estou utilizando a resolução de 1024 x 768 em dois monitores de 17&#8243;. Independente da resolução o bot poderá ser criado. Já fiz todo o processo que vou explicar a seguir em um macbook e tudo funciona normalmente. Para isso é necessário seguir alguns passos que listo no próximo parágrafo.</p>
<p>Para começar, é preciso mapear a altura máxima que a bola pode chegar, leia-se distância entre o topo e a esquerda, em relação a sua área de trabalho. Em seguida, recorte a imagem da bola de acordo com o passo anterior, pois, ela gira em seu eixo. Estes são os passos necessários para calibração do bot.</p>
<p>As etapas anteriores são um tanto quanto chatas, mas as que vem a seguir serão bem mais interessantes. Com a imagem da bola podemos compará-la com o screenshot que vamos tirar do ponto mapeado. E por último, se as imagens forem iguais, aguardamos o momento do chute e chutamos.</p>
<p>É claro que podem haver várias maneiras de se implementar os passos citados acima. Não estou levando em consideração o desempenho, pois, em todos os meus testes o desempenho foi suficiente. Inclusive se você que está lendo tiver alguma sugestão, por favor, sinta-se a vontade para compartilhar.</p>
<p>Agora, um pouco de código.</p>
<h4>Passo 1 e 2 (calibração)</h4>
<p>Tire uma screenshot do navegador com o game iniciado (foto abaixo), com um software de edição de imagens meça a distância do topo (padTop) e esquerda (padLeft) do canvas do game (linhas azuis).</p>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://carlancalazans.com/wp-content/uploads/2009/05/picture-21.png"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/picture-21-300x187.png" alt="Mapeamento" title="Mapeamento" width="300" height="187" class="size-medium wp-image-259" /></a><p class="wp-caption-text">Mapeamento</p></div>
<p>Agora, configure a classe para tirar fotos somente do canvas, encontre a imagem do ponto (linhas vermelhas) mais alto que a bola pode chegar analisando todas as imagens e, por último, com um software de edição de imagens meça novamente a distância do topo e esquerda, mas desta vez em relação a bola. Essa é uma das partes chatas.</p>
<p>Segue abaixo a classe para tirar fotos do game canvas.</p>
<p>TakeShoots.java (canvas)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TakeShoots <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for game canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <span style="color: #cc66cc;">185</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <span style="color: #cc66cc;">209</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">640</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for ball</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padLeft = 322;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padTop = 431;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//w = 46;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//h = 46;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5 seg...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> howManyTimes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span> <span style="color: #339933;">=</span> times<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//file = new File(&quot;ball&quot;+i+&quot;.png&quot;);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageIO.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>image,<span style="color: #0000ff;">&quot;png&quot;</span>, file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Com a imagem do passo 1, recorte a imagem da bola no ponto mais alto em formato de quadrado. A bola possui o tamanho 46&#215;46. Salve este arquivo com o nome ball.png no diretório do arquivo java. No meu caso a screenshot do game canvas em que a bola chega no ponto mais alto e a imagem da bola (ball.png) podem ser visualizadas abaixo:</p>
<div id="attachment_254" class="wp-caption aligncenter" style="width: 410px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/higher2.png" alt="Ponto mais alto" title="Ponto mais alto" width="400" height="300" class="size-full wp-image-254" /><p class="wp-caption-text">Ponto mais alto</p></div>
<div id="attachment_248" class="wp-caption aligncenter" style="width: 56px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/ball.png" alt="Bola" title="Bola" width="46" height="46" class="size-full wp-image-248" /><p class="wp-caption-text">Bola</p></div>
<p>Se desejar, alterando a classe TakeShoots.java, podemos automatizar o processo tirando screenshots somente da bola, é uma forma de ter certeza que é o ponto mais alto também. Para isso faça:</p>
<p>TakeShoots.java (ball)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TakeShoots <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for all game canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padLeft = 185;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padTop = 209;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//w = 640;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//h = 480;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for ball</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <span style="color: #cc66cc;">322</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <span style="color: #cc66cc;">431</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">46</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">46</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5 seg...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> howManyTimes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span> <span style="color: #339933;">=</span> times<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//file = new File(&quot;image&quot;+i+&quot;.png&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ball&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageIO.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>image,<span style="color: #0000ff;">&quot;png&quot;</span>, file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h4>Passo 3</h4>
<p>Com a imagem do passo 2 compare com outra imagem de tamanho 46&#215;46 (ou não). Faça os testes você mesmo, compare a imagem calibrada (ball.png) com qualquer outra 46&#215;46 no formato png. Faça também a comparação de ball.png com ela mesma e veja o resultado. </p>
<p>Estou utilizando uma forma bem simples para identificar se as imagens são iguais. Como se trata de uma imagem de tamanho pequeno, a comparação é feita pelos valores RGB das duas imagens pixel a pixel. Caso a imagem fosse maior que 46&#215;46, uma outra forma seria, traçar linhas horizontais / verticais ou nas diagonais e comparar os valores RGB somente daqueles pontos. Em softwares de detecção de movimento é possível aprender muitas formas de tratar este problema.</p>
<p>Ah, lembrando, as imagens devem estar no mesmo diretório do arquivo java quando executar a classe.</p>
<p>CompareImages.java</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CompareImages <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, image2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> filename1, filename2<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> CompareImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> started <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> compareImage<span style="color: #009900;">&#40;</span>image1, image2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> started <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; ms.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> loadImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename1 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ball.png&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename2 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ball.png&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image1 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>filename1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image2 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>filename2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> compareImage<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> CompareImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h4>Passo 4</h4>
<p>Junte todos os passos anteriores em uma nova classe, quando a classe detectar que as imagens são iguais pressione e solte o botão esquerdo do mouse. Aproveitei este passo e criei um arquivo de configuração que é lido somente ao executar a classe em questão, isso evita recompilar o arquivo java só para ajustar os valores de configuração.</p>
<p>KickOffTrick.java (final)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> KickOffTrick <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a> properties<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> propertiesFileName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;kickoff.properties&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> ball1, ball2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> KickOffTrick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readPropertiesFile<span style="color: #009900;">&#40;</span>propertiesFileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;paddingleft&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;paddingtop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;shootwidth&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;shootheight&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ball1 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ballimagefilename&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5s...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Prepare yourself...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> readPropertiesFile<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> filename<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; properties <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afileinputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">FileInputStream</span></a><span style="color: #009900;">&#40;</span>filename<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">boolean</span> result<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ball2 <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">=</span> compareImage<span style="color: #009900;">&#40;</span>ball1, ball2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepbeforekick&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot.<span style="color: #006633;">mousePress</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputEvent</span></a>.<span style="color: #006633;">BUTTON1_MASK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot.<span style="color: #006633;">mouseRelease</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputEvent</span></a>.<span style="color: #006633;">BUTTON1_MASK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepafterkick&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ball2 <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepballshoot&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> compareImage<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> KickOffTrick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>O arquivo de configuração ficou assim:</p>
<p>kickoff.properties</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># ball left distance<br />
paddingleft = 322<br />
# ball top distance<br />
paddingtop = 431<br />
# ball shoot width<br />
shootwidth = 46<br />
# ball shoot height<br />
shootheight = 46<br />
# ball filename (for comparation)<br />
ballimagefilename = ball.png<br />
# sleep before kick the ball in ms<br />
sleepbeforekick = 110<br />
# sleep after kick the ball in ms<br />
sleepafterkick = 10000<br />
# sleep interval for take another shoot<br />
sleepballshoot = 50</div></div>
<p>Não utilize os valores pré-selecionados, eles só estão preenchidos para você ter uma cola.</p>
<h4>Concluindo</h4>
<p>Talvez com este exemplo você não consiga bater nenhum record, mas vai ter a oportunidade de aprender coisas novas e interessantes. Eu me diverti pensando em como implementar a solução, espero que você se divirta lendo (ou fazendo todos os passos) <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Em breve os arquivos estarão no github.com se alguém se interessar.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/trapaceando-no-monkey-kick-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby calculando o dia da Páscoa</title>
		<link>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/</link>
		<comments>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 23:06:46 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=209</guid>
		<description><![CDATA[A Páscoa é uma data comemorativa que serve de referência para datas comemorativas móveis como Carnaval, Quaresma, Corpus Christ e outras. Por isso é importante saber quando a Páscoa vai ser comemorada. Além de interessante, serve como uma brincadeira para os garotos(as) de programa de plantão que não tem nada para fazer no feriado.
Cálculo
No total [...]]]></description>
			<content:encoded><![CDATA[<p>A Páscoa é uma data comemorativa que serve de referência para datas comemorativas móveis como Carnaval, Quaresma, Corpus Christ e outras. Por isso é importante saber quando a Páscoa vai ser comemorada. Além de interessante, serve como uma brincadeira para os garotos(as) de programa de plantão que não tem nada para fazer no feriado.</p>
<h4>Cálculo</h4>
<p>No total são três formas de calcular a data da Páscoa. A primeira é recorrendo a uma tabela, a segunda é através ao algorítimo de Gauss para o intervalo de anos que se inicia em 1900 e termina em 2099 e a terceira com o algorítimo de Meeus / Jones / Butcher. Como exemplo, optei pela segunda forma por ter umas condições e por ela ser mais elaborada. Para quem se interessar, os algorítimos serão relacionados no final deste texto.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'date'</span><br />
<br />
FIELDS = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>Carnaval Pascoa Corpus\ Christ<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
ano = <span style="color:#006666;">2009</span> <span style="color:#008000; font-style:italic;">#change me</span><br />
<br />
x = <span style="color:#006666;">24</span><br />
y = <span style="color:#006666;">5</span><br />
<br />
a = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">19</span><br />
b = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">4</span><br />
c = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">7</span><br />
d = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">19</span> <span style="color:#006600; font-weight:bold;">*</span> a <span style="color:#006600; font-weight:bold;">+</span> x<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">30</span><br />
e = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span> <span style="color:#006600; font-weight:bold;">*</span> b <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">4</span> <span style="color:#006600; font-weight:bold;">*</span> c <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">6</span> <span style="color:#006600; font-weight:bold;">*</span> d <span style="color:#006600; font-weight:bold;">+</span> y<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">7</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#april</span><br />
&nbsp; dia = d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">9</span><br />
&nbsp; mes = <span style="color:#006666;">4</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;">#exceptions &nbsp;</span><br />
&nbsp; dia = <span style="color:#006666;">19</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>dia == <span style="color:#006666;">26</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; dia = <span style="color:#006666;">18</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>dia == <span style="color:#006666;">25</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> d == <span style="color:#006666;">28</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> a <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#march</span><br />
&nbsp; dia = d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">22</span><br />
&nbsp; mes = <span style="color:#006666;">3</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
dt = <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ano, mes, dia<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
result = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">47</span><br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt<br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">60</span><br />
<br />
FIELDS.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>d<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{d}: #{result.shift.strftime(&quot;</span><span style="color:#006600; font-weight:bold;">%</span>d<span style="color:#006600; font-weight:bold;">-%</span>m<span style="color:#006600; font-weight:bold;">-%</span>Y<span style="color:#996600;">&quot;)}&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Este texto tem uma pegadinha. Na verdade, meu intuito com ele não é ensinar Ruby nem mostrar como se calcula o dia da Páscoa. Foi uma forma que encontrei de mostrar como a linguagem chega perto do idioma, como poucas linguagens o fazem. Qualquer pessoa é capaz de entender as fórmulas matemáticas e relacioná-las com o exemplo mostrado. Sim, existe um açúcar, mas é fácil de entendê-lo também.</p>
<p>A maior parte do tempo, parece que estamos conversando com um editor de textos.</p>
<h4>Referências:</h4>
<ul>
<li><a href="http://pt.wikipedia.org/wiki/P%C3%A1scoa">Páscoa</a></li>
<li><a href="http://pt.wikipedia.org/wiki/C%C3%A1lculo_da_P%C3%A1scoa">Cálculo da Páscoa</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rapidinha: GIF animado com Ruby</title>
		<link>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/</link>
		<comments>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 19:50:15 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=203</guid>
		<description><![CDATA[A algumas horas atrás estava tentando criar um gif animado para o twitter. Esbarrei com uma solução usando Gimp, sugestão do oráculo. Fiz o gif animado. Alguns minutos depois, o lembrei de uma gem para Ruby chamada RMagick para processamento de imagens. Como nunca a tinha experimentado eis que veio a idéia de escrever uma [...]]]></description>
			<content:encoded><![CDATA[<p>A algumas horas atrás estava tentando criar um gif animado para o <a href="http://twitter.com/carlancalazans">twitter</a>. Esbarrei com uma <a href="http://azulebanana.com/bluey/2007/04/30/simples-faixa-animada-em-gif-com-o-gimp/">solução</a> usando <a href="http://www.gimp.org/">Gimp</a>, sugestão do oráculo. Fiz o gif animado. Alguns minutos depois, o lembrei de uma gem para <a href="http://http://www.ruby-lang.org/">Ruby</a> chamada <a href="http://rmagick.rubyforge.org/">RMagick</a> para processamento de imagens. Como nunca a tinha experimentado eis que veio a idéia de escrever uma classe para criar um gif animado.</p>
<p>A gem RMagick é baseada na biblioteca de imagens <a href="http://www.imagemagick.org/">Image Magick</a> comumente conhecida no mundo Linux pelo poder de seus utilitários em linha de comando. É, linha de comando, sem a necessidade de Gimp, FW, PS e similares. Quem nunca ouviu falar de import ou convert? <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>A classe em questão é a:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'RMagick'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">include</span> Magick<br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> AnimatedGif<br />
<br />
&nbsp; DELAY = <span style="color:#006666;">100</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">LOOP</span> = <span style="color:#006666;">0</span><br />
&nbsp; <br />
&nbsp; attr_accessor <span style="color:#ff3333; font-weight:bold;">:source</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> save<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">delay</span> = DELAY<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">iterations</span> = <span style="color:#CC0066; font-weight:bold;">LOOP</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; private<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span> = ImageList.<span style="color:#9900CC;">new</span><br />
&nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>source<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f =~ <span style="color:#006600; font-weight:bold;">/</span>^\.<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">read</span> <span style="color:#996600;">&quot;#{source}/#{f}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;">#Usage:</span><br />
gif = AnimatedGif.<span style="color:#9900CC;">new</span><br />
gif.<span style="color:#9900CC;">source</span> = <span style="color:#996600;">'img_src'</span><br />
gif.<span style="color:#9900CC;">save</span> <span style="color:#996600;">'/tmp/animated.gif'</span></div></div>
<p>O delay entre as imagens está fixo no código. O loop é infinito, ou seja, seu gif ficará se repetindo a vida toda. Após criar um objeto da classe AnimatedGif é necessário informar um diretório com imagens estáticas para gerar o gif animado. E por último, é só chamar o método save passando o caminho do arquivo gif final.</p>
<p>Demorou uns dois minutos a mais depois do entendimento da solução em Gimp para gerar esta classe em Ruby. Foram uns 3 minutos para entender a técnica do Gimp e 5 minutos para criar a classe em Ruby. A linguagem não morde!</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Triggers no SQLITE</title>
		<link>http://carlancalazans.com/triggers-no-sqlite/</link>
		<comments>http://carlancalazans.com/triggers-no-sqlite/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 03:24:41 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[pesquisa]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[trigger]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=157</guid>
		<description><![CDATA[Esta semana um grande amigo twitou uma pergunta que me chamou atenção. Já tinha estudado sobre o assunto a alguns anos atrás para utilizar em um sistema. Foi dai que veio a idéia para este post, peguei os meus rascunhos e comecei a escrever.
O banco de dados SQLITE, em sua versão atual, não possui suporte [...]]]></description>
			<content:encoded><![CDATA[<p>Esta semana um <a href="http://www.leocabral.com.br">grande</a> <a href="http://twitter.com/lcquadros">amigo</a> <a href="http://twitter.com/lcquadros/status/1275497421">twitou</a> uma pergunta que me chamou atenção. Já tinha estudado sobre o assunto a alguns anos atrás para utilizar em um sistema. Foi dai que veio a idéia para este post, peguei os meus rascunhos e comecei a escrever.</p>
<p>O banco de dados <a href="http://www.sqlite.org">SQLITE</a>, em sua <a href="http://www.sqlite.org/releaselog/3_6_11.html">versão atual</a>, não possui suporte a <a href="http://pt.wikipedia.org/wiki/Integridade_referencial">integridade referencial</a>. Nunca consegui entender o motivo, já que bancos similares como <a href="http://www.h2database.com">h2</a> e <a href="http://hsqldb.org">HSQLDB</a> possuem. Talvez não implementaram a funcionalidade ainda por que existe uma outra alternativa. Uma forma de driblar essa limitação é através de <a href="http://pt.wikipedia.org/wiki/Gatilho_(banco_de_dados)">triggers</a>. Um trigger é disparado quando um evento ocorre. É possível deletar os registros filhos relacionados com uma tabela pai, por exemplo. O evento neste caso, para ficar bem claro, é a remoção de um registro da tabela pai.</p>
<p>A sintaxe básica para a criação de um trigger é:</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> nome_da_trigger<br />
<span style="color: #66cc66;">&#123;</span> BEFORE <span style="color: #66cc66;">|</span> AFTER <span style="color: #66cc66;">|</span> INSTEAD OF <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#123;</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> OF <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#125;</span><br />
BEGIN<br />
<span style="color: #66cc66;">&#123;</span> SQL STATEMENT <span style="color: #66cc66;">&#125;</span><br />
END;</div></div>
<p>Para praticar, criei as tabelas abaixo. Se você for preguiçoso como eu, pode baixar o arquivo do banco de dados direto <a href="http://files.carlancalazans.com/sqlite/exemplo.zip">daqui</a>. É um exemplo bem simples, se você já for um expert em banco de dados (ou um dba), nada do que vou mostrar é novidade.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BEGIN TRANSACTION;<br />
<br />
<span style="color: #808080; font-style: italic;">-- users table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> users <span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> login text<span style="color: #66cc66;">,</span> password text<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- tasks table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> tasks <span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> user_id integer<span style="color: #66cc66;">,</span> name text<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- logs table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> logs<span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> event text<span style="color: #66cc66;">,</span> created_at datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">&#40;</span>datetime<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'now'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'localtime'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- counts table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> counts<span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> name text<span style="color: #66cc66;">,</span> value integer<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- data</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Entender triggers no sqlite'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Aprender a voar'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;counts&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'users'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;counts&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'tasks'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
COMMIT;</div></div>
<p>Agora vem a parte interessante. Vejamos como inserir um registro na tabela logs toda vez que um usuário for criado. O trigger é &#8220;colocado&#8221; na tabela users e, toda vez, após ocorrer um insert o trigger é disparado.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- after insert user trigger</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> user_insert<br />
after <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
begin<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> logs <span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;New user created&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
end;</div></div>
<p>Faça o teste. Termine de inserir outros usuários e verifique a tabela logs.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> logs;</div></div>
<p>O trigger acima monitora a operação insert e adiciona um registro em outra tabela. Agora um exemplo que monitora a mesma operação, mas realiza o update em outra tabela.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- update users count</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> update_users_count<br />
after <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
begin<br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> counts <span style="color: #993333; font-weight: bold;">SET</span> value <span style="color: #66cc66;">=</span> value <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;users&quot;</span>;<br />
end;<br />
<br />
<span style="color: #808080; font-style: italic;">-- test again</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'delete'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'me'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'highlander'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'therecanbeonlyone'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Para o exemplo de integridade referencial, maiores informações no início do post, o trigger realiza o delete em todos os registros (for each row) relacionados com a tabela pai. Neste exemplo a tabela pai é users e a filha é tasks. A referência feita a old significa o valor atual do iterator no loop.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- before delete user trigger</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> user_delete<br />
before <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
<span style="color: #993333; font-weight: bold;">FOR</span> each row<br />
begin<br />
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> tasks <span style="color: #993333; font-weight: bold;">WHERE</span> tasks<span style="color: #66cc66;">.</span>user_id<span style="color: #66cc66;">=</span>old<span style="color: #66cc66;">.</span>id;<br />
end;<br />
<br />
<span style="color: #808080; font-style: italic;">-- test</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Ganhar na mega-sena'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Delete me'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Dominar o mundo'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Test task'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Hello world'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Buy new car'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Drink more'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Delete o usuário de id número 4 e veja o que acontece.</p>
<p>Pra finalizar, recomendo a todos <a href="http://files.carlancalazans.com/sqlite/exemplo.zip">baixar o arquivo de exemplo</a> e fuçar. Esta solução pode não atender a todos, já que para deletar 1000000 registros filhos, dependendo o seu hardware, o processo pode ser custoso. Não tenho um conhecimento tão profundo sobre engines de banco de dados para explicar como seria feito utilizando um banco com suporte a integridade referencial, portanto, leve isso em consideração ao interpretar a afirmação acima.</p>
<p>De qualquer forma, o uso do SQLITE só deve ser feito em protótipos ou em aplicações cujo os dados não são de muita importância. Caso os dados de sua aplicação sejam muito importantes, geralmente são, você deveria procurar outra alternativa.</p>
<p>Enfim, pelo menos, deu pra brincar um pouco.</p>
<p>Referências:<a href="     * http://www.sqlite.org/lang_createtrigger.html  "><br />
</a></p>
<ul>
<li><a href="     * http://www.sqlite.org/lang_createtrigger.html  ">http://www.sqlite.org/lang_createtrigger.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/triggers-no-sqlite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Números em Objective-C</title>
		<link>http://carlancalazans.com/numeros-em-objective-c/</link>
		<comments>http://carlancalazans.com/numeros-em-objective-c/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 00:33:03 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[objectivec]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=119</guid>
		<description><![CDATA[Objective-C pode ser considerado um cinto de utilidades baseado no C. Isso significa que todo o poder da linguagem pai está disponível, incluindo as diversas bibliotecas. Em todos os meus testes, quando precisei de tipos numéricos usei os tipos primitivos do C. A pouco tempo descobri que existe um problema nessa abordagem.
Dependendo do uso, acredito [...]]]></description>
			<content:encoded><![CDATA[<p>Objective-C pode ser considerado um cinto de utilidades baseado no C. Isso significa que todo o poder da linguagem pai está disponível, incluindo as diversas bibliotecas. Em todos os meus testes, quando precisei de tipos numéricos usei os tipos primitivos do C. A pouco tempo descobri que existe um problema nessa abordagem.</p>
<div id="attachment_120" class="wp-caption aligncenter" style="width: 410px"><img class="size-full wp-image-120" title="Números" src="http://carlancalazans.com/wp-content/uploads/2009/02/cone.jpg" alt="Números" width="400" height="332" /><p class="wp-caption-text">4 8 15 16 23 42</p></div>
<p>Dependendo do uso, acredito que os tipos numéricos do C sejam mais indicados, mas ao desenvolver utilizando algumas classes, como NSArray onde não podemos incluir elementos que não sejam objetos, a coisa começa a complicar. O problema em questão não é a linguagem ou os seus criadores e sim a falta de conhecimento do programador.</p>
<p>Olhando a <a href="http://developer.apple.com/referencelibrary/index.html">documentação</a>, depois de uma boa garimpada, é possível encontrar referências que chamam atenção. <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html">NSNumber</a> (subclasse de <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSValue_Class/Reference/Reference.html">NSValue</a>), NSInteger, NSUInteger. A primeira é a mais utilizada e é uma classe (imutável), o resto são somente sinônimos (typedef) para os tipos numéricos já conhecidos do C. Podemos criar um objeto da classe NSNumber através dos tipos signed (ou unsigned) char, short int, int, long int, float, double e BOOL.</p>
<p>Exemplos:</p>
<div class="codecolorer-container objc vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">123</span>;<br />
<span style="color: #a61390;">float</span> f <span style="color: #002200;">=</span> <span style="color: #2400d9;">123.45</span>;<br />
<span style="color: #a61390;">char</span> c <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">'c'</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> intObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithInt<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> floatObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithFloat<span style="color: #002200;">:</span>f<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// isn't useful to me</span><br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> yesObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithBool<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> noObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithBool<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> doubleObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithDouble<span style="color: #002200;">:</span><span style="color: #2400d9;">123.456</span><span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> <span style="color: #002200;">*</span> charObject <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/"><span style="color: #400080;">NSNumber</span></a> numberWithChar<span style="color: #002200;">:</span>c<span style="color: #002200;">&#93;</span>;<br />
<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;intObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>intObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;floatObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>floatObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;yesObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>yesObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;noObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>noObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;doubleObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>doubleObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;CharObject class = %@&quot;</span>, <span style="color: #002200;">&#91;</span>charObject className<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// string representation</span><br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;<span style="color: #2400d9;">\n</span>&quot;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of intObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>intObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of floatObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>floatObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of yesObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>yesObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of noObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>noObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of doubleObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>doubleObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;String value of CharObject = %@&quot;</span>, <span style="color: #002200;">&#91;</span>charObject stringValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// comparing</span><br />
<span style="color: #11740a; font-style: italic;">// the return will be NSOrderedAscending (greated than), NSOrderedSame (equal to)</span><br />
<span style="color: #11740a; font-style: italic;">// and NSOrderedDescending (less than).</span><br />
<span style="color: #002200;">&#91;</span>intObject compare<span style="color: #002200;">:</span>floatObject<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>floatObject compare<span style="color: #002200;">:</span>intObject<span style="color: #002200;">&#93;</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/numeros-em-objective-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Acessando o Cep Livre com Ruby</title>
		<link>http://carlancalazans.com/acessando-o-cep-livre-com-ruby/</link>
		<comments>http://carlancalazans.com/acessando-o-cep-livre-com-ruby/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 01:00:17 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=87</guid>
		<description><![CDATA[A (PC)² consultoria lançou um serviço chamado Cep Livre a algumas semanas atrás. O serviço tem por objetivo fornecer informações sobre CEPs brasileiros. O funcionamento é similar aos serviços já existentes, você faz uma chamada em uma URL e recebe os dados em um formato que escolher (XML ou CSV). Acredito que não vai demorar [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://www.pc2consultoria.com">(PC)² consultoria</a> lançou um serviço chamado <a href="http://ceplivre.pc2consultoria.com">Cep Livre</a> a algumas semanas atrás. O serviço tem por objetivo fornecer informações sobre CEPs brasileiros. O funcionamento é similar aos serviços já existentes, você faz uma chamada em uma URL e recebe os dados em um formato que escolher (XML ou CSV). Acredito que não vai demorar para fornecerem o formato JSON já que ele é amplamente utilizado hoje em dia, inclusive em aplicações móveis (XML não pelo-amor-de-deus).</p>
<p>A diferença em relação aos serviços que conheço é a possibilidade de adicionar um CEP a base de dados preenchendo <a href="http://ceplivre.pc2consultoria.com/index.php?module=cep&amp;event=formeditacep">um formulário</a>, ou seja, qualquer um pode fazer. Ah, o mais importante, o serviço é gratuito e a <a href="http://www.pc2consultoria.com">(PC)² consultoria</a> afirma que não tem intenção de cobrar pelo serviço no <a href="http://www.pc2consultoria.com/index.php?option=com_content&amp;task=view&amp;id=298&amp;Itemid=73">website deles</a>.</p>
<p>Agora a parte divertida. Fiz uma classe que busca as informações de CEP, faz o parser e apresenta em dois formatos: Array e Hash.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#008000; font-style:italic;"># 9/2/2009</span><br />
<span style="color:#008000; font-style:italic;"># Carlan Calazans (carlancalazans at gmail.com)</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rexml/document'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> CepLivre<br />
<br />
&nbsp; URL_CEP_LIVRE = <span style="color:#996600;">'http://ceplivre.pc2consultoria.com/index.php?module=cep&amp;formato=xml&amp;cep='</span><br />
&nbsp; FIELDS = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>tipo_logradouro logradouro bairro cidade estado_sigla<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>cep<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@cep</span> = cep<br />
&nbsp; &nbsp; get_data<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> to_array<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
&nbsp; &nbsp; process_a<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> to_hash<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; process_h<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; private<br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> get_data<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@data</span> = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get_response</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{URL_CEP_LIVRE}#{@cep}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;Connection error.&quot;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@data</span>.<span style="color:#9900CC;">kind_of</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Net::HTTPSuccess</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@xml</span> = <span style="color:#6666ff; font-weight:bold;">REXML::Document</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>@data.<span style="color:#9900CC;">body</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> process_a<br />
&nbsp; &nbsp; FIELDS.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; field = <span style="color:#6666ff; font-weight:bold;">REXML::XPath</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>@xml, <span style="color:#996600;">&quot;//#{f}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> field.<span style="color:#9900CC;">text</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> process_h<br />
&nbsp; &nbsp; FIELDS.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; field = <span style="color:#6666ff; font-weight:bold;">REXML::XPath</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>@xml, <span style="color:#996600;">&quot;//#{f}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span><span style="color:#006600; font-weight:bold;">&#91;</span>f<span style="color:#006600; font-weight:bold;">&#93;</span> = field.<span style="color:#9900CC;">text</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@result</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Array</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> CepLivre.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;29040-470&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_array</span><br />
<span style="color:#008000; font-style:italic;"># Hash</span><br />
<span style="color:#CC0066; font-weight:bold;">puts</span> CepLivre.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;29040-470&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_hash</span></div></div>
<h4>[Update]</h4>
<p>Faça o download da versão <a href="http://files.carlancalazans.com/ruby/ceplivre/ceplivre-rexml.rb">rexml</a> e <a href="http://files.carlancalazans.com/ruby/ceplivre/ceplivre-libxml.rb">libxml-ruby</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/acessando-o-cep-livre-com-ruby/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>String em Objective-C</title>
		<link>http://carlancalazans.com/string-em-objective-c/</link>
		<comments>http://carlancalazans.com/string-em-objective-c/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 12:18:32 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[objectivec]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=60</guid>
		<description><![CDATA[Quando falamos de String em Objective-C estamos nos referindo as classes NSString e NSMutableString. Como no C, Strings são basicamente um array de caracteres Unicode.
Por que duas classes?
A diferença entre elas é que uma é imutável ( NSString ) e a outra ( NSMutableString ) pode ser modificada. No entanto, é possível atribuir uma nova [...]]]></description>
			<content:encoded><![CDATA[<p>Quando falamos de String em Objective-C estamos nos referindo as classes NSString e NSMutableString. Como no C, Strings são basicamente um array de caracteres <a href="http://www.unicode.org">Unicode</a>.</p>
<div id="attachment_80" class="wp-caption aligncenter" style="width: 410px"><img class="size-full wp-image-80" title="String Theory" src="http://carlancalazans.com/wp-content/uploads/2009/02/string_theory.png" alt="String Theory from xkcd.com" width="400" height="386" /><p class="wp-caption-text">String Theory from xkcd.com</p></div>
<h4>Por que duas classes?</h4>
<p>A diferença entre elas é que uma é imutável ( NSString ) e a outra ( NSMutableString ) pode ser modificada. No entanto, é possível atribuir uma nova string em um ponteiro para a classe NSString. Dito isso, fica claro distinguir quando usar as classes mencionadas.</p>
<p>Abaixo temos pedaços de códigos com algumas (não todas) operações disponíveis.</p>
<div class="codecolorer-container objc vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// creation</span><br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>firstName <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Carlan&quot;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>lastName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// or [[NSString alloc] init]</span><br />
lastName <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Calazans&quot;</span>;<br />
<br />
<span style="color: #a61390;">char</span> cStr<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">15</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">&quot;An old C string&quot;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>cString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithCString<span style="color: #002200;">:</span>cStr<span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/"><span style="color: #400080;">NSMutableString</span></a> <span style="color: #002200;">*</span>fullNameMutable <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>firstName mutableCopy<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// interpolation</span><br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>fullName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@ %@&quot;</span>, firstName, lastName<span style="color: #002200;">&#93;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;My name is: %@&quot;</span>, fullName<span style="color: #002200;">&#41;</span>;<br />
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #a61390;">printf</span></a><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;%s&quot;</span>, <span style="color: #002200;">&#91;</span>fullName cString<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// basic operations</span><br />
<span style="color: #11740a; font-style: italic;">//[firstName appendString:@&quot; Calazans&quot;]; // wont compile</span><br />
<span style="color: #002200;">&#91;</span>fullNameMutable appendString<span style="color: #002200;">:</span>lastName<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable lowercaseString<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable uppercaseString<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable capitalizedString<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable length<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullName writeToFile<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;/tmp/test.txt&quot;</span> atomically<span style="color: #002200;">:</span> <span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable replaceString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Carlan&quot;</span> withString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Alan&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #a61390;">NSRange</span> r <span style="color: #002200;">=</span> NSMakeRange<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">4</span><span style="color: #002200;">&#41;</span>; <span style="color: #11740a; font-style: italic;">// NSRange is not a class!</span><br />
<span style="color: #002200;">&#91;</span>fullNameMutable substringWithRange<span style="color: #002200;">:</span>r<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable substringToIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>fullNameMutable substringFromIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableString_Class/"><span style="color: #400080;">NSMutableString</span></a> <span style="color: #002200;">*</span>stringWithSpaces <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot; my string &quot;</span> mutableCopy<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>stringWithSpaces trimLeadSpaces<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>stringWithSpaces trimTailSpaces<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>stringWithSpaces trimSpaces<span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>strA <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;stringA&quot;</span>;<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>strB <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;stringB&quot;</span>;<br />
<span style="color: #002200;">&#91;</span>string1 compare<span style="color: #002200;">:</span>string2<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>string1 caseInsensitiveCompare<span style="color: #002200;">:</span>string2<span style="color: #002200;">&#93;</span>;<br />
<br />
<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>splitMe <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;carlan:calazans:29:brasileiro&quot;</span>;<br />
<span style="color: #002200;">&#91;</span>splitMe componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;:&quot;</span><span style="color: #002200;">&#93;</span>;</div></div>
<p>Procurei deixar bem poucos comentários para não sujar muito o código. Não fica tão complicado de ler por que o nome dos métodos já dizem o que eles fazem.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/string-em-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pegando o conteúdo de uma url com Objective-C</title>
		<link>http://carlancalazans.com/pegando-o-conteudo-de-uma-url-com-objective-c/</link>
		<comments>http://carlancalazans.com/pegando-o-conteudo-de-uma-url-com-objective-c/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 01:16:52 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[objectivec]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=40</guid>
		<description><![CDATA[Desde ontem estava tentando pegar o conteúdo de uma url qualquer e imprimir no console. Até que não é tão complicado comparando com Ruby ou Python. Minha maior dificuldade foi converter de NSMutableData para NSString. Também não sei por que cargas d&#8217;águas não está funcionando para todas as urls, a do google, por exemplo.
Estou gostando [...]]]></description>
			<content:encoded><![CDATA[<p>Desde ontem estava tentando pegar o conteúdo de uma url qualquer e imprimir no console. Até que não é tão complicado comparando com <a href="http://www.ruby-lang.org">Ruby</a> ou <a href="http://www.python.org">Python</a>. Minha maior dificuldade foi converter de NSMutableData para NSString. Também não sei por que cargas d&#8217;águas não está funcionando para todas as urls, a do <a href="http://www.google.com.br">google</a>, por exemplo.</p>
<p>Estou gostando de Objective-C, mas sinto falta das facilidades de  <a href="http://www.ruby-lang.org">Ruby</a> e <a href="http://www.python.org">Python</a>, provavelmente por estar mais acostumado a elas. E é muito fácil se perder na chamada a métodos utilizando a sintaxe dos colchetes, pior se eles estiverem aninhados. Como estou programando utilizando o ubuntu a &#8220;dot-syntax&#8221; não está disponível, acredito que somente no Mac Os. É nessa hora que um bom editor de textos faz toda a diferença.</p>
<p>Pra quem se interessar, segue o código.</p>
<div class="codecolorer-container objc vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &lt;Foundation/Foundation.h&gt;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// 03-02-2009</span><br />
<span style="color: #11740a; font-style: italic;">// Carlan Calazans (carlancalazans at gmail.com)</span><br />
<br />
<span style="color: #11740a; font-style: italic;">//connection.h</span><br />
<span style="color: #a61390;">@interface</span> Connection<span style="color: #002200;">:</span> <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/"><span style="color: #400080;">NSObject</span></a><br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">*</span>strUrl;<br />
&nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/"><span style="color: #400080;">NSMutableData</span></a> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">*</span>myReceivedData;<br />
<span style="color: #002200;">&#125;</span><br />
&nbsp; <span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> initialize;<br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #11740a; font-style: italic;">//connection.m</span><br />
<span style="color: #a61390;">@implementation</span> Connection<br />
&nbsp; <span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> initialize<br />
&nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Started...&quot;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; strUrl <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://carlancalazans.com&quot;</span><span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;URL: %@&quot;</span>, strUrl<span style="color: #002200;">&#41;</span>;<br />
&nbsp; myReceivedData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/"><span style="color: #400080;">NSMutableData</span></a> dataWithContentsOfURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> URLWithString<span style="color: #002200;">:</span>strUrl<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Received %d bytes of data.&quot;</span>, <span style="color: #002200;">&#91;</span>myReceivedData length<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>content <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> alloc<span style="color: #002200;">&#93;</span> initWithData<span style="color: #002200;">:</span>myReceivedData encoding<span style="color: #002200;">:</span>NSUTF8StringEncoding<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Content received: %@&quot;</span>, content<span style="color: #002200;">&#41;</span>;<br />
&nbsp; NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Finished...&quot;</span><span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; <span style="color: #002200;">&#91;</span>content release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; <span style="color: #002200;">&#125;</span><br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #11740a; font-style: italic;">//main.m</span><br />
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/"><span style="color: #400080;">NSAutoreleasePool</span></a> <span style="color: #002200;">*</span>pool <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/"><span style="color: #400080;">NSAutoreleasePool</span></a> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; Connection <span style="color: #002200;">*</span>con <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Connection alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; <span style="color: #002200;">&#91;</span>con initialize<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; <span style="color: #002200;">&#91;</span>con release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; <span style="color: #002200;">&#91;</span>pool release<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;<br />
<span style="color: #002200;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/pegando-o-conteudo-de-uma-url-com-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Learning novos cursos</title>
		<link>http://carlancalazans.com/ruby-learning-novos-cursos/</link>
		<comments>http://carlancalazans.com/ruby-learning-novos-cursos/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 01:26:29 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[curso]]></category>
		<category><![CDATA[pesquisa]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby learning]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=11</guid>
		<description><![CDATA[Ruby Learning é um website que oferece cursos baseados em Ruby online, em inglês. O curso em si é muito divertido e muito bem feito para ser um curso online e de graça, até os exercícios são bem bolados. Há a possibilidade dos alunos se interagirem uns com os outros através de fóruns e com [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rubylearning.org" target="_self">Ruby Learning</a> é um website que oferece cursos baseados em <a href="http://www.ruby-lang.org" target="_self">Ruby</a> online, em inglês. O curso em si é muito divertido e muito bem feito para ser um curso online e de graça, até os exercícios são bem bolados. Há a possibilidade dos alunos se interagirem uns com os outros através de fóruns e com os Assistentes de professor, que nada mais são do que alunos mais experientes. O conteúdo de um lição é liberado todo o Sábado, o aluno tem a semana inteira para estudar e fazer os exercícios, é bem tranquilo. Outro incentivo é que o curso é curto, ou seja, tem duração de somente 2 meses.</p>
<p>Aproveitando, o Satish criou uma pesquisa para a criação de novos cursos. O Ruby Learning já tem algumas sugestões e deseja saber o que a comunidade pensa sobre isto. Portanto, citando o Satish em seu blog:</p>
<blockquote><p>We’re rapidly expanding our course offerings here at RubyLearning, trying to keep up with the enormous and ever-growing interest in Ruby. But we need your YOUR help because, as you know, Ruby is a big subject, and we’d like to be sure to focus in on the areas of most interest to you. (<a href="http://rubylearning.com/blog/2008/11/15/can-you-help-rubylearning-with-your-suggestions/" target="_self">link para a pesquisa</a>).</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/ruby-learning-novos-cursos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
