<?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>Silveira Neto &#187; programming</title>
	<atom:link href="http://silveiraneto.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:13:27 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>GenBank renaming</title>
		<link>http://silveiraneto.net/2012/02/20/genbank-renaming/</link>
		<comments>http://silveiraneto.net/2012/02/20/genbank-renaming/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 06:08:30 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Bioinform]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[biopython]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[setuptools]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=4023</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2012/02/20/genbank-renaming/" title="GenBank renaming"></a>DNA inspired sculpture by Charles Jencks. Creative Commons photo by Maria Keays. What is GenBank? The GenBank sequence database is a widely used collection of nucleotide sequences and their protein translations. A GenBank sequence record file typically has a .gbk &#8230;<p class="read-more"><a href="http://silveiraneto.net/2012/02/20/genbank-renaming/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2012/02/20/genbank-renaming/" title="GenBank renaming"></a><p><img class="size-full wp-image-4024" title="DNA sculpture at Centre for Life by Maria Keays on Flickr. Sculpture by  Charles Jencks" src="http://silveiraneto.net/wp-content/uploads/2012/02/DNA-sculpture-at-Centre-for-Life-by-Maria-Keays-on-Flickr.jpg" alt="http://www.flickr.com/photos/maria_keays/1251843227/" width="640" height="480" /><br />
<small>DNA inspired sculpture by Charles Jencks. Creative Commons photo by <a title="Flickr" href="http://www.flickr.com/photos/maria_keays/1251843227/">Maria Keays</a>.</small></p>
<p><strong>What is GenBank?</strong></p>
<p>The <a href="http://www.ncbi.nlm.nih.gov/genbank/">GenBank</a> sequence database is a widely used collection of nucleotide sequences and their protein translations. A GenBank sequence record file typically has a .gbk or .gb extension and is filled with plain text characters. A example of GenBank file can be found <a href="http://silveiraneto.net/downloads/sequence.gb">here</a>.</p>
<p><strong>Filename problem</strong></p>
<p>Although there are several metadata are available inside a GenBank record the name of the file are not always in accordance with the content of the file. This is potentially a source of confusion to organize files and requires an additional effort to rename the files according to their content.</p>
<p><strong>Approach using Biopython</strong></p>
<p>The Biopython project is a mature open source international collaboration of volunteer developers, providing Python libraries for a wide range of bioinformatics problems. Among other tools, Biopython includes modules for reading and writing different sequence file formats including the GenBank&#8217;s record files.</p>
<p>Despite the fact that is possible to write a parser for GenBank&#8217; files it would represent a redundant effort to develop and maintain such tool. Biopython can be delegated to perform parsing and focus the programming on renaming mechanism.</p>
<p><strong>Biopython installation on Linux (Ubuntu 11.10) or Apple OS X (Lion)</strong></p>
<p>For both Ubuntu 11.10 and OS X Lion, a modern version of Python already comes out of the box.</p>
<p>For Linux you just need to install the Biopython package. One method to install Biopython in a APT ready distribution as Ubuntu 11.10 (Oneiric Ocelot) is:</p>
<blockquote><p># apt-get install python-biopython</p></blockquote>
<p>For an Apple OS X (Lion) you can install Biopython using <em>easy_install</em>, a popular package manager for the Python. <em>Easy_install</em> is bundled with <em>Setuptools</em>, a set of tools for Python.</p>
<p>To install the <em>Setuptools</em> <a href="http://pypi.python.org/pypi/setuptools#files">download the .egg file</a> for your python version (probably setuptools-0.6c11-py2.7.egg) and execute it as a Shell Script:</p>
<blockquote><p>sudo sh setuptools-0.6c11-py2.7.egg</p></blockquote>
<p>After this you already have easy_install in place and you can use it to install the Biopython library:</p>
<blockquote><p>sudo easy_install -f http://biopython.org/DIST/ biopython</p></blockquote>
<p>For both operational systems you can test if you already have Biopython installed using the Python iterative terminal:</p>
<blockquote><p>$ python<br />
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)<br />
[GCC 4.6.1] on linux2<br />
Type &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br />
&gt;&gt;&gt; import Bio<br />
&gt;&gt;&gt; Bio.__version__<br />
&#8217;1.57&#8242;<br />
&gt;&gt;&gt;</p></blockquote>
<p><strong>Automatic rename example through scripting</strong></p>
<p>Below the <a href="https://gist.github.com/1859976" title="at Github">Python source-code for a simple use of using Biopython to rename a Genbank file</a> to it&#8217;s description after removing commas and spaces.</p>
<p><script src="https://gist.github.com/1859976.js?file=gbkrename.py"></script></p>
<p>Using the the previous example of GenBank file, suppose you have a file called <a href="http://silveiraneto.net/downloads/sequence.gb">sequence.gb</a>. To rename this file to the GenBank description metadata inside it you can use the script.</p>
<blockquote><p>python gbkrename.py sequence.gb</p></blockquote>
<p>And after this it will be called Hippopotamus_amphibius_mitochondrial_DNA_complete_genome.gbk.</p>
<p><strong>Improvements</strong></p>
<p>There is plenty of room for improvement as:</p>
<ul>
<li>Better command line parsing with <a href="http://docs.python.org/library/optparse.html">optparse</a> and parameterization of all possible configuration.</li>
<li>A graphical interface</li>
<li>Handle special cases such multiple sequences in a single GenBank file.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2012/02/20/genbank-renaming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python, flatten a list</title>
		<link>http://silveiraneto.net/2011/10/08/python-flatten-a-list/</link>
		<comments>http://silveiraneto.net/2011/10/08/python-flatten-a-list/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 21:38:07 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[flatten]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3929</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/10/08/python-flatten-a-list/" title="Python, flatten a list"></a>Surprisingly python doesn&#8217;t have a shortcut for flatten a list (more generally a list of lists of lists of&#8230;). I made a simple implementation that doesn&#8217;t use recursion and tries to be written clearly. I get a element from a &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/10/08/python-flatten-a-list/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/10/08/python-flatten-a-list/" title="Python, flatten a list"></a><p>Surprisingly python doesn&#8217;t have a shortcut for flatten a list (more generally a list of lists of lists of&#8230;).</p>
