<?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>coding &#187; python</title>
	<atom:link href="http://www.coding.com.br/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coding.com.br</link>
	<description>have you coded today?</description>
	<lastBuildDate>Thu, 18 Aug 2011 17:29:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>sl4a &#8211; part one</title>
		<link>http://www.coding.com.br/android/sl4a-part-one/</link>
		<comments>http://www.coding.com.br/android/sl4a-part-one/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 17:22:15 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sl4a]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1756</guid>
		<description><![CDATA[SL4A stands for Scripting Layer for Android.
One of my deceptions with Android platform was the lack of Python support. Nokia (while supporting Symbian and Maemo) had a great commitment with Python support [audio]. In fact, SL4A isn&#8217;t just Python, it&#8217;s scripting language support for Android: it means that you can use: Lua, Perl, Rhino, TCL, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right;">SL4A stands for <strong>S</strong>cripting <strong>L</strong>ayer <strong>for</strong> <strong>A</strong>ndroid.</p>
<p style="text-align: justify;">One of my deceptions with Android platform was the lack of Python support. Nokia (while supporting Symbian and Maemo) had a great commitment with <a href="http://media.libsyn.com/media/awaretek/Python411_20100716_Nokia.mp3" target="_blank">Python support</a> [audio]. In fact, SL4A isn&#8217;t just Python, it&#8217;s scripting language support for Android: it means that you can use: Lua, Perl, Rhino, TCL, etc; even add your own. This is possible due it&#8217;s <a href="http://code.google.com/p/android-scripting/wiki/CodeStructure" target="_blank">design</a>:</p>
<p style="padding-left: 30px; text-align: justify;"><em>The heart of sl4a is the RPC. Each script that is started is given it&#8217;s own instance of the intepreter, a text screen (if started in foreground) and a tcp connection to an instance of the RPC. <strong>rpcHandling</strong> opens a socket, and listens for incoming requests (ie, api call). So, for example. droid.makeToast(&#8220;Hello&#8221;) is formed into a JSON packet. <strong>JsonRpcServer</strong> reads this, sees if it knows what method is being asked for, and passes it to the appropriate facade for processing. Every part of the API is managed by a facade. Each facade are compiled as seperate projects, with different platform targets [due SDK compatibility]. Then <em>JsonRpcServer runs through all the available facades, sees if they can run on the current platform, and puts them into the method list if so.</em></em></p>
<p style="text-align: justify;">Although a <em>alpha</em> quality software you can try in your device. To install SL4A go to <a href="http://code.google.com/p/android-scripting/downloads/list" target="_blank">download</a> page and get <strong>sl4a_rX.apk</strong> and <strong>PythonForAndroid_rX.apk</strong> [replace X to number  referenced by <span style="color: #008000;">Featured</span> label]. All my steps are focused on Python support but I guess that other script languages follow the same path.</p>
<p style="text-align: left;">Connect your device and install.</p>
<p style="text-align: left; padding-left: 30px;">$ <strong>adb install</strong> sl4a_rX.apk<br />
$ <strong>adb install</strong> PythonForAndroid_rX.apk</p>
<p style="text-align: left;">
<p style="text-align: center; padding-left: 30px;"><img class="aligncenter" src="http://farm7.static.flickr.com/6069/6046843648_1f51fa5daf.jpg" alt="" width="500" height="300" /></p>
<p style="text-align: justify;">Follow the steps on device you&#8217;ll need a network connection to finish the process. Open PythonForAndroid on your device and click on <em>Install</em> [this will download all necessary packages]. After you&#8217;ll see:</p>
<p style="text-align: center; padding-left: 30px;">&#8230;.<img class="aligncenter" src="http://farm7.static.flickr.com/6190/6046843686_bf633deb5d.jpg" alt="" width="500" height="300" /></p>
<div id="_mcePaste">Next let&#8217;s create a simple test to check if it&#8217;s working, open your favorite text editor and type:</div>
<div style="padding-left: 30px;"><strong>import</strong> android</div>
<div id="_mcePaste" style="padding-left: 30px;">droid = android.Android()</div>
<div id="_mcePaste" style="padding-left: 30px;">droid.makeToast(&#8220;<span style="color: #ff0000;">Hello, Android</span>&#8220;)</div>
<div style="padding-left: 30px;">print &#8220;Hello world!&#8221;</div>
<p style="text-align: left;">Save as <a href="https://raw.github.com/gist/1145715/0b110b918c334846a42226ce1c46a03a72e30f97/1st.py" target="_blank">1st.py</a> and copy to your phone:</p>
<p style="text-align: left; padding-left: 30px;">$ <strong>adb push</strong> 1st.py /sdcard/sl4a/scripts</p>
<p style="text-align: left;">Select the <em>console</em> logo do start (you can use <em>engine </em>logo too but without console output)</p>
<p style="text-align: center;"><img class="alignleft" src="http://farm7.static.flickr.com/6183/6047371528_8f156a37d8.jpg" alt="" width="300" height="500" /> <img class="alignnone" src="http://farm7.static.flickr.com/6196/6047371572_a58a31be09.jpg" alt="" width="300" height="500" /></p>
<p style="text-align: left;">Also you can choose run script from your host computer.</p>
<p style="text-align: left; padding-left: 30px;">$ adb shell am start -a com.googlecode.android_scripting.action.LAUNCH_FOREGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/1st.py</p>
<p style="text-align: left;">
<p style="text-align: left;">Now you can start write some Python code that will run on Android device. Check <a href="http://www.mithril.com.au/android/doc/" target="_blank">API reference</a> for possibilities.</p>
<h5>This was a introduction text about SL4A necessary to describe my learning process and some cool things that you can do. Wait for the next posts.</h5>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/android/sl4a-part-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>avoid typos with dd wrapper</title>
		<link>http://www.coding.com.br/gnu/avoid-typos-with-dd-wrapper/</link>
		<comments>http://www.coding.com.br/gnu/avoid-typos-with-dd-wrapper/#comments</comments>
		<pubDate>Sat, 23 Jul 2011 18:08:30 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[gnu]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1732</guid>
		<description><![CDATA[When using dd it&#8217;s very common typos that f*ck your important data. I create this 5-minutes python code do wrapper dd and make my life more safe. The usage is simple, just a config file with partition(s) you should avoid. Suppose that you have 2 disks in your computer and want avoid playing both with [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">When using <a href="http://en.wikipedia.org/wiki/Dd_%28Unix%29" target="_blank">dd</a> it&#8217;s <em>very common</em> typos that f*ck your important data. I create this 5-minutes python code do wrapper dd and make my life more safe. The usage is simple, just a config file with partition(s) you should avoid. Suppose that you have 2 disks in your computer and want avoid playing both with dd.</p>
<p style="padding-left: 30px;">$ echo /dev/sda &gt; ~/.blocklist-dd<br />
$ echo /dev/sdb &gt;&gt; ~/.blocklist-dd</p>
<p style="text-align: justify;">Then run you dd wrapper, I choose call my code &#8220;cc&#8221; (near dd in keyboard layout) and associate in $PATH environment.</p>
<p style="padding-left: 30px;">$ wget https://raw.github.com/gist/1100234/b59055e9ab1e3db8ab9d8185287852330d30e777/cc<br />
$ chmod +x cc</p>
<p style="text-align: justify;">And use &#8220;dd&#8221; normally. Bellow we have a correct example to backup MBR. Since /dev/sda is on our blacklist you need  confirm the operation.</p>
<p style="padding-left: 30px;">$ <strong>cc if=/dev/sda of=mbr.img bs=1 count=512</strong><br />
ooops, you are associating a blocked device (/dev/sda) on dd, proceed? (Y/n)<br />
Y<br />
512+0 records in<br />
512+0 records out<br />
512 bytes (512 B) copied, 0.00221805 s, 231 kB/s</p>
<p style="text-align: justify;">Sometimes adding a layer of complexity sometimes could simplify your life.</p>
<p style="text-align: justify;">Code is <a href="https://gist.github.com/1100234" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/gnu/avoid-typos-with-dd-wrapper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SCP with paramiko</title>
		<link>http://www.coding.com.br/sysadmin/scp-with-paramiko/</link>
		<comments>http://www.coding.com.br/sysadmin/scp-with-paramiko/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 23:35:51 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1716</guid>
		<description><![CDATA[This week I needed update some files on remote hosts. rsync is the tool when you need synchronize your files with a remote directory but I tried to use a different approach: a small Python script to transfer files on the same way scp do. I used paramiko module do access different hosts and transfer [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This week I needed update some files on remote hosts. <strong>rsync</strong> is the tool when you need synchronize your files with a remote directory but I tried to use a different approach: a small Python script to transfer files on the same way scp do. I used <a href="http://www.lag.net/paramiko/" target="_blank">paramiko</a> module do access different hosts and transfer a bunch of files, based on this <a href="http://www.stillhq.com/python/paramiko/000001.html">example</a>:</p>
<p><script src="https://gist.github.com/1006704.js?file=send-scp.py"></script></p>
<p><strong>Note:</strong> I used this approach because I&#8217;m transferring few files, <a href="http://blogs.oracle.com/janp/entry/how_the_scp_protocol_works">it&#8217;s not a good idea </a>use this technique with many files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/sysadmin/scp-with-paramiko/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unnamed files</title>
		<link>http://www.coding.com.br/gnu/unnamed-files/</link>
		<comments>http://www.coding.com.br/gnu/unnamed-files/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 00:18:02 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[gnu]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1449</guid>
		<description><![CDATA[
I&#8217;m a heavy user of command line interface and often named files without extension. This behavior forces me to use file utility every time I have doubts.
$ file stick-note1
stick-note1: ASCII text
When organizing my home/ I came across with many files like that, so I decided make this script to walk throughout files and check if it&#8217;s text file [...]]]></description>
			<content:encoded><![CDATA[<div>
<p style="text-align: justify;">I&#8217;m a heavy user of <em>command line interface </em>and often named files without extension. This behavior forces me to use <strong>file </strong>utility every time I have doubts.</p>
<div id="_mcePaste" style="padding-left: 30px; text-align: justify;">$ file stick-note1</div>
<div id="_mcePaste" style="padding-left: 30px;">stick-note1: ASCII text</div>
<p style="text-align: justify;">When organizing my <em>home/</em> I came across with many files like that, so I decided make this script to walk throughout files and check if it&#8217;s text file without extension and put .txt after.</p>
<p style="text-align: center;"><a href="http://gist.github.com/raw/572801/382091bf34aa449d8fc0e21a36d48a4a61b084ff/name.py" target="_blank">download script</a></p>
<p>$ python names.py<br />
This only change the file on current directory and it&#8217;s a &#8220;works for me&#8221; approach. Adapt to your needs.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/gnu/unnamed-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IP representation</title>
		<link>http://www.coding.com.br/programacao/ip-representation/</link>
		<comments>http://www.coding.com.br/programacao/ip-representation/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 03:58:03 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[programação]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1334</guid>
		<description><![CDATA[Yesterday I came across with an interesting contruction for IP address. Suppose that you want store the address &#8216;192.168.10.33&#8242; no matter the dot.
192&#60;&#60;24&#124;168&#60;&#60;16&#124;10&#60;&#60;8&#124;33
That produces
3232238113 (0xc0a80a21)
To return is just get the address in hex format and split in 4 sections. Means that: c0 (192) a8  (168) 0a (10) 21 (33). An example using Python generators to [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Yesterday I came across with an interesting contruction for IP address. Suppose that you want store the address &#8216;192.168.10.33&#8242; no matter the dot.</p>
<p style="text-align: center;"><strong>192</strong>&lt;&lt;24|<strong>168</strong>&lt;&lt;16|<strong>10</strong>&lt;&lt;8|<strong>33</strong></p>
<p>That produces</p>
<p style="text-align: center;">3232238113 (0xc0a80a21)</p>
<p style="text-align: justify;">To return is just get the address in hex format and split in 4 sections. Means that: c0 (192) a8  (168) 0a (10) 21 (33). An example using Python generators to return using <em>big endian</em> format (<a href="http://gist.github.com/514917">download</a>).</p>
<p><span style="color: #2040a0;">def</span> <span style="color: #2040a0;">octet</span><span style="color: #4444ff;">(</span><span style="color: #2040a0;">ip</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span><br />
<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for</strong> <span style="color: #2040a0;">i</span> <strong>in</strong> <span style="color: #2040a0;">range</span><span style="color: #4444ff;">(</span><span style="color: #4444ff;">-</span><span style="color: #ff0000;">24</span>,<span style="color: #ff0000;">8</span>,<span style="color: #ff0000;">8</span><span style="color: #4444ff;">)</span><span style="color: #4444ff;">:</span><br />
<span style="color: #2040a0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yield</span> <span style="color: #2040a0;">ip</span> <span style="color: #4444ff;">&gt;</span><span style="color: #4444ff;">&gt;</span> <span style="color: #4444ff;">-</span><span style="color: #2040a0;">i</span> <span style="color: #4444ff;">&amp;</span> <span style="color: #ff0000;">0xff</span></p>
<p>And got each value:</p>
<p style="padding-left: 30px;">r = octet(ip)<br />
r.next() # returns 192<br />
r.next() # returns 168<br />
r.next() # returns 10<br />
r.next() # returns 33</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/programacao/ip-representation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embed Python inside Latex</title>
		<link>http://www.coding.com.br/linux/embed-python-inside-latex/</link>
		<comments>http://www.coding.com.br/linux/embed-python-inside-latex/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 19:37:53 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1141</guid>
		<description><![CDATA[After a video demostrating the use of Python inside a Tex document. I decided to do a document explaining how to use,  check it:
Embed Python Inside Latex (pdf ~ 100KB)

Update: I also published online through Scribd, check here.

]]></description>
			<content:encoded><![CDATA[<p>After a <a href="http://www.youtube.com/watch?v=e0SSxA1xbaA" target="_blank">video</a> demostrating the use of Python inside a Tex document. I decided to do a document explaining how to use,  check it:</p>
<p style="text-align: center;"><a href="http://www.coding.com.br/wp-content/uploads/2010/07/embed_python_latex.pdf">Embed Python Inside Latex</a> (<em>pdf</em> ~ <em>100KB</em>)</p>
<p style="text-align: center;">
<p style="text-align: left;"><span style="color: #ff0000;">Update:</span> I also published online through Scribd, check <a href="http://www.scribd.com/doc/34332481/Embed-Python-Latex" target="_blank">here</a>.</p>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/linux/embed-python-inside-latex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opcode stats</title>
		<link>http://www.coding.com.br/embarcado/opcode-stats/</link>
		<comments>http://www.coding.com.br/embarcado/opcode-stats/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 00:09:50 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[arm]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=1128</guid>
		<description><![CDATA[I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses .s output and put in a human readable way. Suppose the classical Hello World program. The output will be something like:
$ python stats_opcodes.py file
For Cortex-m3 (check previous post):

At my laptop (x86):

 

Download the script here.
]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I was trying some GCC options and decided see how they affect assembly code generated. I&#8217;ve created a simple Python script that parses <em>.s</em> output and put in a human readable way. Suppose the classical <em>Hello World </em>program. The output will be something like:</p>
<p style="padding-left: 30px;">$ python stats_opcodes.py file</p>
<p>For Cortex-m3 (check <a href="http://www.coding.com.br/embarcado/cortex-m3-and-qemu/" target="_blank">previous</a> post):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1136" title="opcode-arm" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcode-arm.png" alt="" width="304" height="194" /></p>
<p>At my laptop (x86):</p>
<p style="padding-left: 30px;"><img class="aligncenter size-full wp-image-1133" title="output" src="http://www.coding.com.br/wp-content/uploads/2010/06/opcodes1.png" alt="" width="306" height="194" /></p>
<p><span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: small;"><span style="line-height: 18px; white-space: pre;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal;"> </span></span></span></span></p>
<p style="text-align: center;">
<p>Download the script <a href="http://gist.github.com/raw/452170/db097f735c52ffd733d2060603c203982d53b79f/stats_opcode.py" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/opcode-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyHDL: trazendo o Python para o mundo das FPGAs</title>
		<link>http://www.coding.com.br/embarcado/myhdl-trazendo-o-python-para-o-mundo-das-fpgas/</link>
		<comments>http://www.coding.com.br/embarcado/myhdl-trazendo-o-python-para-o-mundo-das-fpgas/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 03:38:01 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[embarcado]]></category>
		<category><![CDATA[fpga]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[verilog]]></category>
		<category><![CDATA[vhdl]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=876</guid>
		<description><![CDATA[From Python to silicon
Depois de uma longa história estou participando de dois um curso aberto sobre hardware: um abordando VHDL e outro Verilog. Até aí nada de novo, quando&#8230; descobri algo interessante. Algo que realmente motivou a mudar minha rotina de trabalho para (durante alguns dias) levantar as 7h. a escrever sobre o assunto aqui [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right;">From Python to silicon</p>
<p style="text-align: justify;"><em>Depois de uma longa história estou participando de <span style="text-decoration: line-through;">dois</span></em><em> um </em><em><a href="http://www.inatel.br/icc/cursos-abertos">curso aberto</a></em><em> sobre hardware: um abordando </em><a href="http://en.wikipedia.org/wiki/VHDL"><em>VHDL</em></a><em> </em><em><span style="text-decoration: line-through;">e outro </span></em><a href="http://en.wikipedia.org/wiki/Verilog"><em><span style="text-decoration: line-through;">Verilog</span></em></a><em>. Até aí nada de novo,</em><em> quando&#8230; </em><a href="http://twitter.com/maluta/status/11915212954" target="_blank"><em>descobri</em></a><em> algo interessante. Algo que realmente motivou <span style="text-decoration: line-through;">a mudar minha rotina de trabalho para (durante alguns dias)</span></em><em><span style="text-decoration: line-through;"> levantar as 7h.</span> a escrever sobre o assunto aqui no blog. :p</em></p>
<p style="text-align: justify;"><em><span style="font-style: normal;"><strong>MyHDL</strong></span></em></p>
<p style="text-align: justify;">Em poucas palavras, é um pacote para o Python que permite utilizá-lo para descrever e verificar uma linguagem de descrição de <em>hardware</em>. Além disso você pode converter seu código Pyhton em Verilog ou VHDL, automaticamente, para gravar numa CPLD ou FPGA. Para quem quiser aprender, o tutorial mais completo está na <a href="http://www.myhdl.org/doc/0.6" target="_blank">documentação</a> oficial do projeto. Há também uma <a href="http://www.cin.ufpe.br/~cinlug/wiki/index.php/Hardware_myhdl_python" target="_blank">introdução</a> muito boa em português feito pela UFPE.</p>
<p style="text-align: justify;">Não vou fazer um tutorial, apenas transcreverei os exemplos utilizados em sala de aula para Pythom, produzir os testes e os equivalentes em VHDL e Verilog. Um dos primeiros exercícios era descrever um multiplexador de 4 entradas.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> myhdl <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>  
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> Mux<span style="color: black;">&#40;</span>dout, din_1, din_2, din_3, din_4, sel<span style="color: black;">&#41;</span>:
&nbsp;
	@always_comb
	<span style="color: #ff7700;font-weight:bold;">def</span> muxLogic<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">if</span> sel == 0x0:
			 dout.<span style="color: black;">next</span> = din_1
		<span style="color: #ff7700;font-weight:bold;">if</span> sel == 0x1:
			 dout.<span style="color: black;">next</span> = din_2
		<span style="color: #ff7700;font-weight:bold;">if</span> sel == 0x2:
			 dout.<span style="color: black;">next</span> = din_3
		<span style="color: #ff7700;font-weight:bold;">if</span> sel == 0x3:
			 dout.<span style="color: black;">next</span> = din_4
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> muxLogic
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> convert<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	dout, din_1, din_2, din_3, din_4  = <span style="color: black;">&#91;</span>Signal<span style="color: black;">&#40;</span>intbv<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">8</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
	sel =   Signal<span style="color: black;">&#40;</span>intbv<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
	toVHDL<span style="color: black;">&#40;</span>Mux, din_1, din_2, din_3, din_4, dout, sel<span style="color: black;">&#41;</span>
	toVerilog<span style="color: black;">&#40;</span>Mux, din_1, din_2, din_3, din_4, dout, sel<span style="color: black;">&#41;</span>
&nbsp;
convert<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p style="text-align: justify;">As funções <em>toVHDL()</em> e <em>toVerilog()</em> produzem arquivos Mux.vhd ou Mux.v respectivamente (o nome é o mesmo da função definida).</p>
<p style="text-align: justify;">Aguardem os próximos <em>posts</em> onde vou apresentar o <em>test case</em> para este e os novos exercícios que forem sugeridos em sala.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/embarcado/myhdl-trazendo-o-python-para-o-mundo-das-fpgas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Primeiras impressões de uso do XCode com PyObjC</title>
		<link>http://www.coding.com.br/mac/primeiras-impressoes-de-uso-do-xcode-com-pyobjc/</link>
		<comments>http://www.coding.com.br/mac/primeiras-impressoes-de-uso-do-xcode-com-pyobjc/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 20:36:10 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[pyobjc]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=810</guid>
		<description><![CDATA[Estou utilizando o Mac OS X a pouco tempo com a intenção de aprender um pouco da programação de interface gráficas. Uma opção é utilizar o Qt que é multi-plataforma, mas resolvi fazer um teste com o que a Apple tem a oferecer. Minha escolha inicial para pegar a &#8220;idéia&#8221; foi partir de alguma coisa [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Estou utilizando o Mac OS X a pouco tempo com a intenção de aprender um pouco da programação de interface gráficas. Uma opção é utilizar o Qt que é multi-plataforma, mas resolvi fazer um teste com o que a Apple tem a oferecer. Minha escolha inicial para pegar a &#8220;idéia&#8221; foi partir de alguma coisa que eu já sei, para isso escolhi o <em>binding</em> PyObjC para criar aplicativos utilizando Python.</p>
<p style="text-align: justify;">O primeiro problema que eu resolvi relativamente rápido foi a questão dos templates para criar um novo projeto em PyObjC. A versão que utilizo do XCode (3.2.1) não instala automaticamente, siga os passos <a href="http://ioanna.me/2009/09/installing-pyobjc-xcode-templates-in-snow-leopard/" target="_blank">aqui</a>.</p>
<p style="text-align: justify;">Resolvi fazer um programa bem simples para converter um número na base decimal para base hexadecimal. Isso em Python é feito com meia linha de código, mas o objetivo aqui é aprender como os componentes gráficos são acessados no código. Aprendi duas coisas importantes: <strong>outlets</strong> e <strong>actions</strong>.</p>
<p style="text-align: justify;">No Interface Builder assim como no Qt Designer não fazemos código e sim a tela. Em alguns tutoriais você pode encontrar referência a interface gráfica como um arquivo com a extensão .nib contudo as versões mais novas possuem a extensão .xib (procurando diferenças, li que o .xib gera um XML ao passo que o .nib não) <a href="http://www.coding.com.br/wp-content/uploads/2010/03/hex.png"><br />
<img class="aligncenter size-full wp-image-813" title="hex" src="http://www.coding.com.br/wp-content/uploads/2010/03/hex.png" alt="" width="163" height="232" /></a></p>
<p>O código que irá tratar dos componentes na janela é o arquivo AppDelegate (ex.: <em>NomeDoProjeto</em>AppDelegate.py). Na janela Library ( Tools -&gt; Library ) selecionamos a aba Classes e procuramos pela classe AppDelegate.<br />
<center><br />
<div id="attachment_814" class="wp-caption aligncenter" style="width: 258px"><a href="http://www.coding.com.br/wp-content/uploads/2010/03/outlet.png"><img class="size-medium wp-image-814" title="outlet" src="http://www.coding.com.br/wp-content/uploads/2010/03/outlet-248x300.png" alt="" width="248" height="300" /></a><p class="wp-caption-text">Acesso as duas edits</p></div><br />
</center><br />
Observe que esse processo de criação da interface gráfica no IB é independente da linguagem escolhida.<br />
<center><br />
<div id="attachment_815" class="wp-caption aligncenter" style="width: 259px"><a href="http://www.coding.com.br/wp-content/uploads/2010/03/action.png"><img class="size-medium wp-image-815" title="action" src="http://www.coding.com.br/wp-content/uploads/2010/03/action-249x300.png" alt="" width="249" height="300" /></a><p class="wp-caption-text">A action é equivalente ao SLOT() no Qt</p></div></center></p>
<p style="text-align: justify;">A parte das conexões são feitas segurando o control e clicando no cubo azul (na janela MainMenu.xib) da classe AppDelagete e arrastando até o componente que você deseja utilizar. Atenção na ordem:</p>
<ul style="text-align: justify;">
<li>Outlets das caixas de texto:  clique no cubo e arraste para o componente, para cada selecione o <em>outlet</em> apropriado.</li>
<li>Action do botão: clique no botão e arraste para o cubo, selecione a <em>action</em> apropriada</li>
</ul>
<p style="text-align: justify;">A parte que e gastei um tempo foi para acessar os <em>outlets</em>, mas depois de ver a opção <em>Write Update Class Files </em>o problema foi resolvido (se você já escreveu alguma no código na classe Int2HexAppDelegate.py opte pelo <em>Merge</em> senão pelo <em>Replace</em>)</p>
<p style="text-align: center;"><a href="http://www.coding.com.br/wp-content/uploads/2010/03/write.png"><img class="aligncenter size-medium wp-image-822" title="write" src="http://www.coding.com.br/wp-content/uploads/2010/03/write-179x300.png" alt="" width="179" height="300" /></a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> Foundation <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">from</span> AppKit <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">import</span> objc
<span style="color: #ff7700;font-weight:bold;">class</span> Int2HexAppDelegate <span style="color: black;">&#40;</span>NSObject<span style="color: black;">&#41;</span>:
    edit_hexa = objc.<span style="color: black;">IBOutlet</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    edit_int = objc.<span style="color: black;">IBOutlet</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    @objc.<span style="color: black;">IBAction</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> converte_<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, sender<span style="color: black;">&#41;</span>:
	    valor_int = <span style="color: #008000;">self</span>.<span style="color: black;">edit_int</span>.<span style="color: black;">intValue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	    valor_hexa = <span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>valor_int<span style="color: black;">&#41;</span>
	    <span style="color: #008000;">self</span>.<span style="color: black;">edit_hexa</span>.<span style="color: black;">setStringValue_</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>valor_hexa<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p style="text-align: justify;">Esse código é bem simples para mostrar o conceito e também porque eu por enquanto não saberia fazer nada muito mais complexo que isso :p</p>
<p style="text-align: justify;">
O acesso as caixas de texto é feita pelas variáveis (outlet) <em>edit_hexa</em> e <em>edit_int</em> e a ação converte_ (lembre-se que o converte: do ObjectiveC vira converte_ no Python)</p>
<p style="text-align: justify;">Fiz um screencast desse exemplo, disponível no <a href="http://www.youtube.com/watch?v=GZ1du3x07JI" target="_blank">Youtube</a> (como estava testando um <em>trial</em> do programa desculpem pela marca d&#8217;agua no video, selecione a qualidade de 720p, depois descobri que o QuickTime faz screencast mas já tinha feito <img src='http://www.coding.com.br/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  )</p>
<p>Espero que ajude quem pretende começar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/mac/primeiras-impressoes-de-uso-do-xcode-com-pyobjc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Download photos from Flickr!</title>
		<link>http://www.coding.com.br/programacao/download-photos-from-flickr/</link>
		<comments>http://www.coding.com.br/programacao/download-photos-from-flickr/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 01:35:22 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[programação]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=783</guid>
		<description><![CDATA[I think that one problem regarding creating a script to download photos form Flickr is getting copyrighted material. Suppose that you want all photos from Itajubá city. You can use Flickr API or an YQL request, as follows:
select * from flickr.photos.search where text="itajubá"
My first try to get license information was showing the pertinent part of [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I think that one problem regarding creating a <em>script</em> to download photos form Flickr is getting copyrighted material. Suppose that you want all photos from Itajubá city. You can use Flickr API or an YQL request, as follows:</p>
<pre>select * from flickr.photos.search where text="itajubá"</pre>
<p style="text-align: justify;">My first try to get license information was showing the pertinent part of JSON output. You could see that there isn&#8217;t a field telling that, but if you look at documentation there&#8217;s a &#8220;license&#8221; parameter.</p>
<blockquote><p>&#8220;farm&#8221;: &#8220;5&#8243;,<br />
&#8220;id&#8221;: &#8220;4458853758&#8243;,<br />
&#8220;isfamily&#8221;: &#8220;0&#8243;,<br />
&#8220;isfriend&#8221;: &#8220;0&#8243;,<br />
&#8220;ispublic&#8221;: &#8220;1&#8243;,<br />
&#8220;owner&#8221;: &#8220;76062736@N00&#8243;,<br />
&#8220;secret&#8221;: &#8220;9edcd7aea8&#8243;,<br />
&#8220;server&#8221;: &#8220;4003&#8243;,<br />
&#8220;title&#8221;: &#8220;Clube&#8221;</p></blockquote>
<p>Flickr! has seven options to licensing your photo (again I didn&#8217;t found in documentation, I tried each one)</p>
<ul>
<li>None (All rights reserved) [ license="0" ]</li>
<li>Attribution-NonCommercial-ShareAlike Creative Commons [ license="1" ]</li>
<li>Attribution-NonCommercial Creative Commons [ license="2" ]</li>
<li>Attribution-NonCommercial-NoDerivs Creative Commons [ license="3" ]</li>
<li>Attribution Creative Commons [ license="4" ]</li>
<li>Attribution-ShareAlike Creative Commons [ license="5" ]</li>
<li>Attribution-NoDerivs Creative Commons [ license="6" ]</li>
</ul>
<p>My friend was looking to a way to download all photos from Yahoo! Open Hack Brazil so I decided to create a quick way to get theses photos (respecting copyrighted material). My <a href="http://developer.yahoo.com/yql/console/?q=select%20*%20from%20flickr.photos.search%20where%20text%3D%22Cat%22%20limit%200#h=select%20*%20from%20flickr.photos.search%280%2C2000%29%20where%20tags%3D%22brhackday%22%20and%20license%3D%221%2C2%2C3%2C4%2C5%2C6%22">query</a> looks like:</p>
<pre>select * from flickr.photos.search(0,2000) where tags="brhackday" and license="1,2,3,4,5,6"</pre>
<p style="text-align: justify;">After tests I put the URL from YQL virtual console in my Python code (that parses JSON) and generate a Shell Script to download (using curl/wget)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> simplejson
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span> 
&nbsp;
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;download.sh&quot;</span>,<span style="color: #483d8b;">&quot;w+&quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;#!/bin/sh<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
i = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
&nbsp;
	url_base=<span style="color: #483d8b;">&quot;http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.search(&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> 
+ <span style="color: #483d8b;">&quot;%2C&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span> +<span style="color: #483d8b;">&quot;)%20where%20tags%3D%22brhackday%22%20and%20license%3D%221%2C2%2C3%2C4%2C5%2C6%22
&amp;format=json&quot;</span> 	
&nbsp;
	rest = simplejson.<span style="color: black;">load</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url_base<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'query'</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> rest<span style="color: black;">&#91;</span><span style="color: #483d8b;">'count'</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'0'</span>:
		f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> 
&nbsp;
	photos = rest<span style="color: black;">&#91;</span><span style="color: #483d8b;">'results'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'photo'</span><span style="color: black;">&#93;</span> 
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> photo <span style="color: #ff7700;font-weight:bold;">in</span> photos:
		<span style="color: #008000;">id</span> = photo<span style="color: black;">&#91;</span><span style="color: #483d8b;">'id'</span><span style="color: black;">&#93;</span>
		owner = photo<span style="color: black;">&#91;</span><span style="color: #483d8b;">'owner'</span><span style="color: black;">&#93;</span>
		d = <span style="color: #483d8b;">&quot;curl -s http://www.flickr.com/photos/%s/%s/sizes/o 
| egrep <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;p&gt;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span> 
| sed 's/&lt;p&gt;//g ; s/&lt;br <span style="color: #000099; font-weight: bold;">\/</span>&gt;//g ; s/&lt;<span style="color: #000099; font-weight: bold;">\/</span>p&gt;//g ; s/&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>//g ; s/<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\/</span>&gt;//g' 
| xargs wget ;&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>owner, <span style="color: #008000;">id</span><span style="color: black;">&#41;</span>
		f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>d+<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
		i += <span style="color: #ff4500;">100</span>
&nbsp;
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p style="text-align: justify;">Probably If you cut &amp; paste the code they will not work due some indentation issue, so I published in gist <a href="http://gist.github.com/346413">here</a>.</p>
<p>The usage I simple:</p>
<pre>$ python flickr-d.py
$ sh download.sh</pre>
<p>This was a extremely simple workaround but I expect you enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/programacao/download-photos-from-flickr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
