<?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>the world is a pixel</description>
	<lastBuildDate>Sun, 08 Jan 2012 05:17:57 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<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[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 &#8220;bad&#8221; list (a list that can have another lists). If the element is not a [...]]]></description>
			<content:encoded><![CDATA[<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[/** * 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 = loadImage&#40;&#34;guy.png&#34;&#41;; &#160; /* The sprite size is 32x49. Look guy.png, the &#34;stand position&#34; is [...]]]></description>
			<content:encoded><![CDATA[<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 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;
PImage sprite_sheet;
PImage player;
&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>;
  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>;
&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>;
  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>, 0, 0, <span style="color: #cc66cc;">32</span>, <span style="color: #cc66cc;">49</span><span style="color: #009900;">&#41;</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>;
  background<span style="color: #009900;">&#40;</span>bg<span style="color: #009900;">&#41;</span>;
&nbsp;
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</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>;
  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: #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[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 patterns in ANSI C. Later Marco continued it in his master&#8217;s degree thesis implementing more [...]]]></description>
			<content:encoded><![CDATA[<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[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. You may already have the Context. WindowManager or the Display and so it would be [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_syntax">
<div class="code">
<pre class="java 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>;
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: #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: #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>;</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[$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 &#91;1&#93; =&#62; Russia &#91;2&#93; =&#62; India &#91;3&#93; =&#62; China &#41; Array &#40; &#91;0&#93; =&#62; Russia [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_syntax">
<div class="code">
<pre class="php 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: #000088;">$ric</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bric</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: #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: #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: #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 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:#800080;">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:#800080;">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[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; &#160; &#125; $ java Foo 42]]></description>
			<content:encoded><![CDATA[<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 java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.*</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: #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: #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>;
			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: #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: #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[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 &#123; public static void main&#40;String args&#91;&#93;&#41; throws IOException &#123; Process proc = Runtime.getRuntime&#40;&#41;.e xec&#40;args&#41;; BufferedReader [...]]]></description>
			<content:encoded><![CDATA[<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 java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</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: #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: #003399;">String</span> line;
      <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: #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[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; &#160; public static void main&#40;String args&#91;&#93;&#41;&#123; Map&#60;Byte, Foo&#62; mHash; &#160; mHash = new HashMap&#60;Byte, Foo&#62;&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<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 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: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</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;
&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>;
      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>;
      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>;
      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>;
&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: #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[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[<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>
		<item>
		<title>Getting enviroment information on Android</title>
		<link>http://silveiraneto.net/2010/03/16/getting-enviroment-information-on-android/</link>
		<comments>http://silveiraneto.net/2010/03/16/getting-enviroment-information-on-android/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 13:18:32 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[who am i]]></category>
		<category><![CDATA[whoami]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3226</guid>
		<description><![CDATA[This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users. Download: WhoAmI.tar.bz2 &#8211; Eclipse project. It&#8217;s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions. WhoAmI.apk &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple program I wrote called <strong>Who Am I</strong> that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users.</p>
<p style="text-align: center;"><img class="size-full wp-image-3227 aligncenter" title="whoami" src="http://silveiraneto.net/wp-content/uploads/2010/03/whoami.png" alt="" width="320" height="475" /></p>
<p><strong>Download</strong>:</p>
<ul>
<li><a href="http://silveiraneto.net/downloads/WhoAmI.tar.bz2">WhoAmI.tar.bz2</a> &#8211; Eclipse project. It&#8217;s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions.</li>
<li><a href="http://silveiraneto.net/downloads/WhoAmI.apk">WhoAmI.apk</a> &#8211; Application installation Android package.</li>
</ul>
<p>Main Activity source code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.silveiraneto.whoami</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Build</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span>;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> WhoAmI <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> EditText mEditor;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span>;
&nbsp;
        setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">whoami</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        mEditor <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">editor</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> properties <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.BOARD&quot;</span>, Build.<span style="color: #006633;">BOARD</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.BRAND&quot;</span>, Build.<span style="color: #006633;">BRAND</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.CPU_ABI&quot;</span>, Build.<span style="color: #006633;">CPU_ABI</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.DEVICE&quot;</span>, Build.<span style="color: #006633;">DEVICE</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.DISPLAY&quot;</span>, Build.<span style="color: #006633;">DISPLAY</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.FINGERPRINT&quot;</span>, Build.<span style="color: #006633;">FINGERPRINT</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.HOST&quot;</span>, Build.<span style="color: #006633;">HOST</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.ID&quot;</span>, Build.<span style="color: #006633;">ID</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.MANUFACTURER&quot;</span>, Build.<span style="color: #006633;">MANUFACTURER</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.MODEL&quot;</span>, Build.<span style="color: #006633;">MODEL</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.PRODUCT&quot;</span>, Build.<span style="color: #006633;">PRODUCT</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.TAGS&quot;</span>, Build.<span style="color: #006633;">TAGS</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.TIME&quot;</span>, Build.<span style="color: #006633;">TIME</span><span style="color: #009900;">&#125;</span>,
        	<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;Build.USER&quot;</span>, Build.<span style="color: #006633;">USER</span><span style="color: #009900;">&#125;</span>,
        <span style="color: #009900;">&#125;</span>;
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> prop<span style="color: #339933;">:</span> properties<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	mEditor.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%s: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, prop<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>, prop<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>And its Android Manifest:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;net.silveiraneto.whoami&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">android:label</span>=<span style="color: #ff0000;">&quot;Who Am I&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;activity</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;WhoAmI&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.intent.action.MAIN&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.intent.category.LAUNCHER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/activity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2010/03/16/getting-enviroment-information-on-android/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