<p>I made a simple implementation that doesn&#8217;t use recursion and tries to be written clearly.</p>
<p><script src="https://gist.github.com/1229108.js?file=flatten"></script></p>
<p>I get a element from a &#8220;bad&#8221; list (a list that can have another lists). If the element is not a list we store in our flat list. If the element is still a list we deal with him later. The flat list always have elements that are not a list.<br />
To preserve the original order we reverse the elements at the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/10/08/python-flatten-a-list/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OpenPixels: simple sprite sheet with Processing</title>
		<link>http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/</link>
		<comments>http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 01:54:00 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Openpixels]]></category>
		<category><![CDATA[Pixelart]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3859</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/" title="OpenPixels: simple sprite sheet with Processing"></a>/** * Openpixels example in Processing. * This simple example of how to get a sprite * from a sprite sheet. */ &#160; PImage bg; PImage sprite_sheet; PImage player; &#160; void setup&#40;&#41; &#123; // load images bg = loadImage&#40;&#34;kitchen.png&#34;&#41;; sprite_sheet &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/" title="OpenPixels: simple sprite sheet with Processing"></a><p style="text-align: center;"><img class="size-full wp-image-3860 aligncenter" title="processing example runnig" src="http://silveiraneto.net/wp-content/uploads/2011/08/processing_example.png" alt="" width="494" height="603" /></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Openpixels example in Processing.
 * This simple example of how to get a sprite 
 * from a sprite sheet.
 */</span>
&nbsp;
PImage bg<span style="color: #339933;">;</span>
PImage sprite_sheet<span style="color: #339933;">;</span>
PImage player<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #666666; font-style: italic;">// load images</span>
  bg <span style="color: #339933;">=</span> loadImage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;kitchen.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  sprite_sheet <span style="color: #339933;">=</span> loadImage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;guy.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/* The sprite size is 32x49.
     Look guy.png, the &quot;stand position&quot; is at (36,102). */</span>
&nbsp;
  player <span style="color: #339933;">=</span> createImage<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span>, <span style="color: #cc66cc;">49</span>, ARGB<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  player.<span style="color: #006633;">copy</span><span style="color: #009900;">&#40;</span>sprite_sheet, <span style="color: #cc66cc;">36</span>, <span style="color: #cc66cc;">102</span>, <span style="color: #cc66cc;">32</span>, <span style="color: #cc66cc;">49</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">32</span>, <span style="color: #cc66cc;">49</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// set screen size and background</span>
  size<span style="color: #009900;">&#40;</span>bg.<span style="color: #006633;">width</span>, bg.<span style="color: #006633;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  background<span style="color: #009900;">&#40;</span>bg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  background<span style="color: #009900;">&#40;</span>bg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  image<span style="color: #009900;">&#40;</span>player, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>See more at <a href="https://github.com/silveira/openpixels/tree/master/examples/processing">OpenPixels</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/08/22/openpixels-simple-sprite-sheet-with-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atiaia early releases</title>
		<link>http://silveiraneto.net/2011/07/23/atiaia-early-releases/</link>
		<comments>http://silveiraneto.net/2011/07/23/atiaia-early-releases/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 00:57:09 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Atiaia]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Marco Diego]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ray Tracying]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3841</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/07/23/atiaia-early-releases/" title="Atiaia early releases"></a>This was a project that me and Marco Diego created during our graduation for the Computer Graphics course. It is a ray tracing engine build from scratch in C. It was great exercise of experimentation on how implement object-oriented design &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/07/23/atiaia-early-releases/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/07/23/atiaia-early-releases/" title="Atiaia early releases"></a><p style="text-align: center;"><iframe width="640" height="510" src="http://www.youtube.com/embed/Jpk4vl48veY" frameborder="0" allowfullscreen></iframe></p>
<p>This was a project that me and <a href="http://plus.google.com/107875064284677597038/posts">Marco Diego</a> created during our graduation for the Computer Graphics course. It is a <a href="http://en.wikipedia.org/wiki/Ray_tracing_(graphics)">ray tracing</a> engine build from scratch in C. It was great exercise of experimentation on how implement object-oriented design patterns in ANSI C. Later Marco continued it in his master&#8217;s degree thesis implementing more features. </p>
<p>Parts of the sources were lost during a disk failure in the forge we hosted the project. I found some early releases and packed them here for future use. It can be useful for someone studying C or how to implement a ray tracer.</p>
<p><strong>Download:</strong> <a href='http://silveiraneto.net/wp-content/uploads/2011/07/atiaia_sources_by_2006.zip'>atiaia_sources_by_2006.zip</a></p>
<p>Enjoy it.</p>
<p>ps: with this project we won the 1st place project of class and maximum grade. ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/07/23/atiaia-early-releases/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android screen height and width</title>
		<link>http://silveiraneto.net/2011/03/12/android-screen-height-and-width/</link>
		<comments>http://silveiraneto.net/2011/03/12/android-screen-height-and-width/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 00:30:26 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[screensize]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3705</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/03/12/android-screen-height-and-width/" title="Android screen height and width"></a>Context ctx = getContext&#40;&#41;; Display display = &#40;&#40;WindowManager&#41;ctx.getSystemService&#40;ctx.WINDOW_SERVICE&#41;&#41;.getDefaultDisplay&#40;&#41;; int width = display.getWidth&#40;&#41;; int height = display.getHeight&#40;&#41;; Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/03/12/android-screen-height-and-width/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/03/12/android-screen-height-and-width/" title="Android screen height and width"></a>
<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Context</span> ctx <span style="color: #339933;">=</span> getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Display display <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>WindowManager<span style="color: #009900;">&#41;</span>ctx.<span style="color: #006633;">getSystemService</span><span style="color: #009900;">&#40;</span>ctx.<span style="color: #006633;">WINDOW_SERVICE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDefaultDisplay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> width <span style="color: #339933;">=</span> display.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> height <span style="color: #339933;">=</span> display.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be smaller, but this code is more general.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/03/12/android-screen-height-and-width/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: array, all elements but first</title>
		<link>http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/</link>
		<comments>http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 15:52:13 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array_shift]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3694</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/" title="PHP: array, all elements but first"></a>$bric = array&#40;&#34;Brazil&#34;, &#34;Russia&#34;, &#34;India&#34;, &#34;China&#34;&#41;; $ric = $bric; // array copy $br = array_shift&#40;$ric&#41;; // left shift at $ric. $br stores &#34;Brazil&#34; print_r&#40;$bric&#41;; // $bric remains the same print_r&#40;$ric&#41;; // $ric lost &#34;Brazil&#34; Output: Array &#40; &#91;0&#93; =&#62; Brazil &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/" title="PHP: array, all elements but first"></a>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$bric</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Brazil&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Russia&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;India&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;China&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$ric</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bric</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array copy</span>
