<?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>frafra.eu</title>
	<atom:link href="http://frafra.eu/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://frafra.eu</link>
	<description>Frantastico ;)</description>
	<lastBuildDate>Wed, 25 Aug 2010 22:42:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Programmare su Symbian con le QT</title>
		<link>http://frafra.eu/?p=201</link>
		<comments>http://frafra.eu/?p=201#comments</comments>
		<pubDate>Wed, 25 Aug 2010 22:32:53 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[QT]]></category>
		<category><![CDATA[Symbian]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Kiva]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=201</guid>
		<description><![CDATA[Per capire dove nasce questa idea, vi consiglio di leggere la prima e la seconda puntata Giusto questa sera, sono riuscito a fare il porting su Symbian della mia piccola applicazione C++/QT. Ecco come fare: Requisiti: dovete avere gcc/g++ installato, make, qmake, le librerie di sviluppo di libssl e zlib, wine, e un po&#8217; di [...]]]></description>
			<content:encoded><![CDATA[<p><em>Per capire dove nasce questa idea, vi consiglio di leggere <a href="http://frafra.eu/?p=186">la prima</a> e <a href="http://frafra.eu/?p=194">la seconda puntata</a> <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
<p>Giusto questa sera, sono riuscito a fare il porting su Symbian della mia piccola applicazione C++/QT. Ecco come fare:</p>
<p>Requisiti: dovete avere gcc/g++ installato, make, qmake, le librerie di sviluppo di libssl e zlib, wine, e un po&#8217; di pazienza <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In una cartella, scaricate:</p>
<ul>
<li>L&#8217;<a href="http://www.forum.nokia.com/Library/Tools_and_downloads/Other/Symbian_SDKs/">SDK per Symbian</a> &#8220;5th Edition&#8221;</li>
<li>Le <a href="http://brunoabinader.blogspot.com/2010/08/updated-unofficial-qt-for-symbian-463.html">QT per Symbian</a> (4.6.3)</li>
<li>Il file <a href="http://qdrive.net/index.php/page-file_share-choice-download_file-id_file-161544-ce-0">s60_open_c_cpp_plug_in_v1_6_en.zip</a></li>
<li>Il file <a href="http://www.codesourcery.com/public/gnu_toolchain/arm-none-symbianelf/gnu-csl-arm-2005Q1C-arm-none-symbianelf-i686-pc-linux-gnu.tar.bz2">gnu-csl-arm-2005Q1C-arm-none-symbianelf-i686-pc-linux-gnu.tar.bz2</a></li>
<li>Il file <a href="http://martin.st/symbian/gnupoc-package-1.15.tar.gz">gnupoc-package-1.15.tar.gz</a></li>
<li>Lo script <a href="http://franciscoalecrim.com/lizardo/gnupoc_1.15_installer_v2.sh">gnupoc_1.15_installer_v2.sh</a></li>
<li>Lo script <a href="http://franciscoalecrim.com/abinader/qt_for_symbian_4.6.3_all_in_one_linux_installer_v3.sh">qt_for_symbian_4.6.3_all_in_one_linux_installer_v3.sh</a></li>
<li><a href="http://get.qt.nokia.com/qt/solutions/qt-mobility-symbian-opensource-1.0.2.zip">QT Mobility</a> (1.0.2 &#8211; opzionale)</li>
</ul>
<p>A questo punto bisogna creare (in una posizione a piacimento della nostra home directory), la cartella &#8220;gnupoc&#8221;, contenente la cartella &#8220;qt&#8221;, che a sua volta deve contenere la cartella &#8220;bin&#8221;. Una volta creata questa struttura, bisogna avviare il primo script scaricato, in questo modo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> gnupoc_1.15_installer_v2.sh <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #007800;">$GNUPOC</span> <span style="color: #000000;">5.0</span></pre></div></div>

<p>&#8220;$GNUPOC&#8221; deve essere sostituito col percorso assoluto della cartella poco fa creata, senza slash (&#8220;/&#8221;) finale.  Se tutto è andato bene, vi dirà di dare un paio di comandi da terminale per impostare l&#8217;ambiente, ovvero:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$GNUPOC</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EPOCROOT</span>=<span style="color: #007800;">$GNUPOC</span><span style="color: #000000; font-weight: bold;">/</span>symbian-sdks<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5.0</span><span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>A questo punto aggiungiamo a $PATH anche il posto dove verranno installate le nuove QT, e avviamo il secondo script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$GNUPOC</span><span style="color: #000000; font-weight: bold;">/</span>qt<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span>
<span style="color: #c20cb9; font-weight: bold;">bash</span> qt_for_symbian_4.6.3_all_in_one_linux_installer_v1.sh <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #007800;">$GNUPOC</span><span style="color: #000000; font-weight: bold;">/</span>qt</pre></div></div>

<p>Se tutto è andato bene, ci verrà mostrato un messaggio analogo al precedente. Noi eseguiremo, per sicurezza, il secondo comando consigliato dallo script, ovvero:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">unset</span> QMAKESPEC</pre></div></div>

<p>Voilà! Adesso basta andare in un nostro progetto (ricordatevi di dare <strong>sempre</strong> i comandi &#8220;export&#8221; visti qui sopra, altrimenti non compilerete per Symbian), e digitare:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">qmake
<span style="color: #c20cb9; font-weight: bold;">make</span> debug-gcce
<span style="color: #c20cb9; font-weight: bold;">make</span> sis</pre></div></div>

<p>Vi ritroverete un file con estensione &#8220;.sis&#8221; pronto per essere installato sul vostro smartphone. Ovviamente su quest ultimo, dovrete installare anche le dipendenze. Queste (assieme a qualche programma di prova) sono presenti in &#8220;$GNUPOC/qt/&#8221;. Per installare le QT sul vostro cellulare, basta installare il file &#8220;qt_installer.sis&#8221;.</p>
<p>Ora, un paio di dritte:</p>
<ul>
<li>Nel vosto file progetto &#8220;.pro&#8221;, potrebbe essere utile creare una sezione dedicata alla compilazione su Symbian. Nel mio caso, volevo permettere alla mia applicazione di accedere ad internet, e quindi ho aggiunto la seguente linea:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">symbian:TARGET.CAPABILITY = NetworkServices</pre></div></div>

</li>
<li>Nei vostri file sorgente, potrebbe essere utile inserire una struttura di questo tipo:

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef Q_OS_SYMBIAN</span>
<span style="color: #808080; font-style: italic;">/* codice per Symbian */</span>
<span style="color: #339933;">#else</span>
<span style="color: #808080; font-style: italic;">/* codice per le altre piattaforme */</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>Ovviamente &#8220;#else&#8221; è opzionale.</li>
<li>Tenete conto che i cellulari hanno un monitor molto piccolo. Nel mio programma ho preferito quindi mostrare meno informazioni e lanciare il programma a schermo intero, con le seguenti istruzioni:

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#ifdef Q_OS_SYMBIAN</span>
    window.<span style="color: #202020;">showFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#else</span>
    window.<span style="color: #202020;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#endif</span></pre></div></div>

<p>Il fatto scomodo è che la chiusura, se non è presente un bottone o una voce dedicata nel menù, dovrà essere effettuata dalla barra di Symbian che mostra le applicazioni attive (tasto menù tenuto premuto per qualche attimo, selezionare l&#8217;applicazione, premere il tasto &#8220;c&#8221;).</li>
</ul>
<p>Per il resto che dirvi&#8230; Divertitevi! Vorrei ringraziare <a href="http://brunoabinader.blogspot.com/">brunoabinader.blogspot.com</a>, dal quale ho preso spunto per questa guida <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Il pacchetto contenente il mio programmino modificato per funzionare <em>anche</em> su Symbian è lo stesso della volta scorsa (ho aggiornato l&#8217;archivio): <a href="http://frafra.eu/wp-content/uploads/2010/08/kiva.tar.gz">kiva.tar.gz</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=201</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conversione Python/QT – C++/QT</title>
		<link>http://frafra.eu/?p=194</link>
		<comments>http://frafra.eu/?p=194#comments</comments>
		<pubDate>Wed, 25 Aug 2010 13:42:19 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[QT]]></category>
		<category><![CDATA[Symbian]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[QNetworkRequest]]></category>
		<category><![CDATA[QScriptEngine]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=194</guid>
		<description><![CDATA[Aggiornamento: ho fatto il porting su Symbian! (vedi post seguente) Nel precedente articolo ho mostrato un programma scritto in Python, che aveva la peculiarità di sfruttare esclusivamente le funzioni fornite da PyQT, facilitando così un porting verso C++/QT in futuro. Beh,  ho incominciato a riscrivere il programma ieri sera (grazie anche all&#8217;aiuto di Rief) e [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Aggiornamento:</strong> ho fatto il porting su Symbian! (vedi <a href="http://frafra.eu/?p=201">post seguente</a>) <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Nel <a href="http://frafra.eu/?p=186">precedente articolo</a> ho mostrato un programma scritto in Python, che aveva la peculiarità di sfruttare esclusivamente le funzioni fornite da PyQT, facilitando così un porting verso C++/QT in futuro. Beh,  ho incominciato a riscrivere il programma ieri sera (grazie anche all&#8217;aiuto di Rief) e l&#8217;ho finito nel primo pomeriggio di oggi, con ottimi risultati (ovvero: non ci sono regressioni). Il codice non è molto bello (ve l&#8217;ho detto, non sono un bravo programmatore C++), e alcune cose le avrei potute gestire meglio, ma vi ricordo che il mio intento fondamentale era semplicemente trascrivere il programma in un altro linguaggio, non stravolgendone la forma e lasciando invariate le funzioni e l&#8217;aspetto.</p>
<p>Non vi mostro il codice qui perché è lunghetto, e perché è spezzato su più files, quindi vi allego tutto in un <a href="http://frafra.eu/wp-content/uploads/2010/08/kiva.tar.gz">kiva.tar.gz</a>. Il file gui.ui che trovate nel pacchetto è lo stesso che è stato utilizzato sia per generare gui.h per l&#8217;applicativo in C++, sia per generare gui.py (allegato al post di ieri) per la versione pythonica.</p>
<p>Il prossimo passo è, ovviamente, il porting su Symbian <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=194</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Programma in PyQT con qualche spunto</title>
		<link>http://frafra.eu/?p=186</link>
		<comments>http://frafra.eu/?p=186#comments</comments>
		<pubDate>Tue, 24 Aug 2010 17:24:38 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[QT]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[Kiva]]></category>
		<category><![CDATA[QNetworkRequest]]></category>
		<category><![CDATA[QScriptEngine]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=186</guid>
		<description><![CDATA[Aggiornamento: alla fine ho riscritto il programma in C++ (vedi post seguente) Questo programma si interfaccia con le API di Kiva (una piattaforma online per finanziare i progetti di microcredito) e, dato un utente, visualizza i prestiti da lui finanziati. La particolarità sta nel fatto che non usa alcuna libreria propria di Python (ad esclusione [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Aggiornamento:</strong> alla fine ho riscritto il programma in C++ (vedi <a href="http://frafra.eu/?p=194">post seguente</a>) <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Questo programma si interfaccia con le API di <a href="www.kiva.org">Kiva</a> (una piattaforma online per finanziare i progetti di microcredito) e, dato un utente, visualizza i prestiti da lui finanziati. La particolarità sta nel fatto che non usa alcuna libreria propria di Python (ad esclusione di sys), ma esclusivamente PyQt4 (nello specifico: QtCore, QtGui, QtNetwork, QtScript). In parole povere, troverete che:</p>
<ol>
<li>Non è stato usato urllib per prendere i dati dal web, ma QNetworkRequest, in modo tale che l&#8217;interfaccia grafica non si blocchi durante le operazioni di caricamento.</li>
<li>Non è stato utilizzato il parser json dell&#8217;anonima libreria di Python, ma è stato analizzato il codice grazie a QScriptEngine. L&#8217;unico vantaggio ha riguardato la gestione degli errori.</li>
</ol>
<p>Perché ho voluto &#8220;farmi del male&#8221;? <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Semplice: dato che PySide non supporta ancora Symbian, ho deciso di scrivere il codice in Python nelle modalità appena mostrate, per poi riscriverlo in C++ e fare un bel pacchettino .sis da installare sul telefono <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Avrei potuto farlo direttamente in C++, ma dato che sono &#8220;arrugginito&#8221; non volevo mettere troppa carne al fuoco <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Qui sotto metterò il cuore del programma, mentre mi limiterò ad allegare il file <a href="http://dpaste.com/hold/233368/">gui.py</a> relativo all&#8217;interfaccia.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> gui <span style="color: #ff7700;font-weight:bold;">import</span> Ui_MainWindow
<span style="color: #ff7700;font-weight:bold;">from</span> PyQt4 <span style="color: #ff7700;font-weight:bold;">import</span> QtCore, QtGui, QtNetwork, QtScript
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Kiva<span style="color: black;">&#40;</span>QtGui.<span style="color: black;">QMainWindow</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
        QtGui.<span style="color: black;">QWidget</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, parent<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span> = Ui_MainWindow<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">setupUi</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">network</span> = QtNetwork.<span style="color: black;">QNetworkAccessManager</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">engine</span> = QtScript.<span style="color: black;">QScriptEngine</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = <span style="color: #483d8b;">&quot;&quot;</span>
        QtCore.<span style="color: black;">QObject</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">network</span>,
            QtCore.<span style="color: black;">SIGNAL</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;finished(QNetworkReply*)&quot;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">load</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        QtCore.<span style="color: black;">QObject</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">pushButton</span>,
            QtCore.<span style="color: black;">SIGNAL</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;clicked()&quot;</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">refresh</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> add<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, name, status, progress<span style="color: black;">&#41;</span>:
        row = <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">rowCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">insertRow</span><span style="color: black;">&#40;</span>row<span style="color: black;">&#41;</span>
        qstatus = QtGui.<span style="color: black;">QTableWidgetItem</span><span style="color: black;">&#40;</span>status<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">setItem</span><span style="color: black;">&#40;</span>row, <span style="color: #ff4500;">0</span>, qstatus<span style="color: black;">&#41;</span>
        progressBar = QtGui.<span style="color: black;">QProgressBar</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        progressBar.<span style="color: black;">setValue</span><span style="color: black;">&#40;</span>progress<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">setCellWidget</span><span style="color: black;">&#40;</span>row, <span style="color: #ff4500;">1</span>, progressBar<span style="color: black;">&#41;</span>
        qname = QtGui.<span style="color: black;">QTableWidgetItem</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">setItem</span><span style="color: black;">&#40;</span>row, <span style="color: #ff4500;">2</span>, qname<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, req, <span style="color: #66cc66;">**</span>attrs<span style="color: black;">&#41;</span>:
        url = QtCore.<span style="color: black;">QUrl</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://api.kivaws.org/v1%s.json&quot;</span> <span style="color: #66cc66;">%</span> req<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> key, value <span style="color: #ff7700;font-weight:bold;">in</span> attrs.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            url.<span style="color: black;">addQueryItem</span><span style="color: black;">&#40;</span>key, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>value<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">network</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>QtNetwork.<span style="color: black;">QNetworkRequest</span><span style="color: black;">&#40;</span>url<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> load<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, data<span style="color: black;">&#41;</span>:
        sc = <span style="color: #008000;">self</span>.<span style="color: black;">engine</span>.<span style="color: black;">evaluate</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;(%s)&quot;</span> <span style="color: #66cc66;">%</span> QtCore.<span style="color: black;">QString</span><span style="color: black;">&#40;</span>data.<span style="color: black;">readAll</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        current = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>sc.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;paging&quot;</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;page&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">toInteger</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        total = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>sc.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;paging&quot;</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;pages&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">toInteger</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> sc.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;loans&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">isArray</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            cursor = QtScript.<span style="color: black;">QScriptValueIterator</span><span style="color: black;">&#40;</span>sc.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;loans&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> current == <span style="color: #ff4500;">1</span>:
                <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">clearContents</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">setRowCount</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
            cursor.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">while</span> cursor.<span style="color: black;">hasNext</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                tmp = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> attr <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;status&quot;</span>, <span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#93;</span>:
                    tmp<span style="color: black;">&#91;</span>attr<span style="color: black;">&#93;</span> = cursor.<span style="color: black;">value</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span>attr<span style="color: black;">&#41;</span>.<span style="color: black;">toString</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #ff7700;font-weight:bold;">for</span> attr <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;funded_amount&quot;</span>, <span style="color: #483d8b;">&quot;loan_amount&quot;</span>, <span style="color: #483d8b;">&quot;paid_amount&quot;</span><span style="color: black;">&#93;</span>:
                    tmp<span style="color: black;">&#91;</span>attr<span style="color: black;">&#93;</span> = cursor.<span style="color: black;">value</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">property</span><span style="color: black;">&#40;</span>attr<span style="color: black;">&#41;</span>.<span style="color: black;">toInteger</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                cursor.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">parse</span><span style="color: black;">&#40;</span>tmp<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> current == total:
                text = <span style="color: #483d8b;">&quot;%d loan(s) loaded&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">tableWidget</span>.<span style="color: black;">rowCount</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">statusbar</span>.<span style="color: black;">showMessage</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">pushButton</span>.<span style="color: black;">setEnabled</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                text = <span style="color: #483d8b;">&quot;Page %d of %d loaded&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>current, total<span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">statusbar</span>.<span style="color: black;">showMessage</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/lenders/%s/loans&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span>, page = current+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">statusbar</span>.<span style="color: black;">showMessage</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;User %s not found&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">pushButton</span>.<span style="color: black;">setEnabled</span><span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> parse<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, loan<span style="color: black;">&#41;</span>:
        status = loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;status&quot;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> status <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;fundraising&quot;</span><span style="color: black;">&#93;</span>:
            progress = <span style="color: #ff4500;">100</span><span style="color: #66cc66;">*</span>loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;funded_amount&quot;</span><span style="color: black;">&#93;</span>/loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;loan_amount&quot;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> status <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;in_repayment&quot;</span>, <span style="color: #483d8b;">&quot;paid&quot;</span><span style="color: black;">&#93;</span>:
            progress = <span style="color: #ff4500;">100</span><span style="color: #66cc66;">*</span>loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;paid_amount&quot;</span><span style="color: black;">&#93;</span>/loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;loan_amount&quot;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> status == <span style="color: #483d8b;">&quot;defaulted&quot;</span>:
            progress = <span style="color: #ff4500;">0</span> <span style="color: #808080; font-style: italic;"># TODO: Is there a way to know paid_amount?</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> status == <span style="color: #483d8b;">&quot;refunded&quot;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #808080; font-style: italic;"># FIXME: what is that status?</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span>loan<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#93;</span>, status.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;_&quot;</span>, <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span>, progress<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> refresh<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">pushButton</span>.<span style="color: black;">setEnabled</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">name</span> = <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">lineEdit</span>.<span style="color: black;">text</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">ui</span>.<span style="color: black;">statusbar</span>.<span style="color: black;">showMessage</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Connecting...&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/lenders/%s/loans&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">self</span>.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
    app = QtGui.<span style="color: black;">QApplication</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>
    kiva = Kiva<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    kiva.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span>app.<span style="color: black;">exec_</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=186</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VP8 libero!</title>
		<link>http://frafra.eu/?p=177</link>
		<comments>http://frafra.eu/?p=177#comments</comments>
		<pubDate>Wed, 19 May 2010 19:20:42 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[vp8]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=177</guid>
		<description><![CDATA[VP8, il codec sviluppato da On2 Technologies, comprata mesi fa, è stato reso libero da royalities! Su Youtube i filmati che lo usano si stanno moltiplicando ogni attimo che passa, e i browser Chrome/Chromium, Firefox e Opera sono già stati rilascati in versione di testing col supporto a questo formato! Inoltre è stato lanciato webmproject.org, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/VP8">VP8</a>, il codec sviluppato da On2 Technologies, comprata mesi fa, è stato reso libero da royalities! Su Youtube i filmati che lo usano si stanno moltiplicando ogni attimo che passa, e i browser Chrome/Chromium, Firefox e Opera sono già stati rilascati in versione di testing col supporto a questo formato! Inoltre è stato lanciato <a href="http://www.webmproject.org">webmproject.org</a>, sito che vuole essere un punto di riferimento per siluppatori e utenti per tutto quelo che riguarda VP8.</p>
<p>Ecco dove trovare le ultime builds che lo supportano:</p>
<ul>
<li> Firefox (serie 3.7): <a href="http://nightly.mozilla.org/webm/">nightly.mozilla.org/webm/</a></li>
<li>Opera (serie 10.54): <a href="http://labs.opera.com/news/2010/05/19/">labs.opera.com/news/2010/05/19/</a></li>
<li>Chrome (trunk): <a href="http://build.chromium.org/buildbot/snapshots">build.chromium.org/buildbot/snapshots</a></li>
</ul>
<p>Per utilizzarlo in Youtube, bisogna abilitare la modalità HTML5 da: <a href="http://www.youtube.com/html5">www.youtube.com/html5 </a> Inoltre quando si fa una ricerca, bisogna aggiungere &#8220;&amp;webm=1&#8243; all&#8217;URL della pagina che si sta visitando. Questo risulterà inutile quando tutti i video saranno codificati nel nuovo formato.  I nuovi file video saranno così composti:</p>
<ul>
<li>Conteninore: <a href="http://it.wikipedia.org/wiki/Matroska">Matroska</a></li>
<li>Audio: <a href="http://it.wikipedia.org/wiki/Vorbis">Vorbis</a></li>
<li>Video: Vp8</li>
</ul>
<p>Ah, sono già arrivatele prime critiche <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  <a href="http://x264dev.multimedia.cx/?p=377">x264dev.multimedia.cx/?p=377</a> Comunque sia, oggi è un giorno da segnare sul calendario se si è amanti del web libero <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=177</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Webcam capovolta</title>
		<link>http://frafra.eu/?p=171</link>
		<comments>http://frafra.eu/?p=171#comments</comments>
		<pubDate>Sat, 13 Mar 2010 10:24:15 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[v4l]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=171</guid>
		<description><![CDATA[La mia webcam (ID 04f2:b036 Chicony Electronics Co., Ltd [uvcvideo]), funziona bene, ma ha un piccolo problema: si vede sottosopra Nello specifico il mio portatile è un Asus UL30A, ma immagino che la fix che ho trovato possa andare su tutti gli Asus della serie UL. Così, dopo avere cercato un po&#8217; su internet, ho [...]]]></description>
			<content:encoded><![CDATA[<p>La mia webcam (ID 04f2:b036 Chicony Electronics Co., Ltd [uvcvideo]), funziona bene, ma ha un piccolo problema: si vede sottosopra <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Nello specifico il mio portatile è un Asus UL30A, ma immagino che la fix che ho trovato possa andare su tutti gli Asus della serie UL.<br />
Così, dopo avere cercato un po&#8217; su internet, ho segnalato il tutto a hdegoede (at) redhat.com, allegando alla mail i files creati coi seguenti comandi (come root):</p>
<p><code>lsusb &gt; lsusb.log<br />
dmidecode &gt; dmi.log</code></p>
<p>Questo sviluppatore tiene una tabella delle webcam che soffrono di questo problema: proprio per questo motivo, ha bisogno di sapere quali modelli hanno bisogno di raddrizzare l&#8217;immagine.<br />
Mi ha risposto il giorno successivo, con <a href="http://pastebin.com/raw.php?i=GfQgyfcS">questa mail</a>, dove spiega come compilare la versione di test di v4l-utils, come installarla, e come utilizzarla <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Link: <a href="https://lists.berlios.de/pipermail/linux-uvc-devel/2009-June/004886.html">https://lists.berlios.de/pipermail/linux-uvc-devel/2009-June/004886.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=171</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Il mio codice Python è scritto bene?</title>
		<link>http://frafra.eu/?p=168</link>
		<comments>http://frafra.eu/?p=168#comments</comments>
		<pubDate>Tue, 10 Nov 2009 18:44:07 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[PEP 8]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=168</guid>
		<description><![CDATA[Chiedilo a pep8.py Per chi non lo sapesse, la PEP 8 è una specifica di Python che indica come si dovrebbe scrivere il codice (definisce come deve essere l&#8217;indentazione ecc.). Questo programma verifica se il codice scritto è conforme alla PEP 8 Link: http://github.com/jcrocholl/pep8/raw/master/pep8.py]]></description>
			<content:encoded><![CDATA[<p>Chiedilo a pep8.py <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Per chi non lo sapesse, la <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a> è una specifica di Python che indica come si dovrebbe scrivere il codice (definisce come deve essere l&#8217;indentazione ecc.).<br />
Questo programma verifica se il codice scritto è conforme alla PEP 8 <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Link: <a href="http://github.com/jcrocholl/pep8/raw/master/pep8.py">http://github.com/jcrocholl/pep8/raw/master/pep8.py</a></p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=168</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scaricare l&#8217;ultima versione di un certo programma</title>
		<link>http://frafra.eu/?p=164</link>
		<comments>http://frafra.eu/?p=164#comments</comments>
		<pubDate>Tue, 10 Nov 2009 18:34:40 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[sorgenti]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=164</guid>
		<description><![CDATA[Vi è mai capitato di dover (o voler) scaricare l&#8217;ultima versione di uno o più programmi? O sapere semplicemente se è stato rilasciato un aggiornamento? Bene, a Frafra queste cose capitano, soprattutto quando si parla di sorgenti, compilazione, e compagnia cantante Ho creato un programma Python (>= 3.x, testato su 3.1.1), che risolve automaticamente questo [...]]]></description>
			<content:encoded><![CDATA[<p>Vi è mai capitato di dover (o voler) scaricare l&#8217;ultima versione di uno o più programmi? O sapere semplicemente se è stato rilasciato un aggiornamento?<br />
Bene, a Frafra queste cose capitano, soprattutto quando si parla di sorgenti, compilazione, e compagnia cantante <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Ho creato un programma Python (>= 3.x, testato su 3.1.1), che risolve automaticamente questo problema, con l&#8217;uso di un parser e di un crawler <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Sono cento linee giuste giuste, parzialmente commentate, con tanto di licenza (questa volta metto il file per intero, perché in primo luogo ho raggiunto un numero di linee tondo tondo, e in secondo luogo perché la prima linea è molto importante).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python3</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># takeit.py</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Copyright 2009 Francesco Frassinelli &lt;fraph24@gmail.com&gt;</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;">#     This program is free software: you can redistribute it and/or modify</span>
<span style="color: #808080; font-style: italic;">#     it under the terms of the GNU General Public License as published by</span>
<span style="color: #808080; font-style: italic;">#     the Free Software Foundation, either version 3 of the License, or</span>
<span style="color: #808080; font-style: italic;">#     (at your option) any later version.</span>
<span style="color: #808080; font-style: italic;">#    </span>
<span style="color: #808080; font-style: italic;">#     This program is distributed in the hope that it will be useful,</span>
<span style="color: #808080; font-style: italic;">#     but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #808080; font-style: italic;">#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span style="color: #808080; font-style: italic;">#     GNU General Public License for more details.</span>
<span style="color: #808080; font-style: italic;">#    </span>
<span style="color: #808080; font-style: italic;">#     You should have received a copy of the GNU General Public License</span>
<span style="color: #808080; font-style: italic;">#     along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
&nbsp;
<span style="color: #483d8b;">&quot;&quot;&quot; This program shows you the latest version of a source package &quot;&quot;&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">### HTMLParser patched version, see: http://bugs.python.org/issue755660</span>
<span style="color: #808080; font-style: italic;"># $ cp /usr/local/lib/python3.1/html/parser.py HTMLParser.py</span>
<span style="color: #808080; font-style: italic;"># $ wget http://bugs.python.org/file13041/htmlparser_error.diff</span>
<span style="color: #808080; font-style: italic;"># $ patch -p0 HTMLParser.py &lt; htmlparser_error.diff</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">HTMLParser</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>, <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">urllib</span>.<span style="color: black;">request</span>
&nbsp;
servers = <span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">&quot;gnu&quot;</span>:<span style="color: #483d8b;">&quot;http://ftp.gnu.org/gnu/&quot;</span>,
    <span style="color: #483d8b;">&quot;linux&quot;</span>:<span style="color: #483d8b;">&quot;http://ftp.kernel.org/pub/linux/&quot;</span>,
    <span style="color: #483d8b;">&quot;vim&quot;</span>:<span style="color: #483d8b;">&quot;http://ftp.vim.org/pub/vim/unix/&quot;</span>,
<span style="color: black;">&#125;</span> <span style="color: #808080; font-style: italic;"># List of available servers: add yours and report test them</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Parser<span style="color: black;">&#40;</span><span style="color: #dc143c;">HTMLParser</span>.<span style="color: #dc143c;">HTMLParser</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, page, callback<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>Parser, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">callback</span> = callback
        <span style="color: #008000;">self</span>.<span style="color: black;">page</span> = page <span style="color: #808080; font-style: italic;"># Current page</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> handle_starttag<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, tag, attrs<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> tag == <span style="color: #483d8b;">&quot;a&quot;</span>:
            attrs = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span>attrs<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">&quot;href&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> attrs:
                <span style="color: #008000;">self</span>.<span style="color: black;">callback</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">page</span>, attrs<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;href&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> error<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, message<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span> <span style="color: #808080; font-style: italic;"># Overwriting default function, in order to skip any error</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Crawler:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">source</span> = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;&quot;&quot;^
            (.+?)-                  # package name
            ([<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\.</span>-]+)              # version
            <span style="color: #000099; font-weight: bold;">\.</span>(tar<span style="color: #000099; font-weight: bold;">\.</span>bz2|tar<span style="color: #000099; font-weight: bold;">\.</span>gz)    # compression
            $&quot;&quot;&quot;</span>, <span style="color: #dc143c;">re</span>.<span style="color: black;">VERBOSE</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># VERBOSE is for multiline commented regex</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">packages</span> = <span style="color: #008000;">dict</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #dc143c;">inspect</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, page<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;I'm in:&quot;</span>, page<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># If there're errors, report it *always*</span>
        <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #dc143c;">urllib</span>.<span style="color: black;">request</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>page<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">as</span> data:
            <span style="color: #dc143c;">parser</span> = Parser<span style="color: black;">&#40;</span>page, <span style="color: #008000;">self</span>.<span style="color: black;">callback</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">parser</span>.<span style="color: black;">feed</span><span style="color: black;">&#40;</span>data.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;utf_8&quot;</span>, <span style="color: #483d8b;">&quot;ignore&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">parser</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> item<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, page, link<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">source</span>.<span style="color: black;">match</span><span style="color: black;">&#40;</span>link<span style="color: black;">&#41;</span>:
            res = <span style="color: #008000;">self</span>.<span style="color: black;">source</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>link<span style="color: black;">&#41;</span>
            package, version, compression = res.<span style="color: black;">groups</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> package == <span style="color: #483d8b;">&quot;0&quot;</span>: <span style="color: #808080; font-style: italic;"># Should we use re.match(&quot;^\d+$&quot;, package)?</span>
                <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #808080; font-style: italic;"># Not properly detected: regex could be wrong</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> package <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">packages</span>:
                <span style="color: #008000;">self</span>.<span style="color: black;">packages</span><span style="color: black;">&#91;</span>package<span style="color: black;">&#93;</span> = <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">packages</span><span style="color: black;">&#91;</span>package<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>version, page + link<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> callback<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, page, link<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Special link / Backwards link / External link or absolute path</span>
        useless = <span style="color: #483d8b;">&quot;?&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> link <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;..&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> link <span style="color: #ff7700;font-weight:bold;">or</span> link.<span style="color: black;">count</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> useless:
            <span style="color: #ff7700;font-weight:bold;">if</span> link.<span style="color: black;">endswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;/&quot;</span><span style="color: black;">&#41;</span>:
                <span style="color: #008000;">self</span>.<span style="color: #dc143c;">inspect</span><span style="color: black;">&#40;</span>page + link<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Directory: recursive function</span>
            <span style="color: #ff7700;font-weight:bold;">else</span>:
                <span style="color: #008000;">self</span>.<span style="color: black;">item</span><span style="color: black;">&#40;</span>page, link<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># File: analize its name</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> results<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> package, version <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">packages</span>.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
            version, url = <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>version, reverse = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            <span style="color: #ff7700;font-weight:bold;">yield</span> package, version, url <span style="color: #808080; font-style: italic;"># Just to iterate it</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> mycrawler<span style="color: black;">&#40;</span>base, directory = <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>:
    crawler = Crawler<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    crawler.<span style="color: #dc143c;">inspect</span><span style="color: black;">&#40;</span>base + directory<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> package, version, url <span style="color: #ff7700;font-weight:bold;">in</span> crawler.<span style="color: black;">results</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Newline (&quot;\n&quot;)</span>
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Name:&quot;</span>, package<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; -&gt; Version:&quot;</span>, version<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; -&gt; URL:&quot;</span>, url<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    args = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>
    base      = <span style="color: black;">&#40;</span>servers<span style="color: black;">&#91;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>,<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> args <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">else</span> servers.<span style="color: black;">values</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    directory = <span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</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>       <span style="color: #ff7700;font-weight:bold;">if</span> args <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">2</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;</span>,<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> server <span style="color: #ff7700;font-weight:bold;">in</span> base:
        <span style="color: #ff7700;font-weight:bold;">for</span> page <span style="color: #ff7700;font-weight:bold;">in</span> directory:
            mycrawler<span style="color: black;">&#40;</span>server, page<span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=164</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gioco della vita di Conway: da Python a C</title>
		<link>http://frafra.eu/?p=149</link>
		<comments>http://frafra.eu/?p=149#comments</comments>
		<pubDate>Sat, 07 Nov 2009 12:12:36 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Conway]]></category>
		<category><![CDATA[game of life]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=149</guid>
		<description><![CDATA[Vi ricordate il post sul gioco della vita di Conway (life)? Avevo scritto un algoritmo che oltre a implementare questo giochino (vedi Gioco della vita di Conway), ricercasse, con un bruteforce, tutte le figure che si ripetevano. Ora l&#8217;ho riscritto in C, supportando come parametri anche shift e step (sono un metodo grezzo per permettere [...]]]></description>
			<content:encoded><![CDATA[<p>Vi ricordate il post sul gioco della vita di Conway (life)? Avevo scritto un algoritmo che oltre a implementare questo giochino (vedi <a href="http://frafra.eu/?p=60">Gioco della vita di Conway</a>), ricercasse, con un bruteforce, tutte le figure che si ripetevano. Ora l&#8217;ho riscritto in C, supportando come parametri anche shift e step (sono un metodo grezzo per permettere un balance tra cpu/pc lanciando processi con parametri diversi) e un metodo economico (ma stupido) per il calcolo delle figure successive (vedere la variabile dirty e la nota n. 1). Quest&#8217;ultima caratteristica rende l&#8217;algoritmo intrinsecamente più veloce rispetto a quello che avevo scritto in Python, per cui le prestazioni sono sfasate (penso che questo trucco possa rendere il codice cinque volte più veloce mediamente, ma devo ancora studiare meglio gli effetti).</p>
<p>Tenendo conto di questo, il rapporto tra il programma in C, il programma Python convertito in C++ con Shedskin, la versione che usa Psyco, e la versione &#8220;classica&#8221;, è: (approssimativamente) 1:10:70:300. Ripeto: devo ancora applicare l&#8217;algoritmo nuovo in Python, e pare che gli ultimi tre dati si possano dividere per cinque circa, portando la versione Shedskin nello stesso ordine di grandezza della versione in C (questo sottolinea la validità del progetto), mentre la versione Pythonica sarebbe meno di due ordini di grandezza più lenta.</p>
<p>Il codice è questo <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Non lo commenterò passo passo, in quanto mi pare molto leggibile e simile a quello della versione in Python. Oltretutto, è già lungo di suo, quindi eviterei di riprendere inutilmente pezzi di codice per commentare la loro funzione <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Ho tolto la licenza&#8230; Tenete conto che, ovviamente, è sotto GPLv3:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> clean<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>p<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dim<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> c<span style="color: #339933;">;</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> c<span style="color: #339933;">&lt;=</span>dim<span style="color: #339933;">;</span> c<span style="color: #339933;">++,</span> p<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span>p <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> clone<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>from<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>to<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dim<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> c<span style="color: #339933;">;</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> c<span style="color: #339933;">&lt;=</span>dim<span style="color: #339933;">;</span> c<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> to<span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> from<span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>from<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>to<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dim<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> c<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> c<span style="color: #339933;">&lt;=</span>dim<span style="color: #339933;">;</span> c<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>to <span style="color: #339933;">!=</span> <span style="color: #339933;">*</span>from<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> from<span style="color: #339933;">++;</span> to<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">!=</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">!=</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Usage: %s [rows] [columns] [shift] [step]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">const</span> <span style="color: #993333;">int</span> rows <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">const</span> <span style="color: #993333;">int</span> columns <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">const</span> <span style="color: #993333;">int</span> dim <span style="color: #339933;">=</span> rows<span style="color: #339933;">*</span>columns<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> shift <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> step <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">==</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        shift <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        step <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>shift <span style="color: #339933;">&gt;=</span> step<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;shift/step are invalid.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #993333;">int</span> clean_stage<span style="color: #009900;">&#91;</span>dim<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>clean_p <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>clean_stage<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    clean<span style="color: #009900;">&#40;</span>clean_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> alpha_stage<span style="color: #009900;">&#91;</span>dim<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>alpha_p <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>alpha_stage<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    clean<span style="color: #009900;">&#40;</span>alpha_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> beta_stage<span style="color: #009900;">&#91;</span>dim<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>   <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>beta_p <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>beta_stage<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
    clean<span style="color: #009900;">&#40;</span>beta_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> first_stage<span style="color: #009900;">&#91;</span>dim<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>first_p <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>first_stage<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    clean<span style="color: #009900;">&#40;</span>first_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> dirty<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">int</span> p <span style="color: #339933;">=</span> dim<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">int</span> r<span style="color: #339933;">,</span> sum<span style="color: #339933;">,</span> row<span style="color: #339933;">,</span> column<span style="color: #339933;">,</span> row_p<span style="color: #339933;">,</span> row_n<span style="color: #339933;">;</span>
    r <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        p <span style="color: #339933;">=</span> dim<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>first_stage<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> p<span style="color: #339933;">--;</span>
        first_stage<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>p<span style="color: #339933;">++;</span> p<span style="color: #339933;">&lt;</span>dim<span style="color: #339933;">;</span> p<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> first_stage<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>r<span style="color: #339933;">%</span>step <span style="color: #339933;">!=</span> shift<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            r<span style="color: #339933;">++;</span>
            <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> r <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        clone<span style="color: #009900;">&#40;</span>first_p<span style="color: #339933;">,</span> alpha_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        dirty <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>dirty <span style="color: #339933;">!=</span> <span style="color: #0000dd;">18</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #808080; font-style: italic;">/* [1] Nota a fine programma... */</span>
            <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>dim<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                row <span style="color: #339933;">=</span> i<span style="color: #339933;">/</span>columns<span style="color: #339933;">;</span>
                column <span style="color: #339933;">=</span> i<span style="color: #339933;">%</span>columns<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>row <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    row_n <span style="color: #339933;">=</span> i<span style="color: #339933;">+</span>columns<span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">&lt;</span> columns<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> sum <span style="color: #339933;">=</span> \
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>row <span style="color: #339933;">&lt;</span> rows<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    row_p <span style="color: #339933;">=</span> i<span style="color: #339933;">-</span>columns<span style="color: #339933;">;</span>
                    row_n <span style="color: #339933;">=</span> i<span style="color: #339933;">+</span>columns<span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">&lt;</span> columns<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_n<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    row_p <span style="color: #339933;">=</span> i<span style="color: #339933;">-</span>columns<span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>column <span style="color: #339933;">&lt;</span> columns<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">else</span> sum <span style="color: #339933;">=</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>row_p<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span>\
                        alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                beta_stage<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>sum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span> beta_stage<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> alpha_stage<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">:</span> beta_stage<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>compare<span style="color: #009900;">&#40;</span>beta_p<span style="color: #339933;">,</span> first_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>dim<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d &quot;</span><span style="color: #339933;">,</span> first_stage<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> first_stage<span style="color: #009900;">&#91;</span>dim<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>compare<span style="color: #009900;">&#40;</span>alpha_p<span style="color: #339933;">,</span> beta_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            clone<span style="color: #009900;">&#40;</span>beta_p<span style="color: #339933;">,</span> alpha_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            dirty<span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>compare<span style="color: #009900;">&#40;</span>first_p<span style="color: #339933;">,</span> clean_p<span style="color: #339933;">,</span> dim<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Nota [1]:
  Per non comparare sempre lo stage corrente con quelli precedenti,
  ho creato una modalità &quot;stupida&quot; di computazione. Il valore 18
  indica che non è necessario calcolare ulteriori stages se non si è
  ancora usciti dal ciclo, in quanto pare che non ci siano figure nel
  primo stadio, che si ripetano dopo il 18esimo stadio. */</span></pre></td></tr></table></div>

<p><strong>P.S.</strong> Ho trovato una implementazione di questo giochino, molto carina, (senza bruteforce ovviamente) nella directory di Python 3.1.1 (ma penso si trovi anche in versioni precedenti) che usa curses, sotto Python-3.1.1/Demo/curses/life.py <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=149</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Paldo: una distribuzione interessante</title>
		<link>http://frafra.eu/?p=146</link>
		<comments>http://frafra.eu/?p=146#comments</comments>
		<pubDate>Sat, 07 Nov 2009 11:34:59 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Guide]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=146</guid>
		<description><![CDATA[E&#8217; da un po&#8217; di mesi che provo questa distribuzione poco nota. Le peculiarità? In un cdrom sono contenuti tutti i programmi che ci si aspetterebbe, inclusi Openoffice, Gimp e Inkscape Software aggiornatissimo Veloce e leggera, ma non gli manca nulla (avvia anche cups e openssh al boot) Gnome-centrica Comodissima per compilare: il sistema di [...]]]></description>
			<content:encoded><![CDATA[<p>E&#8217; da un po&#8217; di mesi che provo questa distribuzione poco nota. Le peculiarità?</p>
<ol>
<li>In un cdrom sono contenuti tutti i programmi che ci si aspetterebbe, inclusi Openoffice, Gimp e Inkscape</li>
<li>Software aggiornatissimo</li>
<li>Veloce e leggera, ma non gli manca nulla (avvia anche cups e openssh al boot)</li>
<li>Gnome-centrica</li>
<li>Comodissima per compilare: il sistema di gestione dei pacchetti permette di scegliere se installare il binario o il sorgente, che verrà automaticamente compilato. Inoltre, è già inclusa una suite di programmi atti alla compilazione e allo sviluppo, oltre agli headers file di tutti i programmi (non c&#8217;è la divisione tra pacchetti -dev e non)</li>
</ol>
<p>Pochi giorni fa, è stata rilasciata la versione 1.20. Non è stata ancora annunciata sul sito, ma è possibile scaricarla sotto la pagina di download.</p>
<p>Ho testato questa versione sul mio nuovo portatile (Asus UL30), e sono rimasto piacevolmente colpito <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Inoltre ho scritto un post sul forum di paldo dove mostro i problemi riscontrati, cosa si può migliorare, e un paio di workaround (utili quelli per utilizzare qemu in accoppiata con kvm e quello per creare una pennetta usb con paldo live, processo riutilizzabile per altre distribuzioni).</p>
<p>Il link è: <a href="http://forum.paldo.org/index.php?action=topic&amp;topicnr=673">Paldo forum &#8211; Topic 673</a></p>
<p>Il sito della distribuzione è: <a href="http://www.paldo.org/">Paldo.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=146</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Condividere una connessione</title>
		<link>http://frafra.eu/?p=121</link>
		<comments>http://frafra.eu/?p=121#comments</comments>
		<pubDate>Fri, 11 Sep 2009 22:23:26 +0000</pubDate>
		<dc:creator>frafra</dc:creator>
				<category><![CDATA[Frafra]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[connection sharing]]></category>
		<category><![CDATA[dnsmasq]]></category>
		<category><![CDATA[iptables]]></category>

		<guid isPermaLink="false">http://frafra.eu/?p=121</guid>
		<description><![CDATA[Proprio ieri sono stato privato della mia linea ADSL casalinga (sto traslocando). In un primo momento, sono stato preso dal panico, pensando a un malfunzionamento del router (basato su Linux, ha sempre funzionato benissimo). Nonostante nella mia testa iniziasse a girovagare l&#8217;idea che mi avessero staccato la linea, per i primi 30 minuti il mio [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_124" class="wp-caption alignleft" style="width: 275px"><img class="size-full wp-image-124 " src="http://frafra.eu/wp-content/uploads/2009/09/tux.jpg" alt="little tux" width="265" height="265" /><p class="wp-caption-text">Il guardiano del router e compagna <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p></div>
<p>Proprio ieri sono stato privato della mia linea ADSL casalinga (sto traslocando). In un primo momento, sono stato preso dal panico, pensando a un malfunzionamento del router (basato su Linux, ha sempre funzionato benissimo). Nonostante nella mia testa iniziasse a girovagare l&#8217;idea che mi avessero staccato la linea, per i primi 30 minuti il mio cervello non accettava il fatto, come quando viene a mancare un animale domestico al quale si è affezionati e nonostante ciò gli si riempie la ciotola di pappa <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Dopo qualche reboot dei miei tre scatolotti necessari per far funzionare la mia rete (un modem ethernet, un router 4 porte wifi, e uno switch 8 porte), ho guardato il &#8220;guardiano del router&#8221; (un piccolo pinguino di peluche che tiene lontani gli spiriti cattivi dalla mia connessione), e gli ho detto: &#8220;mi dispiace, per un po&#8217; ti toccherà fare il disoccupato&#8230;&#8221;.</p>
<p>Detto ciò, ho passato un po&#8217; di tempo a sistemare i miei programmini Python, e a pubblicare su github un po&#8217; di codice (vedasi <a href="http://github.com/frafra">github.com/frafra</a>, dove ho pubblicato anche una interessante applicazione PyQT4+Twisted per la chat), utilizzando il pc di un amico <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Questo mio amico (nonché vicino di casa), ha acconsentito a condividere temporaneamente la sua connessione wifi. E qui inizia il divertimento <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Obiettivo: dare internet alla lan, utilizzando una rete wifi<br />
</strong></p>
<p>Sostanzialmente, abbiamo bisogno di un pc che da una parte si connetta dalla rete wireless, e dall&#8217;altra condivida la propria connessione. Per fare ciò sul pc dotato sia di scheda wireless sia di scheda ethernet dobbiamo:</p>
<ol>
<li>Connetterci alla rete (soluzione più semplice: networkmanager)</li>
<li>ifconfig eth0 192.168.100.1 up<br />
<em>(ho scelto 192.168.<strong>100</strong>.1 perché così sono sicuro che non si tratti di una rete già in uso)</em></li>
<li>echo 1 &gt; /proc/sys/net/ipv4/ip_forward</li>
<li>iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE<br />
<em>(dove eth0 è l&#8217;inferfaccia di rete e wlan0 quella wifi)</em></li>
<li>Installare dnsmasq</li>
<li>Editare /etc/dnsmasq.conf, mettendo:<br />
<code> domain-needed<br />
bogus-priv<br />
interface=eth0<br />
dhcp-range=192.168.100.2,192.168.100.100,12h</code></li>
<li>Avviare il demone dnsmasq<br />
<em>(spesso basta dare /etc/init.d/dnsmasq start o /etc/rc.d/dnsmasq start)</em></li>
</ol>
<p>Tutti questi comandi devono essere avviati come superutente (quindi o aggiungendo sudo davanti a ogni comando, o digitando su [invio] prima di iniziare la procedura). Dagli altri computer ora potete connettervi come se fosse presente un normale router nella rete locale (quindi con networkmanger, o lanciando un dhclient/dhcpcd eth0), e il gioco è fatto <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Per collegare più dispositivi alla rete del mio portatile, ho collegato i vari computer (incluso il portatile) allo switch. Nulla di più facile <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><img class="size-full wp-image-123 " title="rete" src="http://frafra.eu/wp-content/uploads/2009/09/rete.png" alt="&lt;a href=" width="NaN" height=" mce_href=" /><br />
Ecco che, grazie alle mie doti nell&#8217;arte figurativa (eeeh!) e a inkscape, ho creato una mappa della rete, prima e dopo <img src='http://frafra.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. Ehi, ho appena fatto 19 anni, sto invecchiando <img src='http://frafra.eu/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Domani si parte per l&#8217;avventura chiamata &#8220;università&#8221; <img src='http://frafra.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://frafra.eu/?feed=rss2&amp;p=121</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
