<?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>Riders Of The Bit</title>
	<atom:link href="http://ridersofthebit.net/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://ridersofthebit.net/blog</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Wed, 07 Dec 2011 23:12:38 +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>Whislist</title>
		<link>http://ridersofthebit.net/blog/?p=521</link>
		<comments>http://ridersofthebit.net/blog/?p=521#comments</comments>
		<pubDate>Wed, 07 Dec 2011 23:01:58 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[Fotografía]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[fnac]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[sony]]></category>
		<category><![CDATA[whislist]]></category>

		<guid isPermaLink="false">http://ridersofthebit.net/blog/?p=521</guid>
		<description><![CDATA[Ya vienen las fiestas de Navidad y con ellas los ajetreos por hacer todas las compras de regalos&#8230; esto para mi padre, esto para mi madre, etc. ¡Y como no, los regalos para mi! Una cámara fotográfica nueva. Para poder &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=521">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Ya vienen las fiestas de Navidad y con ellas los ajetreos por hacer todas las compras de regalos&#8230; esto para mi padre, esto para mi madre, etc. ¡Y como no, los regalos para mi!</p>
<p>Una cámara fotográfica nueva. Para poder seguir haciendo fotografías increíbles. Como ya sabéis, personalmente me encanta la nueva <a title="Sony A77" href="http://www.fnac.es/Sony-A77-18-55-MM-Camara-Reflex-Digital-Camara-de-fotos-reflex-Camara-fotos-reflex-digital/a670139?PID=4503&amp;Mn=-1&amp;Ra=-5000&amp;To=0&amp;Nu=1&amp;Fr=2" target="_blank">Sony A77</a>. En la sección de fotografía de <strong>Fnac</strong>, encontraremos esta fantastica cámara a un precio alucinante: <strong>1301,07</strong>€.</p>
<div class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fnac.es/Sony-A77-18-55-MM-Camara-Reflex-Digital-Camara-de-fotos-reflex-Camara-fotos-reflex-digital/a670139?PID=4503&amp;Mn=-1&amp;Ra=-5000&amp;To=0&amp;Nu=1&amp;Fr=2"><img class="  " title="Sony A77" src="http://multimedia.fnac.es/multimedia/ES/images_produits/ES/ZoomPE/3/7/0/4905524807073.jpg" alt="Sony A77" width="300" height="253" /></a><p class="wp-caption-text">Sony A77</p></div>
<p>Y ya puestos a pedir a Papá Noel o a los Reyes Magos, pues aprovecho para sugerir un <a title="iPad de Apple con WiFi y 3G con 32" href="http://www.fnac.es/Apple-iPad-2-con-WiFi-y-3G-32-GB-color-blanco-Ordenador-portatil-Tablet/a429395?PID=14395&amp;Mn=-1&amp;Ra=-5000&amp;To=0&amp;Nu=4&amp;Fr=2" target="_blank">iPad 2, de Apple, con WiFi y 3G con 32GB</a> para poder mostrar las fotos que hagamos con la cámara y de paso leer el último comentario que nos dejen en Flickr, en 500px o en este blog de tecnología. Como es habitual, cualquier modelo de iPad se puede encontrar en cualquier tienda <strong>Fnac</strong>. Y concretamente este modelo a un precio espectacular: <strong>699</strong>€.</p>
<div class="wp-caption aligncenter" style="width: 310px"><a href="http://www.fnac.es/Apple-iPad-2-con-WiFi-y-3G-32-GB-color-blanco-Ordenador-portatil-Tablet/a429395?PID=14395&amp;Mn=-1&amp;Ra=-5000&amp;To=0&amp;Nu=4&amp;Fr=2"><img class=" " title="iPad 2 de Apple con WiFi y 3G con 32GB" src="http://multimedia.fnac.es/multimedia/ES/images_produits/ES/ZoomPE/4/9/2/0885909471294.jpg?201103241906" alt="iPad 2 de Apple con WiFi y 3G con 32GB" width="300" height="300" /></a><p class="wp-caption-text">iPad 2 de Apple con WiFi y 3G con 32GB</p></div>
<p>¡Un abrazo a tod@s y que disfrutéis de las Navidades¡</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=521</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySql tunning</title>
		<link>http://ridersofthebit.net/blog/?p=504</link>
		<comments>http://ridersofthebit.net/blog/?p=504#comments</comments>
		<pubDate>Sun, 26 Jun 2011 18:05:00 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Reflexiones]]></category>
		<category><![CDATA[explain]]></category>
		<category><![CDATA[mysq]]></category>
		<category><![CDATA[optimizador]]></category>
		<category><![CDATA[tunning]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=504</guid>
		<description><![CDATA[Uno de los primeras cosas que hay que saber antes de empezar a optimizar consultas en MySql es conocer la existencia de la cláusula EXPLAIN. Con EXPLAIN podemos obtener el plan de ejecución de una consulta dada, como se muestra &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=504">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Uno de los primeras cosas que hay que saber antes de empezar a optimizar consultas en <em>MySql</em> es conocer la existencia de la cláusula <em>EXPLAIN</em>.</p>
<p>Con <em>EXPLAIN</em> podemos obtener el plan de ejecución de una consulta dada, como se muestra en el siguiente ejemplo:</p>
<pre>EXPLAIN SELECT * FROM People</pre>
<p>Resultado:</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>select_type</th>
<th>table</th>
<th>type</th>
<th>possible_keys</th>
<th>key</th>
<th>key_len</th>
<th>ref</th>
<th>rows</th>
<th>Extra</th>
</tr>
<tr>
<td>1</td>
<td>SIMPLE</td>
<td>People</td>
<td>ALL</td>
<td>NULL</td>
<td>NULL</td>
<td>NULL</td>
<td>NULL</td>
<td>979</td>
<td></td>
</tr>
</tbody>
</table>
<p>En el ejemplo anterior el plan de ejecución es un simple <em>full scan</em> (type = ALL) de toda la tabla People.</p>
<p>Vamos a ver otro ejemplo:</p>
<pre>EXPLAIN SELECT * FROM People WHERE gender = 'Male'</pre>
<p>Resultado:</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>select_type</th>
<th>table</th>
<th>type</th>
<th>possible_keys</th>
<th>key</th>
<th>key_len</th>
<th>ref</th>
<th>rows</th>
<th>Extra</th>
</tr>
<tr>
<td>1</td>
<td>SIMPLE</td>
<td>People</td>
<td>ALL</td>
<td>NULL</td>
<td>NULL</td>
<td>NULL</td>
<td>NULL</td>
<td>979</td>
<td>Using where</td>
</tr>
</tbody>
</table>
<p>En este caso vemos que la consulta devuelve al motor de base de datos sigue devolviendo todos los registros en un <em>full scan</em>.  En este caso podemos optimizar la consulta creando un índice para <em>gender</em> (<strong>Idx_gender</strong>). Y de esta forma el resultado de <em>EXPLAIN</em> será:</p>
<table>
<tbody>
<tr>
<th>id</th>
<th>select_type</th>
<th>table</th>
<th>type</th>
<th>possible_keys</th>
<th>key</th>
<th>key_len</th>
<th>ref</th>
<th>rows</th>
<th>Extra</th>
</tr>
<tr>
<td>1</td>
<td>SIMPLE</td>
<td>People</td>
<td>ref</td>
<td>Idx_gender</td>
<td>Idx_gender</td>
<td>22</td>
<td>const</td>
<td>489</td>
<td>Using where</td>
</tr>
</tbody>
</table>
<p>Ahora se puede ver como ya no se requiere un <em>full scan </em>(<em>type != ALL</em>) y únicamente la filas con valores en el índice serán las seleccionadas.</p>
<p>Hasta ahora se puede intuir que cuando el tipo es ALL y no queremos un <em>full scan </em>(todas las filas), siempre se puede optimizar. Lo más sencillo es con la creación de índices que agilicen las búsquedas más frecuentes.</p>
<p>A continuación teneís el detalle de todos los campos que devuelve <em>EXPLAIN</em>:</p>
<p><strong>Id:</strong> El identificador de la <em>SELECT</em>. Es un número secuencial.</p>
<p><strong>Select_type:</strong> Tipo de la <em>SELECT</em>.</p>
<ul>
<li>SIMPLE: <em>SELECT</em> simple, sin <em>UNION</em> o subconsultas.</li>
<li>PRIMARY: Se refiere a la consulta &#8220;más externa&#8221;; a la principal.</li>
<li>UNION: Resto de consulta/s (segunda, tercera, etc.) en una <em>UNION</em>.</li>
<li>DEPENDENT UNION: Resto de consulta/s (segunda, tercera, etc.) en una <em>UNION</em> que depende una una consulta &#8220;externa&#8221;; <em>PRIMARY</em>.</li>
<li>UNION RESULT: Resultado de una <em>UNION</em>.</li>
<li>SUBQUERY: Primera consulta de una subconsulta.</li>
<li>DEPENDENT SUBQUERY: Primera consulta de una subconsulta que depende una consulta &#8220;externa&#8221;.</li>
<li>DERIVED: Tabla derivada en una <em>SELECT</em>; subquery en la cláusula <em>FROM</em>.</li>
<li>UNCACHEABLE SUBQUERY: Subconsulta que no puede ser almacenada en caché, o re-evaluada.</li>
<li>UNCACHEABLE UNION: Resto de consulta/s (segunda, tercera, etc.) en una <em>UNION</em> que no puede ser almacenada en caché, o re-evaluada.</li>
</ul>
<p><strong>Table:</strong> tabla a la que se refiere la fila del resultado.</p>
<p><strong>Type:</strong> el tipo de JOIN. Los tipos de muestran a continuación ordenados desde el mejor al peor.</p>
<ul>
<li>system: la tabla únicamente tiene una fila y es una tabla del sistema. Es un caso especial del tipo <em>const</em>.</li>
<li>const: en la tabla coincide una única fila que el optimizador tomo como constante. También se utiliza cuando se comparan todas las partes de una clave primaria o un índice único (<em>UNIQUE</em>) con un valor constante.</li>
<li>Eq_ref: una fila de una tabla es leída por cada combinación de filas en una segunda tabla. Se utiliza cuando se usan todas las partes de una clave primaria o un índice único (<em>UNIQUE</em>).</li>
<li>ref: todas las filas que coincidan con con los valores de un índice serán leídos por cada combinación de filas de las tablas anteriores. En <em>JOIN</em> se utiliza cuando no se puede seleccionar una única fila en base al valor de la clave. Puede ser usada, por el optimizador, en columnas indexadas que se comparan con =, &lt;=&gt;.</li>
<li>fulltext: la <em>JOIN</em> se realiza con un índice <em>FULLTEXT</em>.</li>
<li>ref or null: el tipo de JOIN es como ref pero hay una búsqueda extra para campos nulos. Este tipo se suele utilizar para resolver subconsultas.</li>
<li>index_merge: se utiliza la optimización <em>index merge</em>.</li>
<li>unique_subquery: sustituye a ref en algunas subconsultas (del tipo<em> SELECT clave_primaria</em>) que utilizan <em>IN</em>.</li>
<li>index_subquery: sustituye a ref en algunas subconsultas (del tipo<em> SELECT valor_columna</em>) que utilizan <em>IN </em>y que no son únicas.</li>
<li>range: cuando se devuelve filas dentro de un rango.</li>
<li>index: igual que un <em>full scan</em> pero cuando se escanea el índice.</li>
<li>ALL: <em>full scan</em>. Normalmente se debe evitar.</li>
</ul>
<p><strong>Possible_keys:</strong> Muestra que índices puede seleccionar MySql para devolver las filas.</p>
<p><strong>Key:</strong> Indica que índice va a utilizar MySql para devolver las filas.</p>
<p><strong>Key_len:</strong> tamaño del índice que se va a utilizar.</p>
<p><strong>Ref:</strong> columna/s o constante/s que se van a comparar con el índice.</p>
<p><strong>Rows:</strong> indica el número de filas que se prevee que MySql examine. En tablas InnoDB es un valor aproximado.</p>
<p><strong>Extra:</strong> información adicional sobre como MySql resolverá la consulta.</p>
<p>Para más información sobre el resultado de <em>EXPLAIN</em> por favor mirar en la <a title="MySql Explain" href="http://dev.mysql.com/doc/refman/5.5/en/explain-output.html">página web de MySql</a>.</p>
<p>Espero que os halla sido de utilidad este breve artículo de cómo utilizar <em>EXPLAIN </em>para optimizar vuestras consultas a bases de datos.</p>
<p>¡Un saludo a tod@s!</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=504</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#SpanishRevolution</title>
		<link>http://ridersofthebit.net/blog/?p=500</link>
		<comments>http://ridersofthebit.net/blog/?p=500#comments</comments>
		<pubDate>Fri, 20 May 2011 14:07:16 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[A través del espejo]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[#democraciarealya]]></category>
		<category><![CDATA[#spanishrevolution]]></category>
		<category><![CDATA[futuro]]></category>
		<category><![CDATA[revolución]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=500</guid>
		<description><![CDATA[¡Revolución ya! Es hora de despertar. La pesadilla debe acabar y empezar a vivir un cambio. Un revolución de vez en cuando es sana para revisar que las cosas se están haciendo bien y mejorar las que se están haciendo &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=500">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>¡Revolución ya! Es hora de despertar. La pesadilla debe acabar y empezar a vivir un cambio. Un revolución de vez en cuando es sana para revisar que las cosas se están haciendo bien y mejorar las que se están haciendo mal. Nuestros políticos, que en su día se revelaron, se han apoltronado en sus puestos y únicamente hacen acto de ostentación de un cargo que deberían ejercer. Los estados están secuestrados por los mercados que han sabido captar &#8211; con cantos de sirena &#8211; a quienes deberían gobernar, más pendientes de sus sueldos vitalicios y su &#8220;futuro&#8221; en el sector privado que en la difícil tarea de gobernar un País. <em>Poderoso caballero es Don dinero</em> y eso las grandes multinacionales lo saben.</p>
<p>Pensar si realmente somos libres. ¿Podemos dejar nuestro trabajo cuando queramos? No. A través de nuestro capricho nos han encadenado a créditos hipotecarios, créditos para estudiar, créditos para irnos de vacaciones, créditos para todo. Hemos vendido nuestra vida a los mercados que a través de los bancos y de nuestros políticos, nos han puesto los grilletes para que esta sociedad siga esclavizada al servicio de unos pocos sin escrúpulos.</p>
<p>Nosotros seguramente ya no tenemos salvación, estamos condenamos a pagar nuestra codicia. Pero todavía podemos salvar a nuestros hijos, nietos y futuras generaciones. Muchos imperios antes han caído y muchos lo harán en el futuro. Y ellos se levantarán,  pero pensado que nosotros también. Y así iremos completando ciclos vitales hasta el fin de tiempos.</p>
<p>Os dejo con el final de una de las mejores películas que he visto. Y dónde el guionista y el director ya nos hacían un guiño de como <em>resetear</em> esta Democracia 1.0 e instalar la <strong>2.0</strong></p>
<p style="text-align: center;">
<object style="width:425px; height:344px;">
<param name="movie" value="http://www.youtube.com/v/xBJ02B6TTcg?version=3" />
<param name="allowScriptAccess" value="always" />
<param name="wmode" value="window" />
<embed src="http://www.youtube.com/v/xBJ02B6TTcg?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" wmode="window" width="425" height="344"></object>
</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=500</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microservices for Twitter&#8230; #givemeasearch</title>
		<link>http://ridersofthebit.net/blog/?p=496</link>
		<comments>http://ridersofthebit.net/blog/?p=496#comments</comments>
		<pubDate>Fri, 22 Apr 2011 18:53:10 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[A través del espejo]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Internet Technologies]]></category>
		<category><![CDATA[givemeasearch]]></category>
		<category><![CDATA[microservices]]></category>
		<category><![CDATA[microservicios]]></category>
		<category><![CDATA[retweet]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=496</guid>
		<description><![CDATA[GiveMeASearch is a microservice for do searches (using Google) from the world of Twitter. Using it is very simple. Add the hashtag #givemeasearch in a tweet &#8211; or retweet &#8211; and the microservice will do the search, of the text, in Google y &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=496">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a title="Give me a search!" href="http://www.givemeasearch.com" target="_blank">GiveMeASearch</a> is a microservice for do searches (using <em>Google</em>) from the world of <em>Twitter</em>. Using it is very simple. Add the <em>hashtag</em> <strong>#givemeasearch</strong> in a <em>tweet</em> &#8211; or <em>retweet</em> &#8211; and the microservice will do the search, of the text, in <em>Google</em> y after will return a mention or direct message (if you follow <a title="Give me a search!" href="http://twitter.com/#!/GiveMeASearch" target="_blank">GiveMeASearch</a>) with the firsts two links of the result of the search.</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=496</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microservicios para Twitter&#8230; #givemeasearch</title>
		<link>http://ridersofthebit.net/blog/?p=493</link>
		<comments>http://ridersofthebit.net/blog/?p=493#comments</comments>
		<pubDate>Thu, 21 Apr 2011 11:34:23 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[A través del espejo]]></category>
		<category><![CDATA[Escenario]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Internet Technologies]]></category>
		<category><![CDATA[givemeasearch]]></category>
		<category><![CDATA[microservices]]></category>
		<category><![CDATA[microservicios]]></category>
		<category><![CDATA[retweet]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=493</guid>
		<description><![CDATA[GiveMeASearch es un microservicio de búsquedas (a través de Google) para el universo Twitter. Su utilización es bien sencilla. Al añadir el hashtag #givemeasearch en un tweet &#8211; o retweet &#8211; el microservicio realiza la búsqueda, del texto, en Google &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=493">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a title="Give me a search!" href="http://www.givemeasearch.com" target="_blank">GiveMeASearch</a> es un microservicio de búsquedas (a través de <em>Google</em>) para el universo <em>Twitter</em>. Su utilización es bien sencilla. Al añadir el <em>hashtag</em> <strong>#givemeasearch</strong> en un <em>tweet</em> &#8211; o <em>retweet</em> &#8211; el microservicio realiza la búsqueda, del texto, en <em>Google</em> y devuelve vía mención o mensaje directo (si sigues a <a title="Give me a search!" href="http://twitter.com/#!/GiveMeASearch" target="_blank">GiveMeASearch</a>) los enlaces de las dos primeras entradas.</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=493</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three useful or not&#8230; Java functions</title>
		<link>http://ridersofthebit.net/blog/?p=483</link>
		<comments>http://ridersofthebit.net/blog/?p=483#comments</comments>
		<pubDate>Thu, 10 Feb 2011 11:30:15 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[A través del espejo]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[codility]]></category>
		<category><![CDATA[hyves]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=483</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 int heavy_decimal_count&#40;int a, int b&#41; &#123; int result = 0; Hashtable&#60;String, Double&#62; range = new Hashtable&#60;String, Double&#62;&#40;&#41;; &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=483">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> heavy_decimal_count<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> a, <span style="color: #000066; font-weight: bold;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;</span> range <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> number<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">double</span> avg<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> a<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        number <span style="color: #339933;">=</span> <span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        avg <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>		
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> number.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    avg <span style="color: #339933;">+=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>number<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
        avg <span style="color: #339933;">/=</span> number.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>avg <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">7.25</span><span style="color: #009900;">&#41;</span>
	    result<span style="color: #339933;">++;</span>
&nbsp;
        range.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">copyValueOf</span><span style="color: #009900;">&#40;</span>number<span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>avg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> dominator<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> A<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
    Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;</span> occurrence<span style="color: #339933;">;</span>
    Hashtable<span style="color: #339933;">&lt;</span>Integer, Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;&gt;</span> indexes <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hashtable<span style="color: #339933;">&lt;</span>Integer, Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> A.<span style="color: #006633;">length</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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>indexes.<span style="color: #006633;">containsKey</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            occurrence <span style="color: #339933;">=</span> indexes.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OCCURRENCES&quot;</span>, occurrence.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OCCURRENCES&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doubleValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DOMINATOR&quot;</span>, <span style="color: #009900;">&#40;</span>occurrence.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OCCURRENCES&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doubleValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> A.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LASTINDEX&quot;</span>, <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            occurrence <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OCCURRENCES&quot;</span>, <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DOMINATOR&quot;</span>, <span style="color: #cc66cc;">1.0</span> <span style="color: #339933;">/</span> A.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            occurrence.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LASTINDEX&quot;</span>, <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        indexes.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>, occurrence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    Iterator<span style="color: #339933;">&lt;</span>Hashtable<span style="color: #339933;">&lt;</span>String, Double<span style="color: #339933;">&gt;&gt;</span> it <span style="color: #339933;">=</span> indexes.<span style="color: #006633;">values</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>it.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        occurrence <span style="color: #339933;">=</span> it.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>occurrence.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DOMINATOR&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">doubleValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0.5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            result <span style="color: #339933;">=</span> occurrence.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;LASTINDEX&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><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: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> amplitude<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> A<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">int</span> result <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> newVal <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> A.<span style="color: #006633;">length</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: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> A.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">==</span> i<span style="color: #009900;">&#41;</span>
                <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
            newVal <span style="color: #339933;">=</span> <span style="color: #003399;">Math</span>.<span style="color: #006633;">abs</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> A<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newVal <span style="color: #339933;">&gt;</span> result<span style="color: #009900;">&#41;</span>
                result <span style="color: #339933;">=</span> newVal<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=483</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programador horario con Arduino</title>
		<link>http://ridersofthebit.net/blog/?p=475</link>
		<comments>http://ridersofthebit.net/blog/?p=475#comments</comments>
		<pubDate>Mon, 03 Jan 2011 11:45:24 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Robótica]]></category>
		<category><![CDATA[acuario]]></category>
		<category><![CDATA[aquarium]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[programador]]></category>
		<category><![CDATA[programmer]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=475</guid>
		<description><![CDATA[¡Hola a tod@s! Últimamente estoy inmerso en un proyecto con Arduino. El proyecto en cuestión trata el diseño y programación de un controlador para la Pecera del Quinto. Uno de los primeros escollos a resolver es el programador horario y &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=475">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>¡Hola a tod@s!</p>
<p>Últimamente estoy inmerso en un proyecto con <a target="_blank" href="http://www.arduino.cc"><strong>Arduino</strong></a>. El proyecto en cuestión trata el diseño y programación de un controlador para la <a target="_blank" href="http://blog.losdelquinto.es"><em>Pecera del Quinto</em></a>. Uno de los primeros escollos a resolver es el programador horario y para ello he hecho la siguiente función. La función <em>between(..)</em> permite saber si la hora actual (o cualquier otra) está entre dos horas diferentes, además permite incluir una hora final en el siguiente día (ver ejemplo).</p>
<p>Código de la función:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
* Between is a method to check if current time is between two different times (initial time and final time). This method supports a 'final time' in the next day.
* @param currHour integer (0-23) with the current hour.
* @param currMinute integer (0-59) with the current minute.
* @param initHour integer (0-23) with the initial hour.
* @param initHour integer (0-59) with the initial minute.
* @param finalHour integer (0-23) with the final hour.
* @param finalMinute integer (0-59) with the final minute.
* @return true if the current hour is between the two times (initial and final)
* @author Oscar Sanchez Montaner (OSanchezMon)
*/</span>
boolean between<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> currHour<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> currMinute<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> initHour<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> initMinute<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> finalHour<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> finalMinute<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  boolean result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Converting times to minutes.</span>
  <span style="color: #993333;">int</span>  on <span style="color: #339933;">=</span> initHour  <span style="color: #339933;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #339933;">+</span>  initMinute<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> now <span style="color: #339933;">=</span> currHour  <span style="color: #339933;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #339933;">+</span>  currMinute<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> off <span style="color: #339933;">=</span> finalHour <span style="color: #339933;">*</span> <span style="color: #0000dd;">60</span> <span style="color: #339933;">+</span> finalMinute<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// If final time is in the next day...</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>finalHour <span style="color: #339933;">&lt;</span> initHour<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// ... must first check if current time is above 12AM (24)...</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>now <span style="color: #339933;">&lt;</span> off<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      now <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1440</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ... if it is above; increase it 1440 minutes.</span>
    <span style="color: #009900;">&#125;</span>
    off <span style="color: #339933;">+=</span> <span style="color: #0000dd;">1440</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Final time (for the next day) is always increased 1440 minutes.</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Development information.</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>DEBUG_ON<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;On: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>on<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;, Now: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>now<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;, Off: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>off<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Check if current time is between initial and final time.</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>now <span style="color: #339933;">&gt;=</span> on <span style="color: #339933;">&amp;&amp;</span> now <span style="color: #339933;">&lt;</span> off<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En el siguiente ejemplo se quiere saber si la hora actual está comprendida entre las 23:10 y las 10:10 (de la mañana siguiente).</p>
<p>Ejemplo de utilización:
</pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>between<span style="color: #009900;">&#40;</span>hora_actual<span style="color: #339933;">,</span> minuto_actual<span style="color: #339933;">,</span> <span style="color: #0000dd;">23</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><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><span style="color: #339933;">!</span>relay02On<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      digitalWrite<span style="color: #009900;">&#40;</span>relay02Pin<span style="color: #339933;">,</span> HIGH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      relay02On <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      logger<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Relay 02 enabled.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=475</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where are my site-packages stored?</title>
		<link>http://ridersofthebit.net/blog/?p=471</link>
		<comments>http://ridersofthebit.net/blog/?p=471#comments</comments>
		<pubDate>Thu, 04 Nov 2010 11:04:52 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[site_packages]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=471</guid>
		<description><![CDATA[The location depends on the operating system, to find out try to execute the following code: python -c &#34;from distutils.sysconfig import get_python_lib; print get_python_lib()&#34; Cheers!]]></description>
			<content:encoded><![CDATA[<p>The location depends on the operating system, to find out try to execute the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">python -c <span style="color: #483d8b;">&quot;from distutils.sysconfig import get_python_lib; print get_python_lib()&quot;</span></pre></div></div>

<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=471</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cómo utilizar JOIN en sentencias UPDATE o DELETE.</title>
		<link>http://ridersofthebit.net/blog/?p=469</link>
		<comments>http://ridersofthebit.net/blog/?p=469#comments</comments>
		<pubDate>Tue, 05 Oct 2010 11:45:16 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[Calidoscópio]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[inner join]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[ms sql 2005]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=469</guid>
		<description><![CDATA[Una práctica muy recomendable antes de lanzar una sentencia UPDATE o DELETE sobre un subconjunto de tuplas, es probar a realizar la proyección, afinando las condiciones de restricción para el subconjunto (mediante una sentencia WHERE). Cuando nos encontramos ante una &#8230;<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=469">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Una práctica muy recomendable antes de lanzar una sentencia <em>UPDATE</em> o <em>DELETE</em> sobre un subconjunto de tuplas, es probar a realizar la proyección, afinando las condiciones de restricción para el subconjunto (mediante una sentencia <em>WHERE</em>). Cuando nos encontramos ante una condiciones sencillas, reutilizar la misma clausula WHERE es trivial. Pero qué sucede cuando queremos utilizar funciones de composición (<em>JOIN</em>) para restringir el conjunto de datos.</p>
<p>Ejemplo para <em><a href="http://dev.mysql.com/doc/refman/5.1/en/update.html" target="_blank">UPDATE</a></em>, donde se puede ver como se han utilizado varios <em>JOINs</em> en el bloque de referencia a la table (<em>table_reference</em> en el manual de MySql):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> table1 T1 <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table2 T2 <span style="color: #993333; font-weight: bold;">ON</span> T1<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table3 T3 <span style="color: #993333; font-weight: bold;">ON</span> T3<span style="color: #66cc66;">.</span>other_id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>other_id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table4 T4 <span style="color: #993333; font-weight: bold;">ON</span> T4<span style="color: #66cc66;">.</span>category <span style="color: #66cc66;">=</span> T3<span style="color: #66cc66;">.</span>category <span style="color: #993333; font-weight: bold;">SET</span> T1<span style="color: #66cc66;">.</span>readed <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">WHERE</span> T1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'X'</span> <span style="color: #993333; font-weight: bold;">AND</span> T1<span style="color: #66cc66;">.</span>category  <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'A'</span>;</pre></div></div>

<p>Ejemplo para <em><a href="http://dev.mysql.com/doc/refman/5.1/en/delete.html" target="_blank">DELETE</a></em>. En este caso después del <em>DELETE</em> hay que especificar la tabla o tablas (<em>multi-delete</em>):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DELETE</span> T2 <span style="color: #993333; font-weight: bold;">FROM</span> table2 T2 <span style="color: #993333; font-weight: bold;">ON</span> T1<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table3 T3 <span style="color: #993333; font-weight: bold;">ON</span> T3<span style="color: #66cc66;">.</span>other_id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>other_id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table4 T4 <span style="color: #993333; font-weight: bold;">ON</span> T4<span style="color: #66cc66;">.</span>category <span style="color: #66cc66;">=</span> T3<span style="color: #66cc66;">.</span>category <span style="color: #993333; font-weight: bold;">WHERE</span> T1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'X'</span> <span style="color: #993333; font-weight: bold;">AND</span> T1<span style="color: #66cc66;">.</span>category  <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'A'</span>;</pre></div></div>

<p>Espero que estos ejemplos os sirvan de ayuda.</p>
<p><span style="text-decoration: underline;"><strong>NOTA</strong></span>: Todos los ejemplos se han ejecutado en un servidor <em>MySql</em> version <strong>5.1</strong>.</p>
<h2>Actualización</h2>
<p>Ejemplo para  <em>MS SQL 2005</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> table1 <span style="color: #993333; font-weight: bold;">SET</span> T1<span style="color: #66cc66;">.</span>readed <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">FROM</span> table1 T1 <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table2 T2 <span style="color: #993333; font-weight: bold;">ON</span> T1<span style="color: #66cc66;">.</span>id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table3 T3 <span style="color: #993333; font-weight: bold;">ON</span> T3<span style="color: #66cc66;">.</span>other_id <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>other_id <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> table4 T4 <span style="color: #993333; font-weight: bold;">ON</span> T4<span style="color: #66cc66;">.</span>category <span style="color: #66cc66;">=</span> T3<span style="color: #66cc66;">.</span>category  <span style="color: #993333; font-weight: bold;">WHERE</span> T1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'X'</span> <span style="color: #993333; font-weight: bold;">AND</span> T1<span style="color: #66cc66;">.</span>category  <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'A'</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=469</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zope and Apache HTTP Server working as reverse proxy</title>
		<link>http://ridersofthebit.net/blog/?p=461</link>
		<comments>http://ridersofthebit.net/blog/?p=461#comments</comments>
		<pubDate>Sun, 03 Oct 2010 20:00:55 +0000</pubDate>
		<dc:creator>oscar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Internet Technologies]]></category>
		<category><![CDATA[Zope/Plone]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[mod_proxy_html]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[virtual host monster]]></category>
		<category><![CDATA[zope]]></category>

		<guid isPermaLink="false">http://www.losdelquinto.es/ridersofthebit.net/blog/?p=461</guid>
		<description><![CDATA[Creating an scenario with a Zope working as production web site and other/s Zope working as application server.<p class="read-more"><a href="http://ridersofthebit.net/blog/?p=461">Leer más &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I folks,</p>
<p>If you want to create an scenario with a <a title="Zope Community" href="http://www.zope.org/" target="_blank">Zope</a> working as production web site and other/s Zope working as application server, probably you are looking for the way to configure <a title="Apache HTTP Server Project" href="http://httpd.apache.org/" target="_blank">Apache</a> as <em>reverse proxy</em> between the <span style="text-decoration: underline;"><em>front row</em></span> (web site and content) and the <span style="text-decoration: underline;"><em>rear row</em></span> (web applications). In this case, working with Zope makes the configuration be easier because it has a product (<a title="Virtual Hosting Services" href="http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/VirtualHosting.stx" target="_blank">VirtualHostMonster</a>) that does part of the work; &#8220;<em>A Virtual Host Monster&#8217;s only job is to change the URLs which       your Zope objects generate.  This allows you to customize the       URLs that are displayed within your Zope application, allowing       an object to have a different URL when accessed in a different       way</em>&#8220;. This is very useful because in other way we should use a third-party module called <a title="mod_proxy_html" href="http://apache.webthing.com/mod_proxy_html/" target="_blank">ProxyHtml</a>. <em>mod_proxy_html</em> is used to rewrite HTML code, specially links. But in our case, we only need to use the rewrite module (mod_rewrite) and the proxy module (mod_proxy).</p>
<p>Let&#8217;e get to work:</p>
<p>To redirect an application from a public server to a private server (private server does not need to has an Apache running) we should add the following code in the virtual host configuration file (<strong>/etc/apache2/vhosts.d/myhost.conf</strong>).</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">RewriteRule ^/Intranet/Apps/app1<span style="">&#40;</span>.*<span style="">&#41;</span> http://private.com:<span style="">8080</span>/VirtualHostBase/http/&lt;strong&gt;%<span style="">&#123;</span>HTTP_HOST<span style="">&#125;</span>&lt;/strong&gt;:<span style="">80</span>/DOM/VirtualHostRoot/Intranet/Apps/app1/$1 <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L,P<span style="">&#93;</span></span>
ProxyPassReverse / http://private.com:<span style="">8080</span>/VirtualHostBase/http/&lt;strong&gt;%<span style="">&#123;</span>HTTP_HOST<span style="">&#125;</span>&lt;/strong&gt;:<span style="">80</span>/DOM/VirtualHostRoot/</pre></div></div>

<p>Note than in the <em>second part</em> of both rules the URL is compliant with the VHM requirements. First we found the rewrite and redirection to the private server (<em><strong>http://private.com:8080/VirtualHostBase/</strong></em>) and after the <em><strong>/http/</strong></em> we find the host (here I use the Apache&#8217;s variale <em>HTTP_HOST</em>) where the VirtualHostMonster will do the reverse proxy. <strong><em>%{HTTP_HOST}</em></strong> is an Apache&#8217;s variable, and we can use it here or directly the name of the public server.</p>
<p>And this is all <img src='http://ridersofthebit.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  If you have any other experience or comment please don&#8217;t hesitate to comment here!</p>
]]></content:encoded>
			<wfw:commentRss>http://ridersofthebit.net/blog/?feed=rss2&#038;p=461</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