<span style="color: #000088;">$br</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ric</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// left shift at $ric. $br stores &quot;Brazil&quot; </span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bric</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $bric remains the same</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ric</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $ric lost &quot;Brazil&quot;</span></pre></div></div>

<p>Output:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Brazil
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Russia
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> India
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> China
<span style="color: #009900;">&#41;</span>
<span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Russia
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> India
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> China
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Reference: <a href="http://php.net/manual/en/function.array-shift.php">PHP array_shift at php.net</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/03/09/php-array-all-elements-but-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: invoking a method by name</title>
		<link>http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/</link>
		<comments>http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 13:29:33 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3364</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/" title="Java: invoking a method by name"></a>import java.lang.reflect.*; &#160; public class Foo &#123; public void bar&#40;int param&#41;&#123; System.out.println&#40;param&#41;; &#125; &#160; public static void main&#40;String args&#91;&#93;&#41;&#123; Object f = new Foo&#40;&#41;; try &#123; Method m = f.getClass&#40;&#41;.getMethod&#40;&#34;bar&#34;, int.class&#41;; m.invoke&#40;f, 42&#41;; &#125; catch &#40;Exception e&#41;&#123; System.err.println&#40;e&#41;; &#125; &#125; &#8230;<p class="read-more"><a href="http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/" title="Java: invoking a method by name"></a><p><center><br />
