<?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>PiumaLab</title>
	<atom:link href="http://www.piumalab.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.piumalab.org</link>
	<description>Idee, esperimenti, tentativi e molto altro</description>
	<lastBuildDate>Fri, 13 Jan 2012 13:26:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Jboss as 7 disegnato per essere flessibile</title>
		<link>http://www.piumalab.org/jboss-as-7-disegnato-per-essere-flessibile/</link>
		<comments>http://www.piumalab.org/jboss-as-7-disegnato-per-essere-flessibile/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 13:55:51 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Sviluppo Software]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=656</guid>
		<description><![CDATA[La prima versione di Jboss 7 fu rilasciata nel novembre 2010, già da allora è possibile apprezzare il lavoro del team di RedHat e della comunità che ha lavorato alla realizzazione dell'Application Server. La versione 7 segna un punto di svolta rispetto alle versioni precedenti, esso infatti ha subito un processo di restyling completo, distaccandosi [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/Jboss-as7.png" alt="Jboss-AS7" title="" class="alignnone size-full wp-image-519" />
</td>
<td>
La prima versione di <a href="http://www.jboss.org/as7">Jboss 7</a> fu rilasciata nel novembre 2010, già da allora è possibile apprezzare il lavoro del team di <strong>RedHat</strong> e della comunità che ha lavorato alla realizzazione dell'Application Server.</p>
<p>La versione 7 segna un punto di svolta rispetto alle versioni precedenti, esso infatti ha subito un processo di restyling completo, distaccandosi molto dalle versioni precedenti come se fosse a tutti gli effetti un prodotto nuovo , che tuttavia può contare sulla grande esperienza accumulata negli anni dal gruppo di sviluppo.</p>
<p>Di seguito vengono riportate alcuni punti di forza del nuovo Jboss che forniscono notevoli vantaggi rispetto agli altri AS.
</td>
</tr>
</table>
<p><span id="more-680"></span></p>
<h3>+ Velocit&agrave;</h3>
<p>All'avvio di AS7 i servizi sono lanciati in maniera concorrente. Questo elimina inutili attese e sfrutta maggiormente i processori con architetture multi-core. I servizi non indispensabili rimangono inattivi fino a quando non vengono effettivamente utilizzati. Queste modifiche hanno permesso di ridurre i tempi di avvio di ben 10 volte rispetto alle versioni precedenti.</p>
<h3>+ Modularit&agrave;</h3>
<p>Il tempo del caricamento delle classi in modo gerarchico, e con lui il comportamento non convenzionale che ha provocato è stato surclassato; infatti AS7 vanta di un metodo di caricamento delle classi in grado di garantire l'isolamento dell'applicazione dalle classi del server. I moduli sono formati da un insieme di classi che restano isolate dagli altri moduli a meno che non si definisce espressamente la dipendenza da un altro modulo. Saranno caricati solo i moduli necessari e in maniera concorrente.</p>
<h3>+ Leggerezza</h3>
<p>AS7 ha migliorato la gestione della memoria con il Garbage Collector per ridurre al minimo le pause caricando solo i file JAR di cui ha realmente bisogno e indicizzando tutti i meta-dati. Tutto questo consente di ridurre l'occupazione della memoria con la diretta conseguenza di poter girare su dispositivi con meno risorse, inoltre lascia più spazio a disposizione delle applicazioni e supporta una maggiore scalabilità. I profili personalizzabili del server consentono di escludere le funzionalità non necessarie e rendere il server quanto più snello possibile.</p>
<h3>+ Amministrazione</h3>
<p>La configurazione di <strong>AS7</strong> è centralizzata, semplice e orientata all'utente. Il file di configurazione si basa su un modello molto essenziale, completo ed elegante. A differenza delle versioni precedenti è stata unificata la configurazione su un solo file <strong>XML</strong>, non dovremo più andare alla ricerca dei file di configurazione per modificare un parametro. Quest'unificazione ha permesso anche la nascita di nuovi strumenti di amministrazione come la console, sia web che a linea di comando, e le api java e http. Con questi nuovi strumenti è inoltre possibile modificare la configurazione in run time, molto utile in ambienti di produzione.</p>
<h3>+ Portabilit&agrave;</h3>
<p>Il team di <strong>Jboss</strong> è da sempre impegnato sulla portabilità delle applicazioni, ecco perché hanno reso AS7 certificata <strong>Java EE 6 web profile</strong>. Quest'attenzione consente di far girare applicazioni in AS7, purché rispecchino le linee guida Java EE.</p>
<h3>+ Robustezza</h3>
<p>AS7 è stato disegnato per facilitare il debugging delle applicazioni, tutto questo è dovuto alla scelta di utilizzare Arquillian che mette a disposizione un modello per i test di integrazione eseguiti all'interno dell'ambiente runtime reale. Viene fornita agli sviluppatori la possibilità di scrivere test per tutta la casistica che l'applicazione può incontrare durante il suo uso.</p>
<h3>+ Scalabilit&agrave;</h3>
<p>Jboss AS7 può essere avviato in due modalità differenti, standalone e dominio. La prima gestisce una sola istanza mentre la seconda consente di  gestire una tipologia multi server.</p>
<h2>Struttura</h2>
<p>Capire la struttura delle directory dell'AS7 ci permette di trovare con facilità i file di configurazione, i file di log, i deploy delle applicazioni utente. Per familiarizzare con la struttura vedremo in dettaglio le le directory più importanti.<br />
<code>.<br />
|-- bin<br />
|   |-- domain.conf<br />
|   |-- domain.sh<br />
|   |-- jboss-admin.sh<br />
|   |-- scripts<br />
|   |-- standalone.conf<br />
|   `-- standalone.sh<br />
|-- bundles<br />
|-- docs<br />
|   |-- licenses<br />
|   `-- schema<br />
|-- domain<br />
|   |-- configuration<br />
|   |-- content<br />
|   |-- lib<br />
|   |    `-- ext<br />
|   |-- log<br />
|   `-- servers<br />
|-- modules<br />
|-- standalone<br />
|   |-- configuration<br />
|   |-- data<br />
|   |-- deployments<br />
|   |-- lib<br />
|   |    `-- ext<br />
|   |-- log<br />
|   `-- tmp<br />
`-- welcome-content<br />
</code></p>
<p><strong>bin</strong>: Script per avviare e fermare il server e script di configurazione per settare le variabili d'ambiente e le impostazioni della java virtual machine.<br />
<strong>bundles</strong>: Posto per i bundles OSGi.<br />
docs/schema: Definizioni in xsd dei file XML usati da jboss.<br />
<strong>modules</strong>: I moduli usati dal server sono in questa directory. (AS 7 è basato su una architettura modulare per il caricamento delle classi).<br />
<strong>welcome-content</strong>: Pagina di default di benvenuto.</p>
<p><strong>standalone</strong>: File di configurazione, deploy, e aree scrivibili usate dal server quando avviato  nella modalità standalone.<br />
<strong>standalone/configuration</strong>: File di configurazione per il server standalone. Questo è il solo posto dove ci sono tutte le informazioni di configurazione per il server standalone.<br />
<strong>standalone/data</strong>: Informazioni persistenti memorizzate dal server.<br />
<strong>standalone/deployments</strong>: I deploy degli utenti verranno rilevati e caricati automaticamente da questa directory anche a runtime.<br />
NOTA: Le API per l'amministrazione del server sono la strada consigliata per installare i contenuti dei deploy. La capacita di scansione del file system per i deploy resta una funzionalità consigliata per lo sviluppo.<br />
<strong>standalone/lib/ext</strong>: Luogo per l'installazione di jars per le applicazioni utilizzando il meccanismo dell'Extension-list.<br />
<strong>standalone/log</strong>: File di log per il server standalone.<br />
<strong>standalone/tmp</strong>: Directory per i file temporanei scritti dal server.</p>
<p><strong>domain</strong>: File di configurazione, deploy, e aree scrivibili usate dal server quando avviato  nella modalità domain.<br />
<strong>domain/configuration</strong>: File di configurazione per il server domain. Questo è il solo posto dove ci sono tutte le informazioni di configurazione per il server domain.<br />
<strong>domain/content</strong>: Area interna di lavoro per l'Host Controller. Questo è il posto dove vengono memorizzati internamente i contenuti dei deploy; questo non significa che le informazioni possono essere manipolate dagli utenti e sviluppatori. Da notare che la modalità dominio non prevede i deploy automatici basati sulla scansione del file system.<br />
<strong>domain/lib/ext</strong>: Luogo per l'installazione di jars per le applicazioni utilizzando il meccanismo dell'Extension-list.<br />
<strong>domain/log</strong>: Directory dove il processo Host Controller scrive i log. Il Process Controller, un piccolo processo che genera gli altri processi Host Controller, ed ogni processo Application Server che a sua volta utilizza  questo path.<br />
<strong>domain/servers</strong>: Area scrivibile da ogni istanza di Application Server. Ogni istanza, ha la sua sotto directory creata al primo avvio del server. In ogni sotto directory, per ogni istanza  troviamo: data, log e tmp che hanno la stessa funzione delle omonime utilizzate dal server standalone.</p>
<h2>Creazione di un modulo</h2>
<p>Uno dei punti di forza di AS7 è la gestione del caricamento delle classi; questa funzionalità è cambiata radicalmente rispetto alle versioni precedenti di Jboss. In AS7 è basata sui moduli che hanno sostituito la più familiare organizzazione gerarchica delle classi. Le dipendenze dei moduli sono definite esplicitamente nella configurazione. I moduli hanno permesso all'application server di ridurre i tempi di startup sfruttando l'hiperthtreading dei moderni processori e la separazione delle classi del web server con quelle delle applicazioni.<br />
Il nuovo Jboss è retro compatibile con i metodi di deploy di archivi jar e war. È Sufficiente mettere il file nell'apposita directory e l'application server lo carica in automatico come nella vecchia versione. In questo modo, però, non si sfruttano le potenzialità introdotte con l'uso dei moduli.<br />
Ecco dei semplici passi per la configurazione di un Datasource MySql con la creazione di un nuovo modulo per il driver.</p>
<h2>Installare il driver</h2>
<p>Una volta definito il datasource, abbiamo due modi per installare il driver <strong>JDBC</strong>. Come si è già specificato precedentemente la creazione di un nuovo modulo è la strada più pulita e performante da seguire anche se leggermente più lunga. Si dovrànno aggiungere 2 file: <em>module.xml</em> e il <em>jar</em> della libreria nel path <em>$JBOSS_HOME/modules/com/mysql/main</em><br />
Il file <em>module.xml</em> definisce il modulo in cui è semplicemente indicato il nome, la risorsa utilizzata e le sue dipendenze. Sarà fatto in questo modo:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #ddbb00;">&amp;lt;</span>?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
<span style="color: #ddbb00;">&amp;lt;</span>module xmlns=&quot;urn:jboss:module:1.0&quot; name=&quot;com.mysql&quot;&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>resources&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>resource-root path=&quot;mysql-connector-java-5.1.17-bin.jar&quot;/&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>/resources&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>dependencies&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>module name=&quot;javax.api&quot;/&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>module name=&quot;javax.transaction.api&quot;/&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>/dependencies&gt;
<span style="color: #ddbb00;">&amp;lt;</span>/module&gt;</pre></div></div>

<p>Il secondo metodo per installare il driver JDBC nell'application server è quello di effettuare il deploy del jar. Questa opzione è particolarmente utile quando l'application server gira in modalità domain. In questo scenario il deploy del jar verrà automaticamente propagato a tutti i server del dominio.</p>
<h2>Definizione datasource</h2>
<p>Il file di configurazione <em>$JBOSS_HOME/standalone/configuration/standalone.xml</em> per la versione standalone è nel formato XML. Il seguente esempio mostra la configurazione del datasource:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #ddbb00;">&amp;lt;</span>subsystem xmlns=&quot;urn:jboss:domain:datasources:1.0&quot;&gt;
 <span style="color: #ddbb00;">&amp;lt;</span>datasources&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>datasource jndi-name=&quot;MySqlDS&quot; pool-name=&quot;MySqlDS_Pool&quot; enabled=&quot;true&quot;
                       jta=&quot;true&quot; use-java-context=&quot;true&quot; use-ccm=&quot;true&quot;&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>connection-url&gt;jdbc:mysql://localhost:3306/database<span style="color: #ddbb00;">&amp;lt;</span>/connection-url&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>driver&gt;mysql<span style="color: #ddbb00;">&amp;lt;</span>/driver&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>pool&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>min-pool-size&gt;5<span style="color: #ddbb00;">&amp;lt;</span>/min-pool-size&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>max-pool-size&gt;10<span style="color: #ddbb00;">&amp;lt;</span>/max-pool-size&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>/pool&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>security&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>user-name&gt;jboss<span style="color: #ddbb00;">&amp;lt;</span>/user-name&gt;
    <span style="color: #ddbb00;">&amp;lt;</span>password&gt;jboss<span style="color: #ddbb00;">&amp;lt;</span>/password&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>/security&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>/datasource&gt;
&nbsp;
  <span style="color: #ddbb00;">&amp;lt;</span>drivers&gt;
   <span style="color: #ddbb00;">&amp;lt;</span>driver name=&quot;mysql&quot; module=&quot;com.mysql&quot;/&gt;
  <span style="color: #ddbb00;">&amp;lt;</span>/drivers&gt;
&nbsp;
 <span style="color: #ddbb00;">&amp;lt;</span>/datasources&gt;
<span style="color: #ddbb00;">&amp;lt;</span>/subsystem&gt;</pre></div></div>

<p>La struttura dell'XML è definita nella specifica<em> $JBOSS_HOME/docs/schema/jboss-as-datasources_1_0.xsd</em>. Possiamo editare manualmente il file oppure utilizzare gli strumenti per l'amministrazione che mette a disposizione AS7, come la console web, raggiungibile all'indirizzo <a href="http://localhost:9990/console">http://localhost:9990/console</a><br />
Se tutto è andato a buon fine allo start di AS7 vediamo il caricamento del modulo:<br />
<code>  JBoss Bootstrap Environment</p>
<p>  JBOSS_HOME: /opt/jboss-as-web-7.0.1.Final</p>
<p>  JAVA: /opt/java/bin/java</p>
<p>  JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman</p>
<p>=========================================================================</p>
<p>19:09:28,300 INFO  [org.jboss.modules] JBoss Modules version 1.0.1.GA<br />
19:09:29,711 INFO  [org.jboss.msc] JBoss MSC version 1.0.0.GA<br />
19:09:29,917 INFO  [org.jboss.as] JBoss AS 7.0.1.Final "Zap" starting<br />
19:09:33,048 INFO  [org.jboss.as.domain-management] Starting 'TestRealm' Security Realm Service<br />
19:09:33,378 INFO  [org.jboss.as] creating http management service using network interface (management) port (9990)<br />
19:09:33,381 WARN  [org.jboss.as] No security realm defined for http management service, all access will be unrestricted.<br />
19:09:33,442 INFO  [org.jboss.as.logging] Removing bootstrap log handlers<br />
19:09:33,602 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying JDBC-compliant driver class org.h2.Driver (version 1.2)<br />
19:09:33,751 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)<br />
19:09:33,836 INFO  [org.jboss.as.clustering.infinispan.subsystem] (Controller Boot Thread) Activating Infinispan subsystem.<br />
19:09:34,200 INFO  [org.jboss.as.naming] (Controller Boot Thread) Activating Naming Subsystem<br />
19:09:34,255 INFO  [org.jboss.as.naming] (MSC service thread 1-1) Starting Naming Service<br />
19:09:34,275 INFO  [org.jboss.as.osgi] (Controller Boot Thread) Activating OSGi Subsystem<br />
19:09:34,359 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem<br />
19:09:34,377 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 3.2.0.Beta2<br />
19:09:34,492 INFO  [org.xnio] (MSC service thread 1-2) XNIO Version 3.0.0.Beta3<br />
19:09:34,578 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.0.0.Beta3<br />
19:09:35,291 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-2) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/jdk1.6.0_18/jre/lib/amd64/server:/opt/jdk1.6.0_18/jre/lib/amd64:/opt/jdk1.6.0_18/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib<br />
19:09:35,385 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem<br />
19:09:35,442 INFO  [org.jboss.as.remoting] (MSC service thread 1-2) Listening on /127.0.0.1:9999<br />
19:09:35,693 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-1) Starting remote JMX connector<br />
19:09:35,756 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080<br />
19:09:36,619 INFO  [org.jboss.as.connector] (MSC service thread 1-1) Starting JCA Subsystem (JBoss IronJacamar 1.0.3.Final)<br />
19:09:36,946 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) Bound data source [java:jboss/datasources/MySqlDS]<br />
19:09:38,014 INFO  [org.jboss.as] (MSC service thread 1-2) JBoss AS 7.0.1.Final "Zap" started in 11360ms - Started 147 of 208 services (61 services are passive or on-demand)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/jboss-as-7-disegnato-per-essere-flessibile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installazione di Joomla nel cloud di Red Hat</title>
		<link>http://www.piumalab.org/installazione-di-joomla-nel-cloud-di-red-hat/</link>
		<comments>http://www.piumalab.org/installazione-di-joomla-nel-cloud-di-red-hat/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 11:42:29 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Amministrazione]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=632</guid>
		<description><![CDATA[Vedremo dei semplici passi per l'installazione dell'ultima versione ad oggi stabile di Joomla, la 1.7 sul cloud OpenShift di Red Hat. Nel'articolo useremo per convenzione che i comandi shell preceduti dal # (cancelletto) dovranno essere lanciati dall'utente amministratore o in alternativa utilizzando sudo. I comandi preceduti da $ (dollaro) possono essere lanciati da un normale [...]]]></description>
			<content:encoded><![CDATA[<table>
<tbody>
<tr>
<td><img class="alignnone size-full wp-image-519" title="" src="http://www.piumalab.org/wp-content/uploads/joomla-openshift.png" alt="joomla openshift" /></td>
<td>Vedremo dei semplici passi per l'installazione dell'ultima versione ad oggi stabile di <strong>Joomla</strong>, la 1.7 sul cloud <strong>OpenShift</strong> di Red Hat.</td>
</tr>
</tbody>
</table>
<p>Nel'articolo useremo per convenzione che i comandi shell preceduti dal # (cancelletto) dovranno essere lanciati dall'utente amministratore o in alternativa utilizzando sudo. I comandi preceduti da $ (dollaro) possono essere lanciati da un normale utente che non ha i privilegi di root.</p>
<p>Per prima cosa abbiamo bisogno del client OpenShift che ci servirà per la creazione del cloud, la configurazione e l’aggiunta di applicazioni e servizi. E` possibile scegliere 3 profili di OpenShift, noi faremo riferimento a quella gratuita chiamata Express, ci sono poi la Flex e la Power in caso abbiamo bisogno di maggiori performance.</p>
<p><span id="more-658"></span></p>
<p>Di seguito i passi per l'installazione del client OpenShift su un sistema RHEL 6 o superiore, oppure Fedora 14 o una versione più recente. Questa guida non ha lo scopo di coprire tutti i casi, per gli altri sistemi operativi si rimanda alla documentazione del progetto.<br />
Installazione del client per OpenShift:<br />
<code># cd /etc/yum.repos.d/<br />
# wget https://openshift.redhat.com/app/repo/openshift.repo<br />
# yum -y install rhc<br />
</code><br />
Al termine dell'installazione abbiamo sul nostro computer tutti i pacchetti necessari per lanciare il nostro portale Joomla. Vedremo che grazie a <strong>GIT</strong> non sarà necessario neanche scaricare il pacchetto di Joomla. Ora possiamo utilizzare i comandi appena installati di OpenShift per creare il nostro sotto dominio che chiameremo joomla. Quando questo comando verrà eseguito per la prima volta verranno create delle chiavi SSH che saranno usate per comunicare con Openshift Express. E` possibile creare un solo sottodominio per ogni utente registrato.<br />
<code>$ rhc-create-domain -n joomla -l guest@example.it</code></p>
<pre>Password:
Generating OpenShift Express ssh key to /home/guest/.ssh/libra_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/guest/.ssh/libra_id_rsa.
Your public key has been saved in /home/guest/.ssh/libra_id_rsa.pub.
The key fingerprint is:
3e:88:b7:e9:a4:c8:6c:e3:9a:16:d4:32:b7:70:06:61 guest@example.com
The key's randomart image is:
+--[ RSA 2048]----+
| E.              |
|..               |
|  o              |
| = =             |
|. B .   S        |
| . . . o         |
|  . . + o        |
| =o. + o .       |
|++=...+          |
+-----------------+
Contacting https://openshift.redhat.com
Creation successful

You may now create an application.</pre>
<p>Ora possiamo creare la nostra applicazione, prima però vediamo il contenuto del file di configurazione:<br />
<code>$ cat .openshift/express.conf</code></p>
<pre># SSH key file
#ssh_key_file = 'libra_id_rsa'
# Default rhlogin to use if none is specified
default_rhlogin=guest@example.it</pre>
<p>C'è specificato l'rhlogin che userà di default se non specificato. Questo ci semplifica il lancio dei successivi comandi perché da ora in poi non sarà più necessario specificarlo.</p>
<p>Ora possiamo creare un'applicazione, Joomla necessita del PHP ed è la prima cosa che andremo ad installare nel nostro cloud. Con rhc-create-app --help abbiamo la lista delle applicazioni supportate.<br />
Creiamo una directory che diventerà il repository di GIT, in poche parole la nostra directory di lavoro:<br />
<code>$ mkdir rhc-joomla<br />
$ cd rhc-joomla<br />
$ rhc-create-app -a test -t php-5.3</code></p>
<pre>Password:

Found a bug? Post to the forum and we'll get right on it.
      IRC: #openshift on freenode
      Forums: https://www.redhat.com/openshift/forums

Attempting to create remote application space: test
Contacting https://openshift.redhat.com
API version: 1.1.1
Broker version: 1.1.1

RESULT:
Successfully created application: test
Checking ~/.ssh/config
Contacting https://openshift.redhat.com
      Adding rhcloud.com to ~/.ssh/config
Now your new domain name is being propagated worldwide (this might take a
minute)...
Pulling new repo down
Warning: Permanently added 'test-joomla.rhcloud.com,107.22.25.216' (RSA) to the
list of known hosts.
Confirming application test is available
Attempt # 1

Success! Your application is now published here:

http://test-joomla.rhcloud.com/

The remote repository is located here:

     ssh://791a8fe8bd1c48c1820f933c6cad3579@test-joomla.rhcloud.com/~/git/test.git/

To make changes to your application, commit to test/.
Then run 'git push' to update your OpenShift Express space</pre>
<p>Abbiamo creato la nostra applicazione chiamata test e gli abbiamo specificato che userà il php.<br />
Niente di più semplice, non dobbiamo installare il php direttamente sul cloud partendo dal pacchetto o dai sorgenti perché OpenShift lo fa per noi in modo del tutto trasparente. Vediamo se è altrettanto semplice aggiungere un altro servizio di cui Joomla ha bisogno, un server <strong>MySql</strong>.<br />
<code>$ rhc-ctl-app -a test -e add-mysql-5.1</code></p>
<pre>Password:
Contacting https://openshift.redhat.com
Contacting https://openshift.redhat.com
API version: 1.1.1
Broker version: 1.1.1

RESULT:

Mysql 5.1 database added.
Please make note of these credentials:

    Root User: admin
    Root Password: Q2eXtiXqcXXX
    Database Name: test

Connection URL: mysql://127.1.33.XXX:3306/</pre>
<p>In meno di un secondo abbiamo anche il nostro database server installato ed avviato. L'output ci fornisce le informazioni per l'accesso e ci comunica che è stato creato un database con lo stesso nome che abbiamo scelto per la nostra applicazione.<br />
Ora il nostro ambiente è pronto per l'installazione di Joomla.<br />
Grazie alla potenza di GIT possiamo fare tutto in modo molto pulito e veloce. GIT infatti ci permettere di aggiungere un ulteriore repository al nostro branch di lavoro. Dopo essere entrati nella directory "test" digitiamo il comando<br />
<code>$ git remote add upstream -m master git://github.com/openshift/joomla-example.git<br />
</code><br />
Fatto. Facciamo ora il fetch e il merge con il nuovo repository:<br />
<code>$ git pull -s recursive -X theirs upstream master</code></p>
<pre>warning: no common commits
remote: Counting objects: 3805, done.
remote: Compressing objects: 100% (2963/2963), done.
remote: Total 3805 (delta 818), reused 3805 (delta 818)
Receiving objects: 100% (3805/3805), 4.83 MiB | 340 KiB/s, done.
Resolving deltas: 100% (818/818), done.
From git://github.com/openshift/joomla-example
* branch      master        -&gt; FETCH_HEAD

*** Please tell me who you are.

Run

    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident  not allowed</pre>
<p>Ci ha restuito un errore perché il repository di github necessita dell'autenticazione. Quindi andiamo sul sito <a href="http://github.com">github</a> ed effettuiamo la registrazione. Poi diciamo a git di utilizzare lo username appena registrato.<br />
<code>$ git config user.name "guest"<br />
</code><br />
Lanciamo il comando precedente ed ora vediamo che l'operazione va a buon fine.<br />
<code>$ git pull -s recursive -X theirs upstream master</code></p>
<pre>From git://github.com/openshift/joomla-example
 * branch            master     -&gt; FETCH_HEAD
Auto-merging .openshift/action_hooks/build
Auto-merging php/index.php
Merge made by recursive.
 .openshift/action_hooks/build                      |   38 +-
 .openshift/action_hooks/joomla.sql                 | 1860 +++
 README.md                                          |   51 +
 php/LICENSE.txt                                    |  340 +
 php/README.txt                                     |   70 +
 php/administrator/cache/index.html                 |    1 +
 php/administrator/components/com_admin/admin.php   |   20 +
 php/administrator/components/com_admin/admin.xml   |   30 +
 .../components/com_admin/controller.php            |   24 +
 .../components/com_admin/controllers/index.html    |    1 +
 .../components/com_admin/controllers/profile.php   |   89 +
 .../com_admin/helpers/html/directory.php           |   61 +
 .../components/com_admin/helpers/html/index.html   |    1 +
 .../com_admin/helpers/html/phpsetting.php          |   81 +
 .../components/com_admin/helpers/html/system.php   |   37 +
 .../components/com_admin/helpers/index.html        |    1 +
 php/administrator/components/com_admin/index.html  |    1 +
 .../components/com_admin/models/forms/index.html   |    1 +
 .../components/com_admin/models/forms/profile.xml  |  136 +
[...]</pre>
<p>Facciamo il push del repository upstream, questa operazione serve per aggiornare refs remoto usando quello locale, e va fatta ogni volta che vogliamo pubblicare le modifiche di Joomla.<br />
<code>$ git push</code></p>
<pre>Counting objects: 3811, done.
Compressing objects: 100% (2966/2966), done.
Writing objects: 100% (3805/3805), 4.83 MiB | 327 KiB/s, done.
Total 3805 (delta 819), reused 3800 (delta 818)
remote: Stopping application...
remote: Waiting for stop to finish
remote: Done
remote: Running .openshift/action_hooks/build
remote: ERROR 1146 (42S02) at line 1: Table 'test.tt7ki_assets' doesn't exist
remote:
remote: Database schema not found, importing 'joomla.sql' schema.
remote:
remote:
remote: done.
remote: ==================================================
remote: Joomla admin login: admin
remote: Joomla admin password: 4dm1n
remote: Don't forget to change your Joomla admin password!
remote: ==================================================
remote: Starting application...
remote: Done
To
ssh://791a8fe8bd1c48c1820f933c6cad3579@test-joomla.rhcloud.com/~/git/test.git/
    0f9bf26..fff3d3e   master -&gt; master</pre>
<p>Dall'output possiamo vedere che il database non era inizializzato e lui si è preoccupato di farlo. Questa operazione normalmente veniva effettuata durante il processo configurazione di Joomla, che però in questo contesto non abbiamo bisogno di eseguire perché chi ha creato joomla-example su github lo ha già configurato per girare sul cloud di Red Hat. Abbiamo terminato l'installazione, ora possiamo utilizzare Joomla. Aprimo la url http://test-joomla.rhcloud.com/ la url è formata in questo modo http://$app_name-$your_domain.rhcloud.com quindi se abbiamo scelto nomi diversi per l'applicazione o il dominio dovremmo modificarla opportunamente.<br />
Se abbiamo eseguito tutti i passi correttamente dovremmo poter iniziare ad utilizzare Joomla. Ho utilizzato il condizionale perché in realtà se apriamo l'url viene visualizzato solamente il seguente messaggio di errore:</p>
<p><strong>Infinite loop detected in Jerror</strong></p>
<p>Questo è meno grave di quanto sembra, innanzi tutto è un errore generato da Joomla, quindi è stata lanciata l'applicazione che abbiamo appena installato. Il loop infinito si riferisce ad un errore che indirizza ad un errore, nel nostro caso avviene che ho una query che va in errore nella homepage e sull'errore faccio una redirect in homepage, ed è così che si genera un loop infinito. Quindi c'è qualcosa che non va nella configurazione del database. Apriamo il file php/configuration.php e modifichiamo i parametri per la connessione del db settandoli con i valori che abbiamo ottenuto durante la generazione del database.</p>
<pre>public $host = '127.1.33.XXX';
public $user = 'admin';
public $password = 'Q2eXtiXqcXXX';
public $db = 'test';</pre>
<p>Non ci resta che rendere effettive le modifiche.<br />
<code>$ git add php/configuration.php<br />
$ git commit -m 'alter db configuration'</code></p>
<pre>[master 28bb973] alter db configuration
 1 files changed, 4 insertions(+), 4 deletions(-)</pre>
<p><code>$ git push</code></p>
<pre>Counting objects: 7, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 419 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Stopping application...
remote: Waiting for stop to finish
remote: Done
remote: Running .openshift/action_hooks/build
remote: Database found, skipping import.
remote: Starting application...
remote: Done
To ssh://791a8fe8bd1c48c1820f933c6cad3579@test-joomla.rhcloud.com/~/git/test.git/
   fff3d3e..28bb973  master -&gt; master</pre>
<p>Ora tutto è pronto per essere utilizzato, all'indirizzo http://test-joomla.rhcloud.com/ c'è la nostra homepage, l'amministrazione possiamo raggiungerla alla url http://test-joomla.rhcloud.com/administrator/ le credenziali di accesso sono utente admin e password 4dm1n che è preferibile cambiare dopo il primo accesso.</p>
<p style="font-size: 80%;">Licenza d'uso "Attribuzione - Non commerciale - Non opere derivate", secondo i criteri internazionali <a href="http://creativecommons.org/licenses/by-nc-nd/2.5/it/">Creative Commons</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/installazione-di-joomla-nel-cloud-di-red-hat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualBox: usare Wireless Broadband come Host Interface Networking</title>
		<link>http://www.piumalab.org/virtualbox-wireless-broadband-host-interface/</link>
		<comments>http://www.piumalab.org/virtualbox-wireless-broadband-host-interface/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 10:05:59 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=615</guid>
		<description><![CDATA[Nelle impostazioni di rete di VirtualBox per una macchina virtuale non vengono mostrati i dispositivi Wireless Broadband. Se ad esempio siamo collegati ad internet tramite una chiavetta USB non potremmo utilizzare la connessione nella macchina virtuale. Per risolvere questo problema abbiamo bisogno di una configurazione di rete un p&#242; pi&#249; complessa. Dobbiamo creare un bridge [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/virtualbox_logo.png" alt="virtualbox logo" title="" width="140" height="151" class="size-thumbnail wp-image-268" />
</td>
<td>
<p>
Nelle impostazioni di rete di VirtualBox per una macchina virtuale non vengono mostrati i dispositivi Wireless Broadband. Se ad esempio siamo collegati ad internet tramite una chiavetta USB non potremmo utilizzare la connessione nella macchina virtuale. Per risolvere questo problema abbiamo bisogno di una configurazione di rete un p&ograve; pi&ugrave; complessa.
</p>
</td>
</tr>
</table>
<p><span id="more-615"></span></p>
<p>
Dobbiamo creare un bridge e configurare l'interfaccia di rete della macchina virtuale per utilizzarlo. Poi dobbiamo dargli l'accesso alla rete e questo lo facciamo grazie ad un NAT.
</p>
<p>
Di seguito c'&egrave; un piccolo script che ci aiuta a configurare il tutto.
</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># set PATH for the case we are called via sudo or su root</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">USER</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #007800;">INTIF</span>=<span style="color: #ff0000;">&quot;br0&quot;</span>
<span style="color: #007800;">EXTIF</span>=<span style="color: #ff0000;">&quot;ppp0&quot;</span>
&nbsp;
<span style="color: #007800;">NUMBER_OF_VM</span>=<span style="color: #000000;">1</span>
<span style="color: #666666; font-style: italic;"># create the bridge</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>brctl addbr br0
&nbsp;
<span style="color: #666666; font-style: italic;"># create the taps and insert them into the bridge</span>
&nbsp;
<span style="color: #007800;">NB</span>=<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$NB</span> <span style="color: #660033;">-lt</span> <span style="color: #007800;">$NUMBER_OF_VM</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
   tunctl <span style="color: #660033;">-t</span> tap<span style="color: #007800;">$NB</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$USER</span>
   ip <span style="color: #c20cb9; font-weight: bold;">link</span> <span style="color: #000000; font-weight: bold;">set</span> up dev tap<span style="color: #007800;">$NB</span>
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>brctl addif br0 tap<span style="color: #007800;">$NB</span>
   <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">NB</span>=<span style="color: #007800;">$NB</span>+<span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># set the IP address and routing</span>
ip <span style="color: #c20cb9; font-weight: bold;">link</span> <span style="color: #000000; font-weight: bold;">set</span> up dev br0
ip addr add 10.1.1.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> dev br0
ip route add 10.1.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> dev br0
&nbsp;
<span style="color: #666666; font-style: italic;">####</span>
<span style="color: #666666; font-style: italic;"># Connecting the internal network to the world.</span>
<span style="color: #666666; font-style: italic;">####</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
&nbsp;
<span style="color: #666666; font-style: italic;"># clear existing iptable rules, set a default policy</span>
iptables <span style="color: #660033;">-P</span> INPUT ACCEPT
iptables <span style="color: #660033;">-F</span> INPUT
iptables <span style="color: #660033;">-P</span> OUTPUT ACCEPT
iptables <span style="color: #660033;">-F</span> OUTPUT
iptables <span style="color: #660033;">-P</span> FORWARD DROP
iptables <span style="color: #660033;">-F</span> FORWARD
iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># set forwarding and nat rules</span>
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$EXTIF</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$INTIF</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$INTIF</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$EXTIF</span> <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> <span style="color: #007800;">$EXTIF</span> <span style="color: #660033;">-j</span> MASQUERADE
&nbsp;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Virtual host network setup:&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   ip link set up dev eth0&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   ip addr add 10.1.1.2/24 dev eth0&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;   ip route add default via 10.1.1.1 dev eth0&quot;</span></pre></div></div>

<p>Lo script &egrave; abbastanza chiaro, per adattarlo alle nostre esigenze potrebbe bastare il settaggio della variabile <strong>USER</strong>, e gli indirizzi IP utilizzati non devono andare in conflitto con l'ip principale del tuo PC che probabilmente sta nella rete 192.168.0.0/16.</p>
<h2>Passi da eseguire</h2>
<ul>
<li>Lanciare lo script da utente <strong>root</strong> dopo aver impostato <strong>USER</strong></li>
<li>Configurare l'interfaccia di rete della macchina virtuale come in figura</li>
<p>[lg_image folder="virtualbox" image="ScreenshotWinXPSettings.png" width="570px"]</p>
<li>Avviare la macchina virtuale</li>
<li>Settare manualmente l'indirizzo ip della macchina virtuale, si potrebbe saltare questo passaggio configurando opportunamente un server dhcp.
<p>IP: 10.1.1.2<br />
NETMASK: 255.255.255.0<br />
DEFAULT GATEWAY: 10.1.1.1</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/virtualbox-wireless-broadband-host-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boot testuale e disabilitazione GDM in Ubuntu 10.04 (Lucid) e 10.10 (Maverick)</title>
		<link>http://www.piumalab.org/boot-testuale-e-disabilitazione-gdm-in-ubuntu-1004-lucid-e-1010-maverick/</link>
		<comments>http://www.piumalab.org/boot-testuale-e-disabilitazione-gdm-in-ubuntu-1004-lucid-e-1010-maverick/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 10:55:42 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=603</guid>
		<description><![CDATA[I giorni di /etc/inittab sembrano essere ormai finiti per Ubuntu. Ma niente paura se per qualche motivo non si vuole la grafica al login (GDM, KDM, ecc...) durante il boot di Ubuntu, ecco come fare. Vi mostrer&#242; anche come disabilitare l'immagine spash durante il boot e tornare al buon vecchio schermo nero con i log [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/ubuntu-crystal.jpg" alt="camera" title="" width="200" height="154" class="size-thumbnail wp-image-268" />
</td>
<td>
<p>
I giorni di <em>/etc/inittab</em> sembrano essere ormai finiti per Ubuntu. Ma niente paura se per qualche motivo non si vuole la grafica al login (GDM, KDM, ecc...) durante il boot di Ubuntu, ecco come fare. Vi mostrer&ograve; anche come disabilitare l'immagine spash durante il boot e tornare al buon vecchio schermo nero con i log del processo di avvio.
</p>
</td>
</tr>
</table>
<p><span id="more-603"></span></p>
<p>Questo procedimento si applica ad Ubuntu 10.04 (Lucid), 10.10 (Maverick) e non escludo alcune versioni precedenti. Il modo pi&ugrave; semplice, senza modificare il file <em>/etc/init/gdm.comf</em>, &egrave; questo:</p>
<ul>
<li>Per disabilitare GDM,KDM, ecc, editare <em>/etc/default/grub</em> e modificare la riga <strong>GRUB_CMDLINE_LINUX = ""</strong> con <strong>GRUB_CMDLINE_LINUX = "text"</strong></li>
<li>Per visualizzare i messaggi di avvio e disattivare la splash image, togliere <strong>quiet splash</strong>  da <strong>GRUB_CMDLINE_LINUX_DEFAULT</strong>. Se si vuole la splash image e del testo, utilizzare <strong>splash</strong>.</li>
<li>Eseguire il comando <em>sudo update-grub</em></li>
</ul>
<p>Fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/boot-testuale-e-disabilitazione-gdm-in-ubuntu-1004-lucid-e-1010-maverick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display per il livello di una cisterna</title>
		<link>http://www.piumalab.org/display-per-livello-acqua/</link>
		<comments>http://www.piumalab.org/display-per-livello-acqua/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 15:02:20 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Elettronica]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Sketchbook]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=574</guid>
		<description><![CDATA[In questo articolo vedremmo come costruire un dipositivo in grado di leggere e visualizzare in un display l'altezza del livello di acqua in un pozzo o una cisterna. Utilizzeremo un dispositivo hardware Open Source chiamato Arduino, un sensore ad ultrasuoni per misurare l'altezza dell'acqua, un display LCD di 16 caratteri su due linee e un [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/pozzo.png" alt="pozzo" title="" class="alignnone size-full wp-image-519" />
</td>
<td>
In questo articolo vedremmo come costruire un dipositivo in grado di leggere e visualizzare in un display l'altezza del livello di acqua in un pozzo o una cisterna. Utilizzeremo un dispositivo hardware Open Source chiamato <a href="http://www.arduino.cc/">Arduino</a>, un sensore ad ultrasuoni per misurare l'altezza dell'acqua, un display LCD di 16 caratteri su due linee e un buzzer che ci avvertir&agrave; se il livello supera una certa soglia.
</td>
</tr>
</table>
<h2>Panoramica</h2>
<p>Il progetto, come abbiamo gi&agrave; accennato, &egrave; composto da pi&ugrave; parti. Un sensore sonar da posizionare nella parte alta del pozzo (lontano dall'acqua) che guarda verso il basso cos&igrave; da misurare la distanza tra il punto pi&ugrave; alto del pozzo e l'acqua. Facendo una semplice differenza tra l'altezza dal fondo al sensore e la misura letta otteniamo l'altezza dell'acqua. Ad intervalli di tempo prestabiliti verr&agrave; letta la quantit&agrave; dell'acqua e visualizzata sul display. Se il livello supera una soglia scatter&agrave; un allarme che fa suonare il buzzer fino a quando il livello scender&agrave; di nuovo sotto la soglia o quando si disattiva manualmente la suoneria.<br />
<span id="more-574"></span><br />
Arduino controlla la logica di funzionamento, tramite un programma che vedremo di seguito, e gestisce tutti i dispositivi.</p>
<h2>Arduino</h2>
<p>Arduino &egrave; una piattaforma elettronica open-source basata sulla semplicit&agrave; e la facilit&agrave; di utilizzo. &Egrave; proprio per queste sue caratteristiche che viene utilizzata da artisti, design, hobbisti e chiunque si interessi di creare oggetti o ambienti interattivi.</p>
<p>Supporta un vasto numero di sensori ed &egrave; programmabile attraverso un linguaggio che ha molte affinit&agrave; con il C. Dal sito del progetto &egrave; possibile scaricare un enviroment con editor, compilatore e funzione di upload. Tutto ci&ograve; di cui abbiamo bisogno per programmare Arduino. &Egrave; possibile anche utilizzare strumenti a linea di comando ma ora non ci occuperemo di questo.</p>
<h2>Schema elettrico</h2>
<p><a href="/wp-content/uploads/pozzo_bb.png"><img src="/wp-content/uploads//pozzo_bb.png" alt="" title="pozzo_bb" width="630" class="alignnone size-medium wp-image-740" /></a></p>
<h2>PCB</h2>

		<div class="download-area">
			<a class="download" href="http://www.piumalab.org/wp-content/uploads/pozzo.pcb"><img alt="Download pcb per ExpressPCB here" src="http://www.piumalab.org/wp-content/themes/nest/img/download-button.gif" /></a>
			<h3><a href="http://www.piumalab.org/wp-content/uploads/pozzo.pcb">Download pcb per ExpressPCB</a></h3>
			<p>
			File size: 0 Byte<br/>
			</p>
		</div>
		
<h2>Sketchbook</h2>
<p>Di seguito c'&egrave; il programma caricato su Arduino. Il codice &egrave; molto semplice soprattutto se gi&agrave; si conosce il C o il C++. Da notare che manca la funzione <em>main()</em>, l'esecuzione inizia invocando la funzione <em>setup()</em> una sola volta all'avvio del dispositivo e poi ciclicamente la funzione <em>loop()</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* -*- mode: c -*- */</span>
<span style="color: #808080; font-style: italic;">/**
 * pozzo.pde
 * version: 1.2
 */</span>
&nbsp;
<span style="color: #339933;">#include &lt;liquidCrystal.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define PING_PIN 13</span>
<span style="color: #339933;">#define BUZZER_PIN 8</span>
<span style="color: #339933;">#define SWITCH_INT 0 /* 0 =&gt; pin 2 */</span>
<span style="color: #339933;">#define PI 3.1415926535898</span>
<span style="color: #339933;">#define SUPERFICE_BASE (R_POZZO * R_POZZO * PI)</span>
<span style="color: #339933;">#define SIZE_BAR (16 * 5)</span>
<span style="color: #339933;">#define ALARM_ICON 0 /* code */</span>
<span style="color: #339933;">#define SOUND_ICON 6 /* code */</span>
<span style="color: #339933;">#define SOUND_ICON_ON 7 /* code */</span>
&nbsp;
<span style="color: #339933;">#define R_POZZO 0.5 /* raggio pozzo (m) */</span>
<span style="color: #339933;">#define H_POZZO 146.0 /* cm */</span>
<span style="color: #339933;">#define SOGLIA_ALLARME_1 100 /* cm */</span>
<span style="color: #339933;">#define SOGLIA_ALLARME_2 120 /* cm */</span>
<span style="color: #339933;">#define DELAY_0 60000 /* ms; 1000 * 60 * 1 = 1 min */</span>
<span style="color: #339933;">#define DELAY_1 600 /* ms */</span>
<span style="color: #339933;">#define DELAY_2 200 /* ms */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* initialize the library with the numbers of the interface pins */</span>
LiquidCrystal lcd<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> mute <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
byte <span style="color: #339933;">*</span>getChar<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> n<span style="color: #339933;">,</span> byte newChar<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: #993333;">int</span> i<span style="color: #339933;">;</span>
  byte code<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    B10000<span style="color: #339933;">,</span>
    B11000<span style="color: #339933;">,</span>
    B11100<span style="color: #339933;">,</span>
    B11110<span style="color: #339933;">,</span>
    B11111<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <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> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    newChar<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> code<span style="color: #009900;">&#91;</span>n <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> newChar<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #993333;">float</span> h<span style="color: #339933;">;</span>
  byte newChar<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* set up the LCD's number of rows and columns: */</span>
  lcd.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">6</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    lcd.<span style="color: #202020;">createChar</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> getChar<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> newChar<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  newChar <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    B00000<span style="color: #339933;">,</span>
    B00100<span style="color: #339933;">,</span>
    B01010<span style="color: #339933;">,</span>
    B01010<span style="color: #339933;">,</span>
    B11111<span style="color: #339933;">,</span>
    B00100<span style="color: #339933;">,</span>
    B00000<span style="color: #339933;">,</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">createChar</span><span style="color: #009900;">&#40;</span>ALARM_ICON<span style="color: #339933;">,</span> newChar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  newChar <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    B00011<span style="color: #339933;">,</span>
    B00101<span style="color: #339933;">,</span>
    B11001<span style="color: #339933;">,</span>
    B11001<span style="color: #339933;">,</span>
    B11001<span style="color: #339933;">,</span>
    B00101<span style="color: #339933;">,</span>
    B00011<span style="color: #339933;">,</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">createChar</span><span style="color: #009900;">&#40;</span>SOUND_ICON<span style="color: #339933;">,</span> newChar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  newChar <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    B00100<span style="color: #339933;">,</span>
    B10010<span style="color: #339933;">,</span>
    B01001<span style="color: #339933;">,</span>
    B01001<span style="color: #339933;">,</span>
    B01001<span style="color: #339933;">,</span>
    B10010<span style="color: #339933;">,</span>
    B00100<span style="color: #339933;">,</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">createChar</span><span style="color: #009900;">&#40;</span>SOUND_ICON_ON<span style="color: #339933;">,</span> newChar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  pinMode<span style="color: #009900;">&#40;</span>BUZZER_PIN<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * LOW to trigger the interrupt whenever the pin is low,
   * CHANGE to trigger the interrupt whenever the pin changes value
   * RISING to trigger when the pin goes from low to high,
   * FALLING for when the pin goes from high to low.
   */</span>
  attachInterrupt<span style="color: #009900;">&#40;</span>SWITCH_INT<span style="color: #339933;">,</span> button<span style="color: #339933;">,</span> RISING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* initialize serial communication */</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">long</span> hWatherCm<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> litres<span style="color: #339933;">;</span>
&nbsp;
  hWatherCm <span style="color: #339933;">=</span> read_height<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>check_alarm<span style="color: #009900;">&#40;</span>hWatherCm<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #808080; font-style: italic;">/* read again wather height */</span>
    hWatherCm <span style="color: #339933;">=</span> read_height<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  print_histogram<span style="color: #009900;">&#40;</span>hWatherCm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>hWatherCm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; cm - &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// litres = SUPERFICE_BASE * (hWather / 100.0) * 1000</span>
  litres <span style="color: #339933;">=</span> floor<span style="color: #009900;">&#40;</span>SUPERFICE_BASE <span style="color: #339933;">*</span> hWatherCm <span style="color: #339933;">*</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>litres<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; l &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">14</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>SOUND_ICON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">15</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>mute<span style="color: #009900;">&#41;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>SOUND_ICON_ON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
  Serial.print(&quot;cm = &quot;);
  Serial.println(hWatherCm);
*/</span>
&nbsp;
  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>check_alarm<span style="color: #009900;">&#40;</span>hWatherCm<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span>
    lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>ALARM_ICON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    buzz<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span>DELAY_1<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>
&nbsp;
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span>
    lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>ALARM_ICON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    buzz<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    buzz<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    delay<span style="color: #009900;">&#40;</span>DELAY_2<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>
&nbsp;
  <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">// no alarm</span>
    delay<span style="color: #009900;">&#40;</span>DELAY_0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> print_histogram<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> hWatherCm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> bloks<span style="color: #339933;">;</span>
  <span style="color: #993333;">float</span> histogram<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// hWatherCm : HPOZZO = histogram : SIZE_BAR</span>
  histogram <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SIZE_BAR <span style="color: #339933;">*</span> hWatherCm<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> H_POZZO<span style="color: #339933;">;</span>
  histogram <span style="color: #339933;">=</span> histogram <span style="color: #339933;">+</span> <span style="color:#800080;">0.5</span><span style="color: #339933;">;</span>
&nbsp;
  bloks <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>histogram <span style="color: #339933;">/</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
&nbsp;
  <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> bloks<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>histogram<span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #0000dd;">5</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>histogram<span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">long</span> read_height<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #808080; font-style: italic;">/**
   * establish variables for duration of the ping,
   * and the distance result in centimeters:
   */</span>
  <span style="color: #993333;">long</span> duration<span style="color: #339933;">,</span> hWatherCm<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
   * Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
   */</span>
  pinMode<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delayMicroseconds<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delayMicroseconds<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/**
   * The same pin is used to read the signal from the PING))): a HIGH
   * pulse whose duration is the time (in microseconds) from the sending
   * of the ping to the reception of its echo off of an object.
   */</span>
  pinMode<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> INPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  duration <span style="color: #339933;">=</span> pulseIn<span style="color: #009900;">&#40;</span>PING_PIN<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">/* convert the time into a distance */</span>
  hWatherCm <span style="color: #339933;">=</span> H_POZZO <span style="color: #339933;">-</span> microseconds_to_centimeters<span style="color: #009900;">&#40;</span>duration<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>hWatherCm <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>hWatherCm <span style="color: #339933;">&gt;</span> H_POZZO<span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">return</span> H_POZZO<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> hWatherCm<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> buzz<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> msec<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>mute<span style="color: #009900;">&#41;</span>
    digitalWrite<span style="color: #009900;">&#40;</span>BUZZER_PIN<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span>msec<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>BUZZER_PIN<span style="color: #339933;">,</span> LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> check_alarm<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> hWatherCm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>hWatherCm <span style="color: #339933;">&gt;</span> SOGLIA_ALLARME_1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>hWatherCm <span style="color: #339933;">&lt;</span> SOGLIA_ALLARME_2<span style="color: #009900;">&#41;</span>
       <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">else</span>
       <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">2</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: #993333;">long</span> microseconds_to_centimeters<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> microseconds<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #808080; font-style: italic;">/**
   * The speed of sound is 340.29 m/s or 29.4 microseconds per centimeter.
   * The ping travels out and back, so to find the distance of the
   * object we take half of the distance travelled.
   */</span>
  <span style="color: #b1b100;">return</span> microseconds <span style="color: #339933;">/</span> <span style="color:#800080;">29.387</span> <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> button<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">//  Serial.println(&quot;Pulsante premuto&quot;);</span>
  mute <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>mute<span style="color: #339933;">;</span>
&nbsp;
  lcd.<span style="color: #202020;">setCursor</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">15</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>mute<span style="color: #009900;">&#41;</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span>SOUND_ICON_ON<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span>
    lcd.<span style="color: #202020;">write</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Immagini</h3>

<a href='http://www.piumalab.org/display-per-livello-acqua/pozzo_bb/' title='pozzo_bb'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/pozzo_bb-150x150.png" class="attachment-thumbnail" alt="pozzo_bb" title="pozzo_bb" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/261120102014/' title='261120102014'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/261120102014-150x150.jpg" class="attachment-thumbnail" alt="261120102014" title="261120102014" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/011120102011/' title='011120102011'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/011120102011-150x150.jpg" class="attachment-thumbnail" alt="011120102011" title="011120102011" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/011120102009/' title='011120102009'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/011120102009-150x150.jpg" class="attachment-thumbnail" alt="011120102009" title="011120102009" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/011120102008/' title='011120102008'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/011120102008-150x150.jpg" class="attachment-thumbnail" alt="011120102008" title="011120102008" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/011120102007/' title='011120102007'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/011120102007-150x150.jpg" class="attachment-thumbnail" alt="011120102007" title="011120102007" /></a>
<a href='http://www.piumalab.org/display-per-livello-acqua/attachment/011120102006/' title='011120102006'><img width="150" height="150" src="http://www.piumalab.org/wp-content/uploads/2010/11/011120102006-150x150.jpg" class="attachment-thumbnail" alt="011120102006" title="011120102006" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/display-per-livello-acqua/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Makefile per Java</title>
		<link>http://www.piumalab.org/java-makefile/</link>
		<comments>http://www.piumalab.org/java-makefile/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:47:48 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Sviluppo Software]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=515</guid>
		<description><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/gnu-make.jpg" alt="gnu make" title="" class="alignnone size-full wp-image-519" />
</td>
<td>
Quanti di voi programmatori Java hanno avuto problemi per la compilazione di programmi? librerie fuori da <em>$CLASSPATH</em>, parametri chilometrici da passare al compilatore Java. Anche usando ambienti di sviluppo per Java la situazione non migliora di molto. Spendiamo molto tempo a settare paramteri e ogni volta che lanciamo la compilazione manca sempre qualcosa!
</td>
</tr>
</table>
Potete evitare tutti questi problemi semplicemente organizzando i sorgenti Java e usando un <strong>Makefile</strong> scritto ad hoc.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/05/gnu-make.jpg" alt="gnu make" title="" class="alignnone size-full wp-image-519" />
</td>
<td>
Quanti di voi programmatori Java hanno avuto problemi per la compilazione di programmi? librerie fuori da <em>$CLASSPATH</em>, parametri chilometrici da passare al compilatore Java. Anche usando ambienti di sviluppo per Java la situazione non migliora di molto. Spendiamo molto tempo a settare paramteri e ogni volta che lanciamo la compilazione manca sempre qualcosa!
</td>
</tr>
</table>
<p>Potete evitare tutti questi problemi semplicemente organizzando i sorgenti Java e usando un <strong>Makefile</strong> scritto ad hoc.<br />
<span id="more-515"></span></p>
<h3>Cos'&egrave; un Makefile</h3>
<p>Un <strong>makefile</strong> &egrave; un file che descrive i passi da efftuare per arrivare ai file che vorremmo ottenere e tutto l'albero delle sue dipendenze. &Egrave; molto usato nelle piattaforme basate su Unix e pu&ograve; essere utilizzato per compilare ogni tipo di programma. L'utility <strong>make</strong> interpreta i makefile e compila il codice sorgente per ottenere programmi eseguibili e librerie.</p>
<h3>Vantaggi nell'uso di make</h3>
<p>
Molti di voi saranno scettici nell'utilizzo di un makefile per ogni progetto Java per la semplice ragione che il makefile richiede di specificare tutte le dipendenze tra i files, che sicuramente cambia da progetto a progetto. Quindi dovremmo scrivere un makefile diverso per ogni nostro progetto. Questo limite pu&ograve; essere superato scrivendo un makefile generico e in grado di calcolarsi tutte le dipendenze per il progetto da compilare in modo da utilizzare lo stesso script per tutti i progetti senza bisogno di moficare niente all'interno del makefile.
</p>
<p>
Un vantaggio sicuramente non trascurabile &egrave; la capacit&agrave; di make di compilare solo il necessario. Evita quindi di compiare ci&ograve; che &egrave; gi&agrave; compilato e non &egrave; stato modificato con un risparmio notevole di tempo.
</p>
<p>
Con un solo makefile si riesce a compilare tutti i sorgenti del progetto.
</p>
<h3>Come usarlo</h3>
<p>Il makefile che ho scritto per compilare progetti Java pu&ograve; pu&ograve; essere utilizzato senza alcuna modifica per progetti che hanno una certa struttura di directory. I sorgenti Java devono avere una directory per i .java, una per i file .class, e una per le librerie jar.<br />
Come ad esempio:
<pre>|-- src
|  `-- main
|      |-- java
|      |  `-- com
|      |      `-- example
|      |          |-- ExampleA.java
|      |          |-- ExampleB.java
|      |          `-- ExampleC.java
|      `-- resources
|          `-- Res.java
|-- classes
|-- libs
|   |-- general
|   |   |-- DataBase
|   |   |   |-- DB1.jar
|   |   |   `-- DB2.jar
|   `-- Logging
|       `-- log.jar
|-- jars
</pre>
<p>Per usarlo quindi basta scrivere il codice qu&igrave; sotto nel file <em>Makefile</em> nella directory root del progetto, verificare che il nome delle directory sia quello specificato nel file (classes per i .class; src per i .java e libs per i jar) e lanciare il comando<code>make</code><br />
questo &egrave; tutto. Se vogliamo anche un jar contenente tutto il progetto basta lanciare<code>make &#038;& make jar</code></p>
<h3>Makefile</h3>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;"><span style="color: #339900; font-style: italic;">#</span>
<span style="color: #339900; font-style: italic;"># Makefile</span>
<span style="color: #339900; font-style: italic;"># author: Danilo Abbasciano</span>
<span style="color: #339900; font-style: italic;">#</span>
&nbsp;
<span style="color: #339900; font-style: italic;"># set here the directories for classes and sources</span>
CLASS_DIR <span style="color: #004400;">=</span> classes
SOURCE_DIR <span style="color: #004400;">=</span> src
JARS_DIR <span style="color: #004400;">=</span> jars
&nbsp;
SUBDIRS <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">shell</span> find <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SOURCE_DIR</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>name <span style="color: #CC2200;">&quot;*.java&quot;</span> <span style="color: #004400;">-</span>printf <span style="color: #004400;">%</span>h\\n <span style="color: #004400;">|</span> sort <span style="color: #004400;">|</span> uniq <span style="color: #004400;">|</span> sed <span style="color: #CC2200;">'s/$(SOURCE_DIR)<span style="color: #000099; font-weight: bold;">\/</span><span style="color: #000099; font-weight: bold;">\?</span>//'</span><span style="color: #004400;">&#41;</span>
&nbsp;
JAVA_HOME<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>java<span style="color: #004400;">/</span>bin
&nbsp;
<span style="color: #339900; font-style: italic;"># compiler field</span>
<span style="color: #339900; font-style: italic;">#JDEBUGFLAGS = -g -deprecation</span>
<span style="color: #339900; font-style: italic;">#JDEBUGFLAGS = -O -depend -nowarn</span>
JCC <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">JAVA_HOME</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>javac
&nbsp;
<span style="color: #990000;">.PHONY</span><span style="color: #004400;">:</span> clean classes compile jar
&nbsp;
all<span style="color: #004400;">:</span>
	<span style="color: #004400;">@@</span>for p in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBDIRS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do \
		echo <span style="color: #CC2200;">'compile '</span> <span style="color: #000088; font-weight: bold;"><span class='MathJax_Preview'><img src='http://www.piumalab.org/wp-content/plugins/latex/cache/tex_8a8a4674122ad6903ebf61a88b72c46d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="</span>p<span style="color: #004400;">;</span> \
		<span style="color: #666622; font-weight: bold;">export</span> SUBDIR<span style="color: #004400;">=</span><span style="color: #000088; font-weight: bold;">" /></span><script type='math/tex'></span>p<span style="color: #004400;">;</span> \
		<span style="color: #666622; font-weight: bold;">export</span> SUBDIR<span style="color: #004400;">=</span><span style="color: #000088; font-weight: bold;"></script></span>p<span style="color: #004400;">;</span> \
		make <span style="color: #004400;">--</span>no<span style="color: #004400;">-</span>print<span style="color: #004400;">-</span>directory compile<span style="color: #004400;">;</span> \
	done
&nbsp;
clean<span style="color: #004400;">:</span>
	<span style="color: #004400;">-</span>rm <span style="color: #004400;">-</span>f <span style="color: #004400;">*</span>~ <span style="color: #004400;">*.</span>class <span style="color: #004400;">*.</span>bak <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">foreach</span> dir<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBDIRS</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CLASS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">dir</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/*.</span>class<span style="color: #004400;">&#41;</span>
&nbsp;
&nbsp;
LOCAL_CLASS_DIR<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CLASS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBDIR</span><span style="color: #004400;">&#41;</span>
LOCAL_SOURCE_DIR<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SOURCE_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SUBDIR</span><span style="color: #004400;">&#41;</span>
&nbsp;
jar<span style="color: #004400;">:</span>
	cd <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CLASS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> jar <span style="color: #004400;">-</span>cf <span style="color: #004400;">../$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">JARS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>project<span style="color: #004400;">.</span>jar <span style="color: #004400;">*</span>
&nbsp;
compile<span style="color: #004400;">:</span> classes
&nbsp;
<span style="color: #339900; font-style: italic;"># create target class dir if not present.</span>
<span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_CLASS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:</span>
	mkdir <span style="color: #004400;">-</span>p <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_CLASS_DIR</span><span style="color: #004400;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #339900; font-style: italic;"># new rule for java</span>
<span style="color: #990000;">.SUFFIXES</span><span style="color: #004400;">:</span>
<span style="color: #990000;">.SUFFIXES</span><span style="color: #004400;">:</span> <span style="color: #004400;">.</span>java <span style="color: #004400;">.</span>class
&nbsp;
&nbsp;
<span style="color: #339900; font-style: italic;"># magical command that tells make to find class files in another dir</span>
<span style="color: #666622; font-weight: bold;">vpath</span> <span style="color: #004400;">%.</span>class <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_CLASS_DIR</span><span style="color: #004400;">&#41;</span>
<span style="color: #666622; font-weight: bold;">vpath</span> <span style="color: #004400;">%.</span>java <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_SOURCE_DIR</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;"># classpath; all in ./jars and ./libs</span>
LIBCLASSPATH<span style="color: #004400;">:=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CLASS_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SOURCE_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">:$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">subst</span> <span style="color: #004400;">.</span>jar <span style="color: #004400;">,.</span>jar<span style="color: #004400;">:,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> libs<span style="color: #004400;">/*.</span>jar libs<span style="color: #004400;">/*/*.</span>jar libs<span style="color: #004400;">/*/*/*.</span>jar jars<span style="color: #004400;">/*.</span>jar<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
&nbsp;
<span style="color: #339900; font-style: italic;"># compil command</span>
<span style="color: #004400;">.</span>java<span style="color: #004400;">.</span>class<span style="color: #004400;">:</span>
	CLASSPATH<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LIBCLASSPATH</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">JCC</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>nowarn <span style="color: #004400;">-</span>d <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">CLASS_DIR</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">JDEBUGFLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #000088; font-weight: bold;">$&lt;</span>
&nbsp;
<span style="color: #339900; font-style: italic;"># find out target files</span>
PATHFILES <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_SOURCE_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/*.</span>java<span style="color: #004400;">&#41;</span>
FILES <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">subst</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">LOCAL_SOURCE_DIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/,,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">PATHFILES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
classes<span style="color: #004400;">:</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span>FILES<span style="color: #004400;">:.</span>java<span style="color: #004400;">=.</span>class<span style="color: #004400;">&#41;</span></pre></div></div>

<p>Buona compilazione.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/java-makefile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cancellare i file creati dall&#039;apertura di un archivio</title>
		<link>http://www.piumalab.org/unpkg-cancellare-i-file-creati-da-un-archivio/</link>
		<comments>http://www.piumalab.org/unpkg-cancellare-i-file-creati-da-un-archivio/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 13:25:26 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Bash script]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=489</guid>
		<description><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/unpack.png" alt="" title="" width="170" height="170" class="alignnone size-full wp-image-492" />
</td>
<td>
Quante volte ci &#232; capitato di estrarre archivi e ritrovarci con centinaia di files e directories sparsi ovunque. Questo accade quando gli archivi sono sono creati senza includere la cartella di lavoro. Quello che potevate fare fino a ieri &#232; di cancellare tutti i file nuovi facendo molta attenzione a non toccare i file che erano l&#236; precedentemente. Oggi grazie a questo piccolo script Bash &#232; possibile fare questo in modo del tutto automatico e senza rischi per il sistema e per i nostri files.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/04/unpack.png" alt="" title="" width="170" height="170" class="alignnone size-full wp-image-492" />
</td>
<td>
<h3>unpkg.sh: Un piccolo ma molto utile script</h3>
<p>Quante volte ci &egrave; capitato di estrarre archivi e ritrovarci con centinaia di files e directories sparsi ovunque. Questo accade quando gli archivi sono sono creati senza includere la cartella di lavoro. Quello che potevate fare fino a ieri &egrave; di cancellare tutti i file nuovi facendo molta attenzione a non toccare i file che erano l&igrave; precedentemente.
</td>
</tr>
</table>
<p>Oggi grazie a questo piccolo script Bash &egrave; possibile fare questo in modo del tutto automatico e senza rischi per il sistema e per i nostri files. <span id="more-489"></span> Basta lanciare lo script passandogli come argomento il package. <code>$ unpkg.sh &lt;archivio1(.tar|.tgz|.tar.gtz|.tar.gz2|.zip)> [ ... &lt;archivioN>]</code>Come abbiamo visto lo script pu&ograve; accettare anche pi&ugrave; di un archivio e supporta i formati: <strong>tar</strong>, <strong>tgz</strong>, <strong>tar.gz2</strong> e <strong>zip</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tgz<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tar</span> ftz <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar.gz<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tar</span> ftz <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar.gz2<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tar</span> ftj <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.tar<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tar</span> ft <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span>.zip<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           <span style="color: #007800;">FILE_LIST</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">zipinfo</span> <span style="color: #660033;">-1</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$file</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #007800;">IFS</span>=$<span style="color: #ff0000;">'\n'</span>
            <span style="color: #000000; font-weight: bold;">for</span> FILE <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$FILE_LIST</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-fr</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
                    <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILE</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
            <span style="color: #000000; font-weight: bold;">done</span>;
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;File format not supported (<span style="color: #007800;">$file</span>)&quot;</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/unpkg-cancellare-i-file-creati-da-un-archivio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MUSICI.IT : nasce il più innovativo dei portali di annunci per musicisti</title>
		<link>http://www.piumalab.org/musici-innovativo-portale-di-annunci-per-musicisti/</link>
		<comments>http://www.piumalab.org/musici-innovativo-portale-di-annunci-per-musicisti/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 09:43:08 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Comunicato stampa]]></category>
		<category><![CDATA[Musica]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=479</guid>
		<description><![CDATA[<table>
<tr><td>
<img src="http://www.piumalab.org/wp-content/uploads/musici_288x100.png" alt="logo Musici.it" title="musici_288x100" width="288" height="100" class="alignnone size-full wp-image-481" />
</td>
<td>
Diventare il principale punto di riferimento per musicisti di qualsiasi genere, provenienti da ogni parte d’Italia, per dare vita alla massima espressione dell’arte: <strong>la musica!</strong>
</td>
</tr>
</table>
È con questa ambizione che <a href='http://www.musici.it' title="riferimento per musicisti">Musici.it</a> vuole proporre ai propri utenti una piattaforma in grado di dare visibilità a <strong>migliaia di annunci</strong>, rivoluzionando il livello d’interazione sito-utente, grazie agli ingenti studi condotti sulla web utility applicati alla progettazione del layout grafico.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/03/musici_288x100.png" alt="logo Musici.it" title="musici_288x100" width="288" height="100" class="alignnone size-full wp-image-481" />
</td>
<td>
Diventare il principale punto di riferimento per musicisti di qualsiasi genere, provenienti da ogni parte d’Italia, per dare vita alla massima espressione dell’arte: <strong>la musica!</strong>
</td>
</tr>
</table>
<p>È con questa ambizione che <a href='http://musici.piumalab.org' title="riferimento per musicisti">Musici.it</a> vuole proporre ai propri utenti una piattaforma in grado di dare visibilità a <strong>migliaia di annunci</strong>, rivoluzionando il livello d’interazione sito-utente, grazie agli ingenti studi condotti sulla web usability applicati alla progettazione del layout grafico.<br />
<span id="more-479"></span></p>
<p>La principale novità introdotta da <a href='http://musici.piumalab.org' title="Inserzioni di musicisti">Musici.it</a>, sarà a breve, di permettere di aggiungere ai normali annunci anche immagini, brani audio o filmati. Miglioramenti finalizzati per permettere, in maniera totalmente gratuita ai propri utenti, di personalizzare il proprio annuncio.</p>
<p>Non è esclusa la possibilità dell’ampliamento dell’offerta con l’aggiunta di nuove sezioni, sempre inerenti il mondo della musica, come ad esempio annunci di scuole di musica, sale prove e di registrazione, fino alla compra/vendita di dischi e strumenti musicali. <a href='http://musici.piumalab.org' title="Annunci di musica">Musici.it</a> è anche aperto alle proposte inoltrate dai propri utenti.</p>
<p>Visita il sito <a href='http://musici.piumalab.org' title="Annunci di musicisti">www.musici.it</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/musici-innovativo-portale-di-annunci-per-musicisti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alla ricerca del CAPTCHA perfetto</title>
		<link>http://www.piumalab.org/good-captcha/</link>
		<comments>http://www.piumalab.org/good-captcha/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 08:37:17 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Sicurezza]]></category>
		<category><![CDATA[Sviluppo Software]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=438</guid>
		<description><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/captcha_banner1.jpg" alt="" title="" width="300" height="89" class="alignnone size-full wp-image-448" />
</td>
<td>
Un <em>CAPTCHA</em>, "<strong>c</strong>ompletely <strong>a</strong>utomated <strong>p</strong>ublic <strong>T</strong>uring test to tell <strong>c</strong>omputers and <strong>h</strong>umans <strong>a</strong>part", &#232; un test in grado di determinare se l'utente sia effettivamente
</td>
</tr>
</table>
umano e non un computer. Questi metodi vengono utilizzati per impedire che i bot utilizzino dei servizi come scrivere commenti o riempire form. L'uso dei <em>captcha</em> risulta essere indispensabile per evitare il proliferare dello spam.

<h3>Come si giudica un buon captcha</h3>

Molti di voi penseranno che un buon captcha sia quello pi&#249; difficile da risolvere. Cos&#236; da rendere la vita difficile agli algoritmi. Per quelli di tipo visuale esistono infatti algoritmi in grado di convertire un immagine in un testo chiamati Optical Character Recognition.

Io credo che le caratteristiche che rendano un captcha buono siano altre, come l'accessibilit&#224;, la facile comprensione da parte di un umano, la possibilit&#224; di essere generati in modo automatico e allo stesso tempo abbastanza complesso da risultare impossibile da risolvere da parte di algoritmi anche basati su intelligenza artificiale.

La sfida che mi sono posto &#232; quella di poter realizzare un unico captcha che ha queste caratteristiche. Perch&#233; dico unico, perch&#233; sempre pi&#249; spesso i siti utilizzano pi&#249; di un metodo di autenticazione in parallelo come un captcha visuale affiancato da uno sonoro. Dopo che si sono accorti che uno di essi o entrambi non risultano efficaci.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/03/captcha_banner1.jpg" alt="" title="" width="300" height="89" class="alignnone size-full wp-image-448" />
</td>
<td>
Un <em>CAPTCHA</em>, "<strong>c</strong>ompletely <strong>a</strong>utomated <strong>p</strong>ublic <strong>T</strong>uring test to tell <strong>c</strong>omputers and <strong>h</strong>umans <strong>a</strong>part", &egrave; un test in grado di determinare se l'utente sia effettivamente
</td>
</tr>
</table>
<p>umano e non un computer. Questi metodi vengono utilizzati per impedire che i bot utilizzino dei servizi come scrivere commenti o riempire form. L'uso dei <em>captcha</em> risulta essere indispensabile per evitare il proliferare dello spam.</p>
<h3>Come si giudica un buon captcha</h3>
<p>Molti di voi penseranno che un buon captcha sia quello pi&ugrave; difficile da risolvere. Cos&igrave; da rendere la vita difficile agli algoritmi. Per quelli di tipo visuale esistono infatti algoritmi in grado di convertire un immagine in un testo chiamati Optical Character Recognition.</p>
<p>Io credo che le caratteristiche che rendano un captcha buono siano altre, come l'accessibilit&agrave;, la facile comprensione da parte di un umano, la possibilit&agrave; di essere generati in modo automatico e allo stesso tempo abbastanza complesso da risultare impossibile da risolvere da parte di algoritmi anche basati su intelligenza artificiale.</p>
<p><span id="more-438"></span><br />
La sfida che mi sono posto &egrave; quella di poter realizzare un unico captcha che ha queste caratteristiche. Perch&eacute; dico unico, perch&eacute; sempre pi&ugrave; spesso i siti utilizzano pi&ugrave; di un metodo di autenticazione in parallelo come un captcha visuale affiancato da uno sonoro. Dopo che si sono accorti che uno di essi o entrambi non risultano efficaci.</p>
<h3>L'accessibilit&agrave;</h3>
<p>Per anni i captcha visivi sono stati responsabili di una grave discriminazione ai danni di chiunque avesse problemi di vista. La loro esistenza ha reso inaccessibili milioni di siti che li hanno adottati come difesa dagli spammer, frapponendo una barriera, che ormai tutti consideravano insuperabile, tra l’utente e il servizio in rete.</p>
<p>Nulla sono valse le <a href="http://www.petitiononline.com/captcha/">petizioni on line</a> contro questo tipo di captcha, che continuano indisturbatamente a proliferare nel web. Inoltre le nuove generazioni di captcha, create per resistere ai più sofisticati programmi di riconoscimento di testi, possono essere molto difficili o impossibili per molti utenti, anche nel pieno possesso della propria capacità visiva.</p>
<p>Proprio per questo motivo il captcha perfetto non dovr&agrave; essere n&eacute; visuale n&eacute; di tipo uditivo.</p>
<h3>Generazione automatica</h3>
<p>La soluzione &egrave; quella di adottare metodi testuali. Ma non sempre &egrave; possibile. Domande come: <em>Di che colore era il cavallo bianco di Napoleone?</em> oppure <em>Qual'&egrave; il risultato di due per sette?</em> Risultano essere ottime per quanto riguarda l'accessibilit&agrave;, la comprensione da parte dell'uomo e la difficolt&agrave; di essere risolti da parte di programmi.</p>
<p>Il loro unico problema &egrave; l'impossibilit&agrave; di poter generare automaticamente queste domande rendendo questo metodo praticamente inutilizzabile.</p>
<h3>Facile da risolvere per gli utenti</h3>
<p>Non sempre i metodi utilizzati risultano essere di facile risoluzione per gli utenti, potete vedere in figura un form per la registrazione alquanto difficile.<br />
<div id="attachment_454" class="wp-caption alignnone" style="width: 510px"><img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/03/hard_maptcha.png" alt="hard captcha" title="" width="500" height="240" class="alignnone size-full wp-image-457" /><p class="wp-caption-text">hard captcha</p></div></p>
<h3>Un buon captcha</h3>
<p>Leggendo queste righe vi sarete resi conto di quanto sia difficile conciliare l'efficacia e la facilit&agrave; di utilizzo di un buon metodo per proteggere le proprie risorse. Per questo motivo ho deciso di svilupparne io stesso uno, che, non sar&agrave; certo il captcha perfetto ma diciamo che le sue caratteristiche sono molto buone.</p>
<p>Si tratta di un captcha testuale, semplice da generare automaticamente, e facile da risolvere per gli utenti. Il lavoro pi&ugrave; duro non &egrave; stata l'implementazione ma come spesso accade &egrave; stata la ricerca dell'idea giusta.</p>
<p>L'idea &egrave; quella di prendere una parola abbastanza lunga e scambiare la posizione di due lettere diverse. L'utente dovr&agrave; correggere la parola scritta in modo errato.</p>
<div id="attachment_440" class="wp-caption alignnone" style="width: 610px"><img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/03/captcha.png" alt="captcha" title="" width="600" height="188" class="size-full wp-image-440" /><p class="wp-caption-text">captcha</p></div>
<p>L'uso di questo metodo &egrave; stato impiegato nel sito <a href="http://www.musici.it" title="annunci musicicali e di musicisti">musici</a> nella <a href="http://www.musici.it/informazioni">sezione utilizzata per richiedere informazioni</a>.</p>
<p>L'unica carenza di questo metodo &egrave; che con un semplice algoritmo &egrave; possibile risolverlo. Ma sono anche convinto che non &egrave; necessario utilizzare una cassaforte per proteggere pochi spiccioli. Quindi in attesa di trovare un idea migliore e riuscire finalmente a porre fine alla ricerca del captcha perfetto continuer&ograve; ad utilizzare e consiglirvi questo metodo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/good-captcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Congettura di Goldbach</title>
		<link>http://www.piumalab.org/congettura-di-goldbach/</link>
		<comments>http://www.piumalab.org/congettura-di-goldbach/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 15:32:12 +0000</pubDate>
		<dc:creator>Piuma</dc:creator>
				<category><![CDATA[ANSI C]]></category>
		<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Matematica]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Sviluppo Software]]></category>

		<guid isPermaLink="false">http://www.piumalab.org/?p=366</guid>
		<description><![CDATA[<table>
<tr>
<td>
<img src="http://www.piumalab.org/wp-content/uploads/numbers.jpg" alt="" title="" width="90" height="90" class="alignnone size-full wp-image-371" />
</td>
<td>
Una <strong>congettura</strong> &#232; una affermazione ritenuta probabilmente vera ma non ancora dimostrata. Una vota dimostrata la sua validit&#224; diviene un <strong>teorema</strong>. La <strong>Congettura di Goldbach</strong> &#232; uno dei problemi pi&#249; vecchi non ancora risolti, infatti risale al 1742, fu enunciata da Goldbach e riformulata da Euler nel seguente modo:
</td>
</tr>
</table>
<p>
<strong><em>Ogni numero naturale pari maggiore di 2 puo' esere scritto come la somma di due
numeri primi.</em></strong>
</p>
<h3>Proviamo a dimostrare la sua inesattezza</h3>
Su una congettura possiamo effettuare due tipo di dimostrazioni, possiamo dimostrare la sua correttezza o la sua inesattezza. Ovviamente l'una esclude l'altra. Tenteremo di dimostrare che la congettura &#232; falsa, per fare ci&#242; basta trovare un controesempio tele che l'enunciato risulti falso. Quindi nel nostro caso basta trovare un solo numero pari che non &#232; la somma di due primi. Per trovare questo numero scriveremo un programma.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://devcapsula.no-ip.org/wordpress/wp-content/uploads/2009/02/numbers.jpg" alt="" title="" width="90" height="90" class="alignnone size-full wp-image-371" />
</td>
<td>
Una <strong>congettura</strong> &egrave; una affermazione ritenuta probabilmente vera ma non ancora dimostrata. Una vota dimostrata la sua validit&agrave; diviene un <strong>teorema</strong>. La <strong>Congettura di Goldbach</strong> &egrave; uno dei problemi pi&ugrave; vecchi non ancora risolti, infatti risale al 1742, fu enunciata da Goldbach e riformulata da Euler nel seguente modo:
</td>
</tr>
</table>
<p>
<strong><em>Ogni numero naturale pari maggiore di 2 puo' esere scritto come la somma di due<br />
numeri primi.</em></strong>
</p>
<p>Ad esempio:<br />
4  = 2 + 2<br />
6  = 3 + 3<br />
8  = 3 + 5<br />
10 = 3 + 7 = 5 + 5<br />
12 = 5 + 7<br />
14 = 3 + 11 = 7 + 7<br />
16 = 3 + 13 = 5 + 11</p>
<h3>Proviamo a dimostrare la sua inesattezza</h3>
<p>Su una congettura possiamo effettuare due tipo di dimostrazioni, possiamo dimostrare la sua correttezza o la sua inesattezza. Ovviamente l'una esclude l'altra. Tenteremo di dimostrare che la congettura &egrave; falsa, per fare ci&ograve; basta trovare un controesempio tele che l'enunciato risulti falso. Quindi nel nostro caso basta trovare un solo numero pari che non &egrave; la somma di due primi. Per trovare questo numero scriveremo un programma.<br />
<span id="more-366"></span></p>
<h3>Alcune considerazioni</h3>
<p>Tutti i numeri primi sono dispari ad eccezione di 2. Questo &egrave; vero per la definizione di numero dispari. Il numero primo 2 sommato ad un qualsiasi altro numero primo da come risultato un numero dispari. L'unico caso per cui 2 sommato ad un altro numero primo abbia come risultato un numero pari &egrave; 2 + 2. Da questo si deduce che il 4 &egrave; l'unico numero pari che si pu&ograve; scrivere come somma del numero primo 2 con un altro numero primo. Nel programma si considerano i numeri primi senza il 2 e tutti i numeri pari maggiori di quattro.</p>
<h3>Scomponiamo il problema in sotto problemi</h3>
<p>Le azioni che compie il programma possono schematizarsi in una succesioni di fasi distinte:</p>
<ol>
<li>Trovare tutti i numeri primi da 3 ad <strong>n</strong></li>
<li>Prendere tutte le coppie di numeri primi (p1, p2) tali che la loro somma non superi <strong>n</strong> (cio&egrave; p1 + p2 <= n) e se viene considerato (p1, p2) allora verr&agrave; scartato (p2, p1).</li>
<li>Marcare i pari da 6 ad <strong>n</strong> se essi sono il risultato di p1 + p2 per ogni coppia (p1, p2) trovata precedentemente.</li>
<li>Stampare tutti i numeri pari non marcati come somma di numeri primi.</li>
</ol>
<h3>Crivello di Eratostene</h3>
<p>Per torvare tutti i numeri primi da 3 ad <strong>n</strong> esiste un metodo antichissimo noto come <em>Crivello di Eratostene</em>. Esso consiste nello scrivere tutti i numeri da 2 a <strong>n</strong> e cancellare successivamente tutti i multipli di 2(escluso), tutti i multipli di 3(escluso), tutti i multipli di 5(escluso) e così via. I numeri "sopravvissuti" saranno tutti e soli i numeri primi compresi tra 2 ed <strong>n</strong>.</p>
<p>Quindi utilizziamo un vettore di flag <strong>v</strong>, l'idea e' semplice, dobbiamo marcare tutti i numeri multipli di 2, 3, 5, ecc.. cos&igrave; i rimanenti sono primi. Per economizzare la memoria ho fatto partire il vettore da 3 ed esaminato solo i numeri dispari, esempio:</p>
<p>indice vettore(i): 0  1  2  3  4  5  6<br />
informazione  (j): 3  5  7  9  11 13 15<br />
v[i]             : T  T  T  F  T  T  F</p>
<p>per passare da i a j utilizzo la funzione j = 2*i + 3<br />
viceversa i = (j - 3)/2<br />
Nota: j - 3 da sempre un numero divisibile per due dato che i j sono tutti dispari.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> riempi_v<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> k<span style="color: #339933;">;</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> Size<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<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>v<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> TRUE<span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>k <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i <span style="color: #339933;">+</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>k <span style="color: #339933;">&lt;</span> n <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> k <span style="color: #339933;">=</span> k <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
        v<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #339933;">*</span>k <span style="color: #339933;">+</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">*</span>k <span style="color: #339933;">-</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> FALSE<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Algoritmo di backtracking</h3>
<p>Una volta ottenuto il vettore <strong>v</strong> s&ograve; quali sono i numeri primi fino ad <strong>n</strong>.<br />
Ora dovr&ograve; trovare tutte le coppie (p1, p2). Per fare questo utilizzo un algoritmo che sfrutta il metodo del backtracking. L'algoritmo "pota" l'albero delle ricorsioni in modo da non considerare affatto le coppie di numeri che non interessano. Cos&igrave; da essere il pi&ugrave; ottimizzato possibile, ci accorgeremo che l'ottimizzazione di questo programma &egrave; fondamentale se vogliamo raggiungere buoni risultati.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* trova e somma tutte le coppie di numeri primi trovati precedentemente */</span>
<span style="color: #993333;">void</span> backtraking<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">int</span> n<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> p1<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> p2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> x<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    pari<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>p1<span style="color: #339933;">+</span>p2<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> FALSE<span style="color: #339933;">;</span>
    <span style="color: #808080; font-style: italic;">/* printf(&quot;(%d,%d)\n&quot;,p1, p2); */</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> x <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x <span style="color: #339933;">=</span> primo_successivo<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        backtraking<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> i <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> p2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
      <span style="color: #808080; font-style: italic;">/**
       * Inizializzare x con p1 per verificare la congettura di Goldback.
       * Porre x = primo_successivo(n, p1) per trovare tutti i pari
       * dati da p1 + p2 con p1 != p2
       */</span>
      <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">=</span> p1<span style="color: #339933;">;</span> x <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x <span style="color: #339933;">=</span> primo_successivo<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</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>p1 <span style="color: #339933;">+</span> x <span style="color: #339933;">&lt;=</span> n<span style="color: #009900;">&#41;</span>
          backtraking<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> i <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> p1<span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Trovata la coppia (p1, p2) fa la somma e aggiorna il vettore <strong>pari</strong>. Il vettore <strong>pari</strong> ha dimensione n/2, ogni elemento corrisponde ad un numero pari.</p>
<p>Abbiamo sviluppato i punti 1, 2 e 3 del nostro problema, non ci resta che scorre il vettore dei pari e stampare solo l'indice in presenza di un numero pari che non &egrave; la somma di due primi.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">  <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> n<span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pari<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> TRUE<span style="color: #009900;">&#41;</span>
      <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d:i = %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pari<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Risultati</h3>
<p>Vi accorgerete effettaundo dei tests che all'aumentare di <strong>n</strong> aumenta anche il tempo di esecuzione. Con un computer ad un processore Intel da 5336.88 <a href="http://en.wikipedia.org/wiki/Bogomips">bogomips</a> ho impiegato 5 giorni con <strong>n</strong> uguale a 100'000'000.</p>
<p>La congettura di Goldbach si suppone sia vera dal fatto che la probabilit&agrave; per un numero pari di essere somma di due primi cresce al crescere del numero. Esiste un progetto di calcolo distribuito che ha finora verificato la congettura fino a 2 * 10<sup>17</sup> (nel momento in cui scrivo.)</p>
<h3>Un'altra congettura</h3>
<p>Non voglio paragonarmi ad Euler o Goldbach ma forse troverete interessante anche quest'altra congettura che mi &egrave; passta per la mente durante la stesura del programma in questione. &Egrave; un affinamento dell'enunciato di Goldbach.</p>
<p>
<strong><em>Tutti i numeri naturali maggiori di 6 e pari possono essere scritti come somma di due primi p1 e p2 tali che p1 &egrave; diverso da p2</em></strong>
</p>
<p>A voi la dimostrazione. Posso dirvi con certezza che fino a 10<sup>8</sup> risulta vera.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.piumalab.org/congettura-di-goldbach/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