<a href="http://silveiraneto.net/wp-content/uploads/2010/04/Film_star_Helen_Twelvetrees_ca_1936_7_photograph_by_Sam_Hood.jpg"><img src="http://silveiraneto.net/wp-content/uploads/2010/04/Film_star_Helen_Twelvetrees_ca_1936_7_photograph_by_Sam_Hood.jpg" alt="" title="Film_star_Helen_Twelvetrees_ca_1936_7_photograph_by_Sam_Hood" width="388" height="500" class="alignnone size-full wp-image-3365" /></a></center></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> bar<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> param<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&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><span style="color: #003399;">String</span> 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>
		<span style="color: #003399;">Object</span> f <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">Method</span> m <span style="color: #339933;">=</span> f.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bar&quot;</span>, <span style="color: #000066; font-weight: bold;">int</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			m.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>f, <span style="color: #cc66cc;">42</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p>$ java Foo<br />
42
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2010/04/29/java-invoking-a-method-by-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>calling commands in Java</title>
		<link>http://silveiraneto.net/2010/04/08/calling-commands-in-java/</link>
		<comments>http://silveiraneto.net/2010/04/08/calling-commands-in-java/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 16:09:11 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[getruntime]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3291</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2010/04/08/calling-commands-in-java/" title="calling commands in Java"></a>I don&#8217;t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import java.io.*; import java.util.*; public class Exec &#8230;<p class="read-more"><a href="http://silveiraneto.net/2010/04/08/calling-commands-in-java/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2010/04/08/calling-commands-in-java/" title="calling commands in Java"></a><p>I don&#8217;t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Exec <span style="color: #009900;">&#123;</span>
   <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><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">Process</span> proc <span style="color: #339933;">=</span> <span style="color: #003399;">Runtime</span>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">e</span> xec<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">BufferedReader</span> br <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>proc.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">String</span> line<span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> br.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Usage:</p>
<blockquote><p>java Exec VALID_COMMAND</p></blockquote>
<p>Example: </p>
<blockquote><p>$ java Exec echo hello<br />
hello</p></blockquote>
<p>ps: I had to write &#8220;e xec&#8221; instead of exec because it was triggering some very strange security protection in the blog engine here. If you need to compile this code change that. =P Also there&#8217;s no error handling, you should pass a valid command when executing this code.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2010/04/08/calling-commands-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterating over a HashMap</title>
		<link>http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/</link>
		<comments>http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 14:22:33 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[enhanced loop]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[hashmap]]></category>
		<category><![CDATA[iterating]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3288</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/" title="Iterating over a HashMap"></a>Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import java.util.Map; &#160; class Foo &#123;&#125; &#160; public class Main &#123; &#8230;<p class="read-more"><a href="http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/" title="Iterating over a HashMap"></a><p>Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.HashMap</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #009900;">&#123;</span>
&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><span style="color: #003399;">String</span> 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>
      Map<span style="color: #339933;">&lt;</span>Byte, Foo<span style="color: #339933;">&gt;</span> mHash<span style="color: #339933;">;</span>
&nbsp;
      mHash <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>Byte, Foo<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      mHash.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span><span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      mHash.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span><span style="color: #cc66cc;">2</span>, <span style="color: #000000; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      mHash.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span><span style="color: #cc66cc;">3</span>, <span style="color: #000000; font-weight: bold;">new</span> Foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Foo f<span style="color: #339933;">:</span> mHash.<span style="color: #006633;">values</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>f.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2010/04/08/iterating-over-a-hashmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting an Android app source</title>
		<link>http://silveiraneto.net/2010/03/18/getting-an-android-app-source/</link>
		<comments>http://silveiraneto.net/2010/03/18/getting-an-android-app-source/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 03:00:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3239</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2010/03/18/getting-an-android-app-source/" title="Getting an Android app source"></a>Getting the Android&#8217;s AlarmClock application source from official repositories: git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git To get the head version for an old platform like the 1.4 (codename donut), choose the correspondent branch using -o or &#8211;origin: git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git --origin donut]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2010/03/18/getting-an-android-app-source/" title="Getting an Android app source"></a><p style="text-align: center;"><img class="size-full wp-image-3236 aligncenter" title="Donut" src="http://silveiraneto.net/wp-content/uploads/2010/03/460307409_4e78c5dae4_flickr_donut.jpg" alt="" width="500" height="380" /></p>
<p>Getting the Android&#8217;s AlarmClock application source from official repositories:</p>
<pre>git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git</pre>
<p>To get the head version for an old platform like the 1.4 (codename donut), choose the correspondent branch using -o or &#8211;origin:</p>
<pre>git clone git://android.git.kernel.org/platform/packages/apps/AlarmClock.git --origin donut</pre>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2010/03/18/getting-an-android-app-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

