<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Posts on Call me Guido</title>
		<link>https://guidogarcia.net/posts/</link>
		<description>Recent content in Posts on Call me Guido</description>
		<generator>Hugo -- gohugo.io</generator>
		<language>en-us</language>
		<copyright>Copyright Guido García · All rights reserved</copyright>
		<lastBuildDate>Sun, 18 Feb 2018 19:29:39 +0000</lastBuildDate>
		<atom:link href="https://guidogarcia.net/posts/index.xml" rel="self" type="application/rss+xml" />
		
		<item>
			<title>Evolutionary art experiment with Marilyn</title>
			<link>https://guidogarcia.net/blog/2018/02/18/evolutionary-art-experiment-with-marilyn/</link>
			<pubDate>Sun, 18 Feb 2018 19:29:39 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2018/02/18/evolutionary-art-experiment-with-marilyn/</guid>
			<description>You know I like evolutionary algorithms. In the past month I ran a small art experiment reflecting the impact of brands and the harmful effect of advertisements in modern life. The idea was to pick a cultural icon and recreate it using corporate logos only.
I started with Marilyn Monroe and a genetic algorithm that combined a set of logos in a mutation and a crossover loop. The mutation phase randomly picked some individuals (an individual is a specific combination of logos) and modified them, as nature would do, replacing some logos, resizing or rotating them.</description>
			<content type="html"><![CDATA[

<p>You know I like <a href="http://guidogarcia.net/blog/2014/11/05/evolutionary-computation-%c2%b7-tefcon-2014/">evolutionary algorithms</a>. In the past month I ran a small <strong>art experiment reflecting the impact of brands and the harmful effect of advertisements in modern life</strong>. The idea was to pick a cultural icon and recreate it using corporate logos only.</p>

<p><img src="/images/marilyn.jpg" alt="Original image" /></p>

<p>I started with Marilyn Monroe and a genetic algorithm that combined a set of logos in a <strong>mutation and a crossover</strong> loop. The <em>mutation phase</em> randomly picked some individuals (an individual is a specific combination of logos) and modified them, as nature would do, replacing some logos, resizing or rotating them. The <em>crossover phase</em> chose pairs of individuals and produced a child individual from them.</p>

<p>The first image corresponds to the individual 46, after the algorithm had been running for <strong>15 minutes</strong> on a machine with 32 cores. Marylin wasn&rsquo;t there yet but everything looked good so far.</p>

<p><img src="/images/output_individual_46.png" alt="Individual 46" /></p>

<p>After <strong>12 hours</strong>, Marilyn&rsquo;s eye and her eyebrow had already been replaced by an Evernote&rsquo;s elephant and a Facebook logo, as shown in the following image, that belongs to the individual 5449. Her lips seem to be McDonald&rsquo;s Golden Arches. The algorithm was slower than expected, but it looked promising.</p>

<table>
<thead>
<tr>
<th>Individual 5449 (12h)</th>
<th>Original</th>
</tr>
</thead>

<tbody>
<tr>
<td><img src="/images/output_individual_5449.png" alt="Individual 5449" /></td>
<td><img src="/images/marilyn.jpg" alt="Original image" /></td>
</tr>
</tbody>
</table>

<p>Sadly, the fittest individual found after <strong>24 hours</strong> didn&rsquo;t look so good, so I cancelled the experiment. I didn&rsquo;t notice further improvements. The outline of Marilyn is also clear, but the result is way worse than I expected.</p>

<table>
<thead>
<tr>
<th>Individual 8463 (24h)</th>
<th>Original</th>
</tr>
</thead>

<tbody>
<tr>
<td><img src="/images/output_individual_8463.png" alt="Individual 5449" /></td>
<td><img src="/images/marilyn.jpg" alt="Original image" /></td>
</tr>
</tbody>
</table>

<p>In hindsight, I wouldn&rsquo;t call the result a success. What do you say?</p>

<h3 id="how-to-run-your-own-experiment">How to run your own experiment</h3>

<p>The good part of genetic algorithms is that you only need to code <em>what</em> you want to achieve and not <em>how</em> to achieve it. That&rsquo;s why the overall algorithm always look the same. In general you only need to <strong>implement the fitness function</strong>, that measures how good a given solution is. There are also different crossover algorithms. In this experiment I used a wheel probability selector, where the fittest individuals are more likely to be chosen for crossover and a <a href="https://en.wikipedia.org/wiki/Crossover_(genetic_algorithm)#Techniques">single point crossover</a> technique.</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="k">const</span> <span class="nx">population</span> <span class="o">=</span> <span class="p">...</span> <span class="c1">// generate array of random individuals
</span><span class="c1"></span><span class="nx">population</span>
    <span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="nx">individual</span> <span class="p">=&gt;</span> <span class="nx">individual</span><span class="p">.</span><span class="nx">fitness</span> <span class="o">&gt;</span> <span class="nx">MIN_FITNESS</span><span class="p">)</span>
    <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">survivors</span> <span class="p">=&gt;</span> <span class="p">{</span>
        <span class="c1">// always kill the worst 20% individuals
</span><span class="c1"></span>        <span class="k">return</span> <span class="nx">survivors</span>
            <span class="p">.</span><span class="nx">sort</span><span class="p">((</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="nx">b</span><span class="p">.</span><span class="nx">fitness</span> <span class="o">-</span> <span class="nx">a</span><span class="p">.</span><span class="nx">fitness</span><span class="p">)</span>
            <span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">survivors</span><span class="p">.</span><span class="nx">length</span> <span class="o">*</span> <span class="mf">0.8</span><span class="p">);</span>
    <span class="p">})</span>
    <span class="p">.</span><span class="nx">then</span><span class="p">(</span><span class="nx">survivors</span> <span class="p">=&gt;</span> <span class="p">{</span>
        <span class="c1">// mutate phase
</span><span class="c1"></span>        <span class="k">const</span> <span class="nx">mutateCount</span> <span class="o">=</span> <span class="nx">survivors</span><span class="p">.</span><span class="nx">length</span> <span class="o">*</span> <span class="nx">MUTATE_PROBABILITY</span><span class="p">;</span>
        <span class="nx">_</span><span class="p">.</span><span class="nx">times</span><span class="p">(</span><span class="nx">mutateCount</span><span class="p">,</span> <span class="p">()</span> <span class="p">=&gt;</span> <span class="nx">_</span><span class="p">.</span><span class="nx">sample</span><span class="p">(</span><span class="nx">survivors</span><span class="p">).</span><span class="nx">mutate</span><span class="p">());</span>

        <span class="c1">// crossover phase with wheel selection
</span><span class="c1"></span>        <span class="k">const</span> <span class="nx">crossoverCount</span> <span class="o">=</span> <span class="nx">survivors</span><span class="p">.</span><span class="nx">length</span> <span class="o">*</span> <span class="nx">CROSSOVER_PROBABILITY</span><span class="p">;</span>
        <span class="nx">_</span><span class="p">.</span><span class="nx">times</span><span class="p">(</span><span class="nx">crossoverCount</span><span class="p">,</span> <span class="p">()</span> <span class="p">=&gt;</span> <span class="p">{</span>
            <span class="k">const</span> <span class="nx">parent1</span> <span class="o">=</span> <span class="nx">wheel</span><span class="p">();</span>
            <span class="k">const</span> <span class="nx">parent2</span> <span class="o">=</span> <span class="nx">wheel</span><span class="p">();</span>
            <span class="k">const</span> <span class="nx">child</span> <span class="o">=</span> <span class="nx">parent1</span><span class="p">.</span><span class="nx">crossover</span><span class="p">(</span><span class="nx">parent2</span><span class="p">);</span>
            <span class="nx">survivors</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">child</span><span class="p">);</span>
        <span class="p">});</span>

        <span class="k">return</span> <span class="nx">survivors</span><span class="p">;</span>
    <span class="p">});</span>
</code></pre></div>

<p>Node.js is not the best language to do cpu-intensive tasks, but I wanted to enjoy coding and I found <a href="https://github.com/oliver-moran/jimp">jimp</a> and <a href="https://github.com/lovell/sharp">sharp</a> very handy to compare and process images. Sharp is powered by <a href="https://github.com/jcupitt/libvips">libvips</a> which makes it really efficient, but it wasn&rsquo;t enough due to the volume of images I needed to combine. Ideas and cpu-time to make the experiment succeed are welcome! Comments are open.</p>
]]></content>
		</item>
		
		<item>
			<title>The road to serverless computing</title>
			<link>https://guidogarcia.net/blog/2016/07/13/road-serverless-computing/</link>
			<pubDate>Wed, 13 Jul 2016 21:20:13 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2016/07/13/road-serverless-computing/</guid>
			<description>This is my presentation about serverless computing for the TEFcon 2016.
 </description>
			<content type="html"><![CDATA[<p>This is my presentation about <strong>serverless computing</strong> for the TEFcon 2016.</p>

<iframe src="//slides.com/guidogarcia/the-road-to-serverless-computing/embed" width="576" height="420" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
]]></content>
		</item>
		
		<item>
			<title>Ansible. Automate everything.</title>
			<link>https://guidogarcia.net/blog/2015/10/18/ansible-automate-everything/</link>
			<pubDate>Sun, 18 Oct 2015 19:13:07 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2015/10/18/ansible-automate-everything/</guid>
			<description>Ansible is an automation tool that works by running tasks (a playbook) against a set of hosts (inventory).
The first beta of Ansible 2.x is ready, and it comes with modules to automate the management of your openstack infrastructure (other cloud platforms are also available). This is my presentantion for begginers who want to start using Ansible and to stop wasting their time.
 </description>
			<content type="html"><![CDATA[<p><a href="http://www.ansible.com/get-started">Ansible</a> is an automation tool that works by running tasks (a playbook) against a set of hosts (inventory).</p>

<p>The first beta of Ansible 2.x is ready, and it comes with modules to automate the management of your openstack infrastructure (other cloud platforms are also available). This is my presentantion for begginers who want to start using Ansible and to stop wasting their time.</p>

<iframe src="//slides.com/guidogarcia/ansible-2-0/embed" width="576" height="420" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
]]></content>
		</item>
		
		<item>
			<title>Mi experiencia HackForGood 2015</title>
			<link>https://guidogarcia.net/blog/2015/06/16/mi-experiencia-hackforgood-2015/</link>
			<pubDate>Tue, 16 Jun 2015 14:04:13 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2015/06/16/mi-experiencia-hackforgood-2015/</guid>
			<description>HackForGood es un hackaton centrado en la innovación social, donde se desarrollan de forma colaborativa nuevas ideas que ayuden a resolver problemas sociales. Los días 16-18 de abril sacrificamos un día de vacaciones para pasarnos por la tercera edición de la iniciativa HackForGood en la Universidad de Valladolid.
Nuestro equipo &amp;ldquo;Senior OS&amp;rdquo; iba con la idea de hacer un teléfono móvil para personas mayores, sin ningún tipo de configuración y que se pudiese gestionar íntegramente de forma remota.</description>
			<content type="html"><![CDATA[

<p><a href="http://www.hackforgood.net">HackForGood</a> es un hackaton centrado en la innovación social, donde se desarrollan de forma colaborativa nuevas ideas que ayuden a resolver problemas sociales. Los días 16-18 de abril sacrificamos un día de vacaciones para pasarnos por la tercera edición de la iniciativa HackForGood en la Universidad de Valladolid.</p>

<p>Nuestro equipo &ldquo;Senior OS&rdquo; iba con la idea de hacer un <a href="http://www.telefoneo.com">teléfono móvil para personas mayores</a>, sin ningún tipo de configuración y que se pudiese gestionar íntegramente de forma remota. Lo pasamos muy bien y os voy a contar lo que más me llamó la atención.</p>

<h3 id="anarquía-colaborativa">Anarquía colaborativa</h3>

<p>Los proyectos que más me gustaron mezclaban software y hardware para resolver problemas sociales: un lector de libros para personas con deficiencias visuales basado en cámaras de bajo coste y software libre de reconocimiento de textos, un sistema de control domótico basado en Arduino para personas con movilidad reducida, un sistema para automatizar el tratamiento a pacientes de quimioterapia (<a href="https://twitter.com/quimiopro">@quimiopro</a>) también utilizando Arduino o nuestro teléfono basado en Firefox OS.</p>

<p>Quizá no fuesen perfectos, pero son una muestra de que en escasas 48 horas se pueden desarrollar prototipos o comenzar proyectos que en una empresa costaría poner en marcha algún que otro mes de burocracia, reuniones y procedimientos. Hoy en día, con un presupuesto ridículo y un grupo muy pequeño de personas, se puede probar una idea tecnológica. Pienso que, conforme se siga <strong>democratizando el acceso a la tecnología</strong>, las empresas tecnológicas continuarán perdiendo su ventaja frente a grupos de personas organizadas alrededor de un proyecto. Principalmente porque su motivación va más allá del dinero.</p>

<h3 id="generación-encontrada">Generación encontrada</h3>

<p>Parece probado que la diversidad es un factor enriquecedor de ideas y proyectos. Muchas veces se asocia a la diversidad de género y, aunque es cierto que el porcentaje de mujeres en el evento fue muy bajo (alrededor de un 20%), lo que más me llamó la atención fue la ausencia de personas mayores de 35 años. Ni una. La media rondaba los veintipocos y probablemente yo fuese el mayor de todos.</p>

<p>Es algo que se repite en este tipo de eventos. Parece que se asume que para participar se tiene que ser joven y estudiante. ¿Es un problema de comunicación o hay una edad a partir de la cual asumimos que este tipo de iniciativas no van con nosotros?</p>

<p>La verdad es que en quedé gratamente sorprendido con la forma en la que los jóvenes se organizan en esa suerte de anarquía colaborativa. Una generación que ha recibido todo tipo de calificativos, que algunos llaman generación perdida, pero a la que sólo le hace falta levantar la voz. Es a este tipo de eventos donde hay que ir a encontrar talento y gente con ganas de hacer cosas e innovar.</p>

<p>Nos vemos el año que viene. Sin excusas.</p>
]]></content>
		</item>
		
		<item>
			<title>Apache Mesos and the future of microservice architectures</title>
			<link>https://guidogarcia.net/blog/2015/03/24/apache-mesos-and-the-future-of-microservice-architectures/</link>
			<pubDate>Tue, 24 Mar 2015 08:07:05 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2015/03/24/apache-mesos-and-the-future-of-microservice-architectures/</guid>
			<description>Here you have a presentation Apache Mesos, Marathon and Flock I gave for the cloud community in Telefónica.
Flock is an unstable proof of concept I&amp;rsquo;ve been working on lately. It is a next-generation service platform that uses Marathon to allocate services across a cluster of machines.
I think the time to start caring only about services -not machines- has come. Compute resources should be treated as a commodity. As tap water.</description>
			<content type="html"><![CDATA[<p>Here you have a presentation Apache Mesos, Marathon and <a href="https://github.com/flock-cloud/flock-docs">Flock</a> I gave for the cloud community in Telefónica.</p>

<p><a href="https://github.com/flock-cloud/flock-docs">Flock</a> is an unstable proof of concept I&rsquo;ve been working on lately. It is a next-generation service platform that uses Marathon to allocate services across a cluster of machines.</p>

<p>I think the time to start caring only about services -not machines- has come. Compute resources should be treated as a commodity. As tap water.</p>
]]></content>
		</item>
		
		<item>
			<title>Simple moving average with bacon.js</title>
			<link>https://guidogarcia.net/blog/2015/01/15/moving-average-with-baconjs/</link>
			<pubDate>Thu, 15 Jan 2015 08:22:35 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2015/01/15/moving-average-with-baconjs/</guid>
			<description>Bacon is a small functional reactive programming lib for JavaScript. Sometimes it is easier to handle data as a stream and react to changes in the stream instead of processing individual events. In the example below (nodejs), a simple moving average.
var Bacon = require(&amp;#39;baconjs&amp;#39;) function avg(array) { var sum = array.reduce(function(a, b) { return a + b; }, 0); return sum / array.length; } var bus = new Bacon.Bus(); bus.</description>
			<content type="html"><![CDATA[<p><a href="https://baconjs.github.io/">Bacon</a> is a <em>small functional reactive programming lib for JavaScript</em>. Sometimes it is easier to handle data as a stream and react to changes in the stream instead of processing individual events. In the example below (nodejs), a simple moving average.</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="kd">var</span> <span class="nx">Bacon</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;baconjs&#39;</span><span class="p">)</span>

<span class="kd">function</span> <span class="nx">avg</span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">sum</span> <span class="o">=</span> <span class="nx">array</span><span class="p">.</span><span class="nx">reduce</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">a</span> <span class="o">+</span> <span class="nx">b</span><span class="p">;</span> <span class="p">},</span> <span class="mi">0</span><span class="p">);</span>
  <span class="k">return</span> <span class="nx">sum</span> <span class="err">/ array.length;</span>
<span class="p">}</span>

<span class="kd">var</span> <span class="nx">bus</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Bacon</span><span class="p">.</span><span class="nx">Bus</span><span class="p">();</span>
<span class="nx">bus</span><span class="p">.</span><span class="nx">slidingWindow</span><span class="p">(</span><span class="mi">3</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="nx">avg</span><span class="p">).</span><span class="nx">onValue</span><span class="p">(</span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">);</span>
<span class="nx">bus</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="c1">// output = 1
</span><span class="c1"></span><span class="nx">bus</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span> <span class="c1">// output = 1.5
</span><span class="c1"></span><span class="nx">bus</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span> <span class="c1">// output = 2
</span><span class="c1"></span></code></pre></div>

<p>You can see <a href="http://guidogarcia.net/demos/bacon/">another example</a> (<a href="https://github.com/palmerabollo/test-bacon">github</a>) where an event stream is created and populated with your mouse positions. The &ldquo;y&rdquo; position is represented along with the moving average.</p>
]]></content>
		</item>
		
		<item>
			<title>Evolutionary computation · TEFcon 2014</title>
			<link>https://guidogarcia.net/blog/2014/11/05/evolutionary-computation-%c2%b7-tefcon-2014/</link>
			<pubDate>Wed, 05 Nov 2014 08:13:34 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/11/05/evolutionary-computation-%c2%b7-tefcon-2014/</guid>
			<description>This is my presentation (spanish) about evolutionary computation for the TEFcon 2014. It was a talk about how we code and how genetic algorithms and genetic programming might help us. Because &amp;ldquo;programming should be more about the what and less about the how&amp;rdquo;.
 Edit: I&amp;rsquo;ve pushed the Java code for the queens problem using genetic algorithms to github.</description>
			<content type="html"><![CDATA[<p>This is my presentation (spanish) about <a href="https://en.wikipedia.org/wiki/Evolutionary_computation">evolutionary computation</a> for the TEFcon 2014. It was a talk about how we code and how genetic algorithms and genetic programming might help us. Because &ldquo;programming should be more about the what and less about the how&rdquo;.</p>

<iframe src="//slides.com/guidogarcia/algoritmos-geneticos/embed" width="576" height="420" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

<p>Edit: I&rsquo;ve pushed the Java code for the <a href="https://github.com/palmerabollo/genetic-queens">queens problem using genetic algorithms</a> to github.</p>
]]></content>
		</item>
		
		<item>
			<title>DTrace para flipar pepinillos</title>
			<link>https://guidogarcia.net/blog/2014/08/25/dtrace-para-flipar-pepinillos/</link>
			<pubDate>Mon, 25 Aug 2014 08:16:56 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/08/25/dtrace-para-flipar-pepinillos/</guid>
			<description>This is my presentation (spanish) about DTrace, a tracing framework created by Sun that is really cool. It is available on &amp;ldquo;Solaris&amp;rdquo; systems, but also on MacOS, BSD, and some Linux ports.
It is a really powerful tool once you get used to it.
 </description>
			<content type="html"><![CDATA[<p>This is my presentation (spanish) about <a href="https://en.wikipedia.org/wiki/DTrace">DTrace</a>, a tracing framework created by Sun that is really cool. It is available on &ldquo;Solaris&rdquo; systems, but also on MacOS, BSD, and some Linux ports.</p>

<p>It is a really powerful tool once you get used to it.</p>

<iframe src="//slides.com/guidogarcia/dtrace/embed" width="576" height="420" scrolling="no" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
]]></content>
		</item>
		
		<item>
			<title>How to catch an Internet troll</title>
			<link>https://guidogarcia.net/blog/2014/04/25/how-to-catch-an-internet-troll/</link>
			<pubDate>Fri, 25 Apr 2014 16:19:37 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/04/25/how-to-catch-an-internet-troll/</guid>
			<description>Some weeks ago I carried out a social experiment (dameunverso.com, spanish) that consisted in writing a poem in a collaborative and anonymous way. This means that anyone can add a new verse to the poem without identifying themselves or leaving any metadata (no cookies, no IP address tracking, etc).
Our first trolls didn&amp;rsquo;t take long to appear, mostly in the form of copyrighted material, spam and offensive contents. Is it possible to automatically classify an anonymous verse as spammy?</description>
			<content type="html"><![CDATA[

<p>Some weeks ago I carried out a social experiment (<del>dameunverso.com</del>, spanish) that consisted in writing a poem in a collaborative and anonymous way. This means that anyone can add a new verse to the poem without identifying themselves or leaving any metadata (no cookies, no IP address tracking, etc).</p>

<p>Our first trolls didn&rsquo;t take long to appear, mostly in the form of copyrighted material, spam and offensive contents. <strong>Is it possible to automatically classify an anonymous verse as spammy?</strong></p>

<p><img src="http://i.blogs.es/e3f676/trollface/450_1000.jpg" alt="Troll" /></p>

<h3 id="text-classification">Text classification</h3>

<p><a href="http://alias-i.com/lingpipe/">LingPipe</a> is a powerful Java toolkit for processing text, free for research use under some conditions. I followed the <a href="http://alias-i.com/lingpipe/demos/tutorial/classify/read-me.html">Text Classification Tutorial</a>, to classify verses in one of these categories: <strong>&ldquo;spam&rdquo; or &ldquo;love&rdquo;</strong>.</p>

<p>The classifier I built uses 80% of the poem (already classified into &ldquo;spam&rdquo; or &ldquo;love&rdquo; categories by hand), as a training set to learn and build a language model. Then, it uses the remaining 20% of the poem (48 verses) for cross-validation of this model.</p>

<p>You can find the code in the Annex I, it is less than 50 lines of code.</p>

<h3 id="classification-results">Classification results</h3>

<p>The classification <strong>accuracy is 75% ± 12.25%</strong>, so we can say that our model performs better than a monkey at significance level of 0.05.</p>

<pre><code>Categories=[spam, love]
Total Count=48
Total Correct=36
Total Accuracy=0.75
95% Confidence Interval=0.75 +/- 0.1225

Confusion Matrix
Macro-averaged Precision=0.7555
Macro-averaged Recall=0.7412
Macro-averaged F=0.7428
</code></pre>

<p>It seems pretty promising and it can serve as inspiration but, to be honest, I don&rsquo;t think it is such a good model. With so few contributions to the poem, it is prone to overfitting, so it is probably learning to classify just our usual trolls that are not original whatsoever.</p>

<p>Moreover, we are not taking into account other factors that would greatly improve the results, such as the structure of the verse (length, number of words, etc), the relation between the verses (rhyme) or the presence of inexistent words and typos. If you want to further investigate, I suggest taking a look at <a href="http://alias-i.com/lingpipe/demos/tutorial/logistic-regression/read-me.html">Logistic Regression</a>, to build better models that also include these kind of factors.</p>

<p>On a practical note, if you ever plan to carry out a similar experiment, remember two rules. First, make it easier for you to revert vandalism than for the troll to vandalize your site. Second, don&rsquo;t feed the troll. They will eventually get tired.</p>

<h3 id="annex-i-java-code">Annex I. Java Code</h3>

<div class="highlight"><pre class="chroma"><code class="language-java" data-lang="java"><span class="n">String</span><span class="o">[]</span> <span class="n">CATEGORIES</span> <span class="o">=</span> <span class="o">{</span> <span class="s">&#34;spam&#34;</span><span class="o">,</span> <span class="s">&#34;love&#34;</span> <span class="o">};</span>
<span class="kt">int</span> <span class="n">NGRAM_SIZE</span> <span class="o">=</span> <span class="n">6</span><span class="o">;</span>

<span class="n">String</span> <span class="n">textSpamTraining</span> <span class="o">=</span>
        <span class="s">&#34;Ola ke Ase\n&#34;</span> <span class="o">+</span>
        <span class="s">&#34;censurator\n&#34;</span> <span class="o">+</span>
        <span class="s">&#34;...&#34;</span><span class="o">;</span>

<span class="n">String</span> <span class="n">textLoveTraining</span> <span class="o">=</span>
        <span class="s">&#34;Me ahogo en un suspiro,\n&#34;</span> <span class="o">+</span>
        <span class="s">&#34;miro tus ojos de cristal\n&#34;</span> <span class="o">+</span>
        <span class="s">&#34;...&#34;</span><span class="o">;</span>

<span class="n">String</span><span class="o">[]</span> <span class="n">textSpamCrossValidation</span> <span class="o">=</span> <span class="o">{</span>
        <span class="s">&#34;os va a censurar&#34;</span><span class="o">,</span>
        <span class="s">&#34;esto es una mierda&#34;</span><span class="o">,</span>
        <span class="s">&#34;...&#34;</span>
<span class="o">};</span>

<span class="n">String</span><span class="o">[]</span> <span class="n">textLoveCrossValidation</span> <span class="o">=</span> <span class="o">{</span>
        <span class="s">&#34;el experimento ha revelado&#34;</span><span class="o">,</span>
        <span class="s">&#34;que el gran poeta no era orador&#34;</span><span class="o">,</span>
        <span class="s">&#34;y al no resultar como esperado&#34;</span><span class="o">,</span>
        <span class="s">&#34;se ha tornado en vil censor&#34;</span><span class="o">,</span>
        <span class="s">&#34;...&#34;</span>
<span class="o">};</span>

<span class="c1">// FIRST STEP - learn
</span><span class="c1"></span><span class="n">DynamicLMClassifier</span><span class="o">&lt;</span><span class="n">NGramProcessLM</span><span class="o">&gt;</span> <span class="n">classifier</span> <span class="o">=</span>
        <span class="n">DynamicLMClassifier</span><span class="o">.</span><span class="na">createNGramProcess</span><span class="o">(</span><span class="n">CATEGORIES</span><span class="o">,</span> <span class="n">NGRAM_SIZE</span><span class="o">);</span>

<span class="o">{</span>
    <span class="n">Classification</span> <span class="n">classification</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Classification</span><span class="o">(</span><span class="s">&#34;spam&#34;</span><span class="o">);</span>
    <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">classified</span> <span class="o">=</span>
        <span class="k">new</span> <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;(</span><span class="n">textSpamTraining</span><span class="o">,</span> <span class="n">classification</span><span class="o">);</span>
    <span class="n">classifier</span><span class="o">.</span><span class="na">handle</span><span class="o">(</span><span class="n">classified</span><span class="o">);</span>
<span class="o">}</span>

<span class="o">{</span>
    <span class="n">Classification</span> <span class="n">classification</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Classification</span><span class="o">(</span><span class="s">&#34;love&#34;</span><span class="o">);</span>
    <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">classified</span> <span class="o">=</span>
        <span class="k">new</span> <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;(</span><span class="n">textLoveTraining</span><span class="o">,</span> <span class="n">classification</span><span class="o">);</span>
    <span class="n">classifier</span><span class="o">.</span><span class="na">handle</span><span class="o">(</span><span class="n">classified</span><span class="o">);</span>
<span class="o">}</span>

<span class="c1">// SECOND STEP - compile
</span><span class="c1"></span><span class="n">JointClassifier</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">compiledClassifier</span> <span class="o">=</span>
                <span class="o">(</span><span class="n">JointClassifier</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;)</span>
                        <span class="n">AbstractExternalizable</span><span class="o">.</span><span class="na">compile</span><span class="o">(</span><span class="n">classifier</span><span class="o">);</span>

<span class="n">JointClassifierEvaluator</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">evaluator</span> <span class="o">=</span>
        <span class="k">new</span> <span class="n">JointClassifierEvaluator</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;(</span>
                <span class="n">compiledClassifier</span><span class="o">,</span> <span class="n">CATEGORIES</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>

<span class="c1">// THIRD STEP - cross-validate
</span><span class="c1"></span><span class="k">for</span> <span class="o">(</span><span class="n">String</span> <span class="nl">textSpamItem:</span> <span class="n">textSpamCrossValidation</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">Classification</span> <span class="n">classification</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Classification</span><span class="o">(</span><span class="s">&#34;spam&#34;</span><span class="o">);</span>
    <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">classified</span> <span class="o">=</span>
        <span class="k">new</span> <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;(</span><span class="n">textSpamItem</span><span class="o">,</span> <span class="n">classification</span><span class="o">);</span>
    <span class="n">evaluator</span><span class="o">.</span><span class="na">handle</span><span class="o">(</span><span class="n">classified</span><span class="o">);</span>
<span class="o">}</span>

<span class="k">for</span> <span class="o">(</span><span class="n">String</span> <span class="nl">textLoveItem:</span> <span class="n">textLoveValidation</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">Classification</span> <span class="n">classification</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Classification</span><span class="o">(</span><span class="s">&#34;love&#34;</span><span class="o">);</span>
    <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;</span> <span class="n">classified</span> <span class="o">=</span>
        <span class="k">new</span> <span class="n">Classified</span><span class="o">&lt;</span><span class="n">CharSequence</span><span class="o">&gt;(</span><span class="n">textLoveItem</span><span class="o">,</span> <span class="n">classification</span><span class="o">);</span>
    <span class="n">evaluator</span><span class="o">.</span><span class="na">handle</span><span class="o">(</span><span class="n">classified</span><span class="o">);</span>
<span class="o">}</span>

<span class="n">ConfusionMatrix</span> <span class="n">matrix</span> <span class="o">=</span> <span class="n">evaluator</span><span class="o">.</span><span class="na">confusionMatrix</span><span class="o">();</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&#34;Total Accuracy: &#34;</span> <span class="o">+</span> <span class="n">matrix</span><span class="o">.</span><span class="na">totalAccuracy</span><span class="o">());</span>

<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">evaluator</span><span class="o">);</span></code></pre></div>
]]></content>
		</item>
		
		<item>
			<title>Lazy loading of modules in nodejs</title>
			<link>https://guidogarcia.net/blog/2014/03/27/lazy-loading-modules-nodejs/</link>
			<pubDate>Thu, 27 Mar 2014 16:43:59 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/03/27/lazy-loading-modules-nodejs/</guid>
			<description>This is a pattern I found in pkgcloud to lazy-load nodejs modules. That is, to defer their loading until a module is actually needed.
var providers = [ &amp;#39;amazon&amp;#39;, &amp;#39;azure&amp;#39;, ..., &amp;#39;joyent&amp;#39; ]; ... //  // Setup all providers as lazy-loaded getters  //  providers.forEach(function (provider) { pkgcloud.providers.__defineGetter__(provider, function () { return require(&amp;#39;./pkgcloud/&amp;#39; + provider); }); });  It basically defines a getter, so modules won&amp;rsquo;t be loaded until you do:</description>
			<content type="html"><![CDATA[<p>This is a pattern I found in <a href="https://github.com/pkgcloud/pkgcloud/blob/master/lib/pkgcloud.js#L93">pkgcloud</a> to lazy-load nodejs modules. That is, to defer their loading until a module is actually needed.</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js">  <span class="kd">var</span> <span class="nx">providers</span> <span class="o">=</span> <span class="p">[</span> <span class="s1">&#39;amazon&#39;</span><span class="p">,</span> <span class="s1">&#39;azure&#39;</span><span class="p">,</span> <span class="p">...,</span> <span class="s1">&#39;joyent&#39;</span> <span class="p">];</span>
  <span class="p">...</span>

  <span class="c1">//
</span><span class="c1"></span>  <span class="c1">// Setup all providers as lazy-loaded getters
</span><span class="c1"></span>  <span class="c1">//
</span><span class="c1"></span>  <span class="nx">providers</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">provider</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">pkgcloud</span><span class="p">.</span><span class="nx">providers</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="nx">provider</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
      <span class="k">return</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./pkgcloud/&#39;</span> <span class="o">+</span> <span class="nx">provider</span><span class="p">);</span>
    <span class="p">});</span>
  <span class="p">});</span>
</code></pre></div>

<p>It basically defines a getter, so modules won&rsquo;t be loaded until you do:</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="kd">var</span> <span class="nx">provider</span> <span class="o">=</span> <span class="nx">pkgcloud</span><span class="p">.</span><span class="nx">providers</span><span class="p">.</span><span class="nx">amazon</span><span class="p">;</span>
</code></pre></div>

<p>It might be useful in applications where you have different adapters (&ldquo;providers&rdquo; in the example above) offering different implementations of the same API, and you want to let the user choose which one to use at runtime. This is a common requirement in cloud environments but it could be applicable to other scenarios as well (e.g. choose a payment gateway).</p>

<p>This is the first time I see it, so please share your thoughts on it and any other alternative approaches.</p>
]]></content>
		</item>
		
		<item>
			<title>Cloud is not cheap</title>
			<link>https://guidogarcia.net/blog/2014/03/18/cloud-is-not-cheap/</link>
			<pubDate>Tue, 18 Mar 2014 06:56:37 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/03/18/cloud-is-not-cheap/</guid>
			<description>There is a myth about cloud computing. Many people think they will save money moving their services to the cloud, but the reality is that the cloud is not cheap.
Virtualization, one of the core parts of cloud computing, tries to meet the promise of elastic capacity and pay-as-you-go policies. Despite of this promise, the true story is that today we are running virtual machines that don&amp;rsquo;t do much because, most part of the time, our applications are not doing anything.</description>
			<content type="html"><![CDATA[

<p>There is a myth about cloud computing. Many people think they will save money moving their services to the cloud, but the reality is that the cloud is not cheap.</p>

<p>Virtualization, one of the core parts of cloud computing, tries to meet the promise of elastic capacity and pay-as-you-go policies. Despite of this promise, the true story is that today we are running virtual machines that don&rsquo;t do much because, <strong>most part of the time, our applications are not doing anything</strong>. Their processors are underutilized. While this is an opportunity for cloud providers to oversubscribe their data centers, it also means we are overpaying for it. There is still much untapped potential for applications running on the cloud.</p>

<h3 id="services-in-the-21st-century">Services in the 21st century</h3>

<p>In the last few years we have seen many improvements in the way applications are packaged and deployed to the cloud, how to automate these processes, and we have learnt that we have to build applications for failure (see &ldquo;<a href="http://blog.hendrikvolkmer.de/2013/04/03/there-will-be-no-reliable-cloud-part-1/">There will be no reliable cloud</a>&rdquo;).</p>

<p>But what I have not seen yet is anything about services communicating to each other to share its health status. I think <strong>services in the cloud should be able to <a href="https://github.com/palmerabollo/express-ping">expose their status</a> in real time</strong>. This way they could talk to others and say &ldquo;hey, I&rsquo;m struggling to handle this load, who can help me out with 2 extra GB of RAM for <a href="http://aws.amazon.com/ec2/purchasing-options/spot-instances/">less than 10 cents/hour</a>?&ldquo;.</p>

<p>How do you think cloud will change apps in the next 5-10 years? Ryan Dahl - How do you see the future of PaaS (see 4:38)</p>

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/L_JKb61EalQ?start=277" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
]]></content>
		</item>
		
		<item>
			<title>The long tail in this blog</title>
			<link>https://guidogarcia.net/blog/2014/01/23/the-long-tail/</link>
			<pubDate>Thu, 23 Jan 2014 15:30:46 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/01/23/the-long-tail/</guid>
			<description>This blog is two years old, and I&amp;rsquo;d like to share how its &amp;gt;50K visits are distributed.
One single post drives 40% of the traffic to the blog. At the bottom, 70% of its posts represent 4% of the traffic.
In my opinion, the most popular ones are not the best ones. They are about very specific technical subjects, containing keywords in the title and in the URL slug. Google does the rest.</description>
			<content type="html"><![CDATA[<p>This blog is two years old, and I&rsquo;d like to share how its &gt;50K visits are distributed.</p>

<p><img src="/images/blog-longtail.png" alt="Long Tail" /></p>

<p>One <a href="http://guidogarcia.net/blog/2012/03/02/how-to-develop-java-rest-client/">single post</a> drives 40% of the traffic to the blog. At the bottom, 70% of its posts represent 4% of the traffic.</p>

<p>In my opinion, the most popular ones are not the best ones. They are about very specific technical subjects, containing keywords in the title and in the URL slug. Google does the rest.</p>
]]></content>
		</item>
		
		<item>
			<title>Performance is premature optimization</title>
			<link>https://guidogarcia.net/blog/2014/01/18/performance-is-premature-optimization/</link>
			<pubDate>Sat, 18 Jan 2014 19:06:03 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/01/18/performance-is-premature-optimization/</guid>
			<description>I will burn in hell, but performance is premature optimization nowadays. Despite it is very interesting from an engineering perspective, from the practical point of view of someone who wants to follow the make-shit-happen startup mantra, my advice is not to worry much about it when it comes to choosing a programming language.
There are things that matter more than the technology stack you choose. In this post I will try to explain why; then you can vent your rage in the comments section.</description>
			<content type="html"><![CDATA[

<p>I will burn in hell, but <strong>performance is premature optimization nowadays</strong>. Despite it is very interesting from an engineering perspective, from the practical point of view of someone who wants to follow the make-shit-happen startup mantra, my advice is not to worry much about it when it comes to choosing a programming language.</p>

<p>There are things that matter more than the technology stack you choose. In this post I will try to explain why; then you can vent your rage in the comments section.</p>

<p><a href="http://www.startupvitamins.com/products/startup-poster-aaron-levie-get-shit-done"><img src="/images/get-shit-done.jpg" alt="Get Shit Done" />
</a></p>

<h3 id="your-project-is-not-twitter">Your project is not Twitter</h3>

<p>It is not Facebook either, and it probably won&rsquo;t. I am sorry.</p>

<p>Chances of your next project being popular are slim. Even if you are so lucky, you app will not be popular from day one. Even if you are popular enough, hardware is so cheap at that point that it could be considered free for all practical purposes (around one dollar per day for a 1CPU/1GB machine; go compare that with our wages).</p>

<h3 id="your-project-will-fail">Your project will fail</h3>

<p>Face it. You are not alone, most projects fail and there is nothing wrong with it. They fail before performance becomes an issue. I do not know a single project that has failed solely due to a bad choice of a programming language.</p>

<p>So I think that, as a rule of thumb, it is a good idea to choose the technology that allows you to try and develop <a href="http://yobriefca.se/blog/2013/04/29/micro-service-architecture/">small components</a> faster (nodejs, is that you?). You will have time to throw some of those components away and rebuild their ultra-efficient alternatives from scratch in the unlikely case of needing it.</p>

<h3 id="conclusion">Conclusion</h3>

<p>You are not going to need performance; <strong>stop worrying and get shit done instead</strong>. I always have a Moët Et Chandon Dom Pérignon 1955 on the fridge to celebrate the day I face performance issues due to choosing X over Y.</p>
]]></content>
		</item>
		
		<item>
			<title>Function parameters in Python, Java and Javascript</title>
			<link>https://guidogarcia.net/blog/2014/01/18/function-parameters-python-java-javascript/</link>
			<pubDate>Sat, 18 Jan 2014 11:31:44 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/01/18/function-parameters-python-java-javascript/</guid>
			<description>This is a short post about how these programming languages compare with each other when it comes to declaring functions with optional parameters and default values. Feel free to leave alternatives in other languages in the comments.
Python. The good. Python is my favorite. Use your parameters in any order and define their default values as part of the function signature itself.
def foo(arg1, arg2=&amp;#34;default&amp;#34;): print &amp;#34;arg1:&amp;#34;, arg1, &amp;#34;arg2:&amp;#34;, arg2 The price to pay is that you can not define two methods with the same name in the same class.</description>
			<content type="html"><![CDATA[

<p>This is a short post about how these programming languages compare with each other when it comes to declaring functions with optional parameters and default values. Feel free to leave alternatives in other languages in the comments.</p>

<h3 id="python-the-good">Python. The good.</h3>

<p>Python is my favorite. Use your parameters in any order and define their default values as part of the function signature itself.</p>

<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">arg1</span><span class="p">,</span> <span class="n">arg2</span><span class="o">=</span><span class="s2">&#34;default&#34;</span><span class="p">):</span>
    <span class="k">print</span> <span class="s2">&#34;arg1:&#34;</span><span class="p">,</span> <span class="n">arg1</span><span class="p">,</span> <span class="s2">&#34;arg2:&#34;</span><span class="p">,</span> <span class="n">arg2</span></code></pre></div>

<p>The price to pay is that you can not define two methods with the same name in the same class.</p>

<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">sum</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>

<span class="k">def</span> <span class="nf">sum</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="o">+</span> <span class="n">c</span></code></pre></div>

<p>I am not a Python expert, but it does not seem such a big deal.</p>

<h3 id="java-the-ugly">Java. The ugly.</h3>

<p>Java is more verbose, but you have strong types and simple refactoring in exchange.</p>

<div class="highlight"><pre class="chroma"><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kt">void</span> <span class="nf">foo</span><span class="o">(</span><span class="n">String</span> <span class="n">arg1</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">foo</span><span class="o">(</span><span class="n">arg1</span><span class="o">,</span> <span class="s">&#34;default&#34;</span><span class="o">);</span>
<span class="o">}</span>

<span class="kd">public</span> <span class="kt">void</span> <span class="nf">foo</span><span class="o">(</span><span class="n">String</span> <span class="n">arg1</span><span class="o">,</span> <span class="n">String</span> <span class="n">arg2</span><span class="o">)</span> <span class="o">{</span>
    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">printf</span><span class="o">(</span><span class="s">&#34;arg1: %s arg2: %s&#34;</span><span class="o">,</span> <span class="n">arg1</span><span class="o">,</span> <span class="n">arg2</span><span class="o">);</span>
<span class="o">}</span></code></pre></div>

<h3 id="javascript-the-bad">Javascript. The bad.</h3>

<p>Javascript is a bit more ugly.</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">foo</span><span class="p">(</span><span class="nx">arg1</span><span class="p">,</span> <span class="nx">arg2</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">arg2</span> <span class="o">=</span> <span class="nx">arg2</span> <span class="o">||</span> <span class="s1">&#39;default&#39;</span><span class="p">;</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;arg1 %s arg2 %s&#39;</span><span class="p">,</span> <span class="nx">arg1</span><span class="p">,</span> <span class="nx">arg2</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div>

<p>This is <a href="https://github.com/joyent/node-smartdc/blob/master/lib/cloudapi.js#L223">real code</a> we use in Instant Servers, to have an optional first parameter:</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="nx">CloudAPI</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">getAccount</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">account</span><span class="p">,</span> <span class="nx">callback</span><span class="p">,</span> <span class="nx">noCache</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="p">(</span><span class="nx">account</span><span class="p">)</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="p">{</span>
        <span class="nx">callback</span> <span class="o">=</span> <span class="nx">account</span><span class="p">;</span>
        <span class="nx">account</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">account</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span> <span class="o">||</span> <span class="k">typeof</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="o">!==</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">throw</span> <span class="k">new</span> <span class="nx">TypeError</span><span class="p">(</span><span class="s1">&#39;callback (function) required&#39;</span><span class="p">);</span>
    <span class="p">...</span>
<span class="p">}</span>
</code></pre></div>

<p>It is pure crap.</p>
]]></content>
		</item>
		
		<item>
			<title>Give your configuration some REST</title>
			<link>https://guidogarcia.net/blog/2014/01/02/a-rest-configuration-server/</link>
			<pubDate>Thu, 02 Jan 2014 14:00:00 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2014/01/02/a-rest-configuration-server/</guid>
			<description>I have built a simple configuration server to expose your app&amp;rsquo;s configuration as a REST service. Its name is rest-confidence (github). In this post I will try to explain its basics and three use cases where it could be useful:
 To configure distributed services. As a foundation for A/B testing. As a simple service directory.  Install and run a basic rest-confidence configuration server The first step is installing the configuration server:</description>
			<content type="html"><![CDATA[

<p>I have built a simple <strong>configuration server</strong> to expose your app&rsquo;s configuration as a REST service. Its name is <strong>rest-confidence</strong> (<a href="https://github.com/palmerabollo/rest-confidence">github</a>). In this post I will try to explain its basics and three use cases where it could be useful:</p>

<ol>
<li>To configure distributed services.</li>
<li>As a foundation for A/B testing.</li>
<li>As a simple service directory.</li>
</ol>

<h3 id="install-and-run-a-basic-rest-confidence-configuration-server">Install and run a basic rest-confidence configuration server</h3>

<p>The first step is installing the configuration server:</p>

<pre><code>git clone https://github.com/palmerabollo/rest-confidence.git
cd rest-confidence
npm install
</code></pre>

<p>After that, you are ready to edit your <em><code>config.json</code></em> configuration file. For example:</p>

<div class="highlight"><pre class="chroma"><code class="language-json" data-lang="json"><span class="p">{</span>
  <span class="nt">&#34;mongodb&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;host&#34;</span><span class="p">:</span> <span class="s2">&#34;localhost&#34;</span><span class="p">,</span>
    <span class="nt">&#34;user&#34;</span><span class="p">:</span> <span class="s2">&#34;root&#34;</span>
  <span class="p">},</span>
  <span class="nt">&#34;redis&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;host&#34;</span><span class="p">:</span> <span class="s2">&#34;redis-server&#34;</span><span class="p">,</span>
    <span class="nt">&#34;port&#34;</span><span class="p">:</span> <span class="mi">6379</span>
  <span class="p">},</span>
  <span class="nt">&#34;logging&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;appender&#34;</span><span class="p">:</span> <span class="p">{</span>
      <span class="nt">&#34;type&#34;</span><span class="p">:</span> <span class="s2">&#34;file&#34;</span><span class="p">,</span>
      <span class="nt">&#34;filename&#34;</span><span class="p">:</span> <span class="s2">&#34;log_file.log&#34;</span><span class="p">,</span>
      <span class="nt">&#34;maxSize&#34;</span><span class="p">:</span> <span class="mi">10240</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">}</span></code></pre></div>

<p>Launch the configuration server (<code>npm start</code>) and you are done. You are now ready to start retrieving the values associated with any key, in a <strong>hierarchical way</strong>:</p>

<pre><code># curl http://localhost:8000/logging/appender
{&quot;type&quot;:&quot;file&quot;,&quot;filename&quot;:&quot;log_file.log&quot;,&quot;maxSize&quot;:10240}
</code></pre>

<p>or</p>

<pre><code># curl http://localhost:8000/logging/appender/maxSize
10240
</code></pre>

<h3 id="use-case-1-configure-distributed-services">Use case #1: Configure distributed services</h3>

<p>In my last post I wrote about <a href="http://guidogarcia.net/blog/2013/12/09/why-is-nodejs-so-cool-from-a-java-guy/">why I like nodejs</a>, a great platform for building <a href="http://yobriefca.se/blog/2013/04/28/micro-service-architecture/">micro-service-based architectures</a>. However, these kind of architectures also come with their own drawbacks. One of them is that they are <strong>more difficult to deploy and configure</strong>.</p>

<p>With a centralized configuration server such as rest-confidence everything becomes easier. Instead of configuring hundreds of settings on each component, you only need to configure the URL of your configuration server. Your service will go there to look up any configuration property it needs.</p>

<h3 id="use-case-2-a-b-testing">Use case #2: A/B testing</h3>

<p><a href="http://en.wikipedia.org/wiki/A/B_testing">A/B testing</a> is a simple way to test different changes to your application and determine which ones produce positive results.</p>

<p>As a simplistic example, imagine you want to test an alternative color for your blue sign-up button, and check how it affects the conversion rate. You can define a <code>$filter</code> with a <code>$range</code> limit in your configuration:</p>

<div class="highlight"><pre class="chroma"><code class="language-json" data-lang="json"><span class="p">{</span>
  <span class="nt">&#34;color&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;$filter&#34;</span><span class="p">:</span> <span class="s2">&#34;random&#34;</span><span class="p">,</span>
    <span class="nt">&#34;$range&#34;</span><span class="p">:</span> <span class="p">[</span>
      <span class="p">{</span> <span class="nt">&#34;limit&#34;</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="nt">&#34;value&#34;</span><span class="p">:</span> <span class="s2">&#34;red&#34;</span> <span class="p">}</span>
    <span class="p">],</span>
    <span class="nt">&#34;$default&#34;</span><span class="p">:</span> <span class="s2">&#34;blue&#34;</span>
  <span class="p">}</span>
<span class="p">}</span></code></pre></div>

<p>So when you retrieve the &ldquo;color&rdquo; property value using a random filtering criteria, you&rsquo;ll get different colors depending on the ranges.</p>

<pre><code># curl http://localhost:8000/?random=5
{&quot;color&quot;:&quot;red&quot;}
</code></pre>

<p>And with a different filtering value out of the range you will get the default value.</p>

<pre><code># curl http://localhost:8000/?random=15
{&quot;color&quot;:&quot;blue&quot;}
</code></pre>

<h3 id="use-case-3-simple-service-directory">Use case #3: Simple service directory</h3>

<p>You can use <a href="https://github.com/palmerabollo/rest-confidence">rest-confidence</a> as a simple <strong>service directory</strong>,  that is, a centralized server that facilitates dynamic location of other services&rsquo; endpoints, based on different criteria.</p>

<div class="highlight"><pre class="chroma"><code class="language-json" data-lang="json"><span class="p">{</span>
  <span class="nt">&#34;myservice&#34;</span><span class="p">:</span> <span class="p">{</span>
    <span class="nt">&#34;$filter&#34;</span><span class="p">:</span> <span class="s2">&#34;env&#34;</span><span class="p">,</span>
    <span class="nt">&#34;production&#34;</span><span class="p">:</span> <span class="p">{</span>
      <span class="nt">&#34;url&#34;</span><span class="p">:</span> <span class="p">{</span>
        <span class="nt">&#34;$filter&#34;</span><span class="p">:</span> <span class="s2">&#34;country&#34;</span><span class="p">,</span>
        <span class="nt">&#34;ES&#34;</span><span class="p">:</span> <span class="s2">&#34;http://myservice-production.es&#34;</span><span class="p">,</span>
        <span class="nt">&#34;UK&#34;</span><span class="p">:</span> <span class="s2">&#34;http://myservice-production.co.uk&#34;</span><span class="p">,</span>
        <span class="nt">&#34;$default&#34;</span><span class="p">:</span> <span class="s2">&#34;http://myservice-production.co.uk&#34;</span>
      <span class="p">},</span>
    <span class="p">},</span>
    <span class="nt">&#34;development&#34;</span><span class="p">:</span> <span class="p">{</span>
      <span class="nt">&#34;url&#34;</span><span class="p">:</span> <span class="s2">&#34;http://myservice-production.com&#34;</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">}</span></code></pre></div>

<p>With some criteria applied (for example, env=production and country=ES) you will get the proper service endpoint, or any other information you need:</p>

<pre><code># curl http://localhost:8000/myservice?country=ES&amp;env=production
{&quot;url&quot;:&quot;http://myservice-production.es&quot;}
</code></pre>

<p>I hope you find it useful. There is also a <a href="https://github.com/palmerabollo/rest-confidence-client">nodejs client</a>. Contributions are welcome.</p>
]]></content>
		</item>
		
		<item>
			<title>Why is node.js so cool? (from a Java guy)</title>
			<link>https://guidogarcia.net/blog/2013/12/09/why-is-nodejs-so-cool-from-a-java-guy/</link>
			<pubDate>Mon, 09 Dec 2013 14:43:51 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2013/12/09/why-is-nodejs-so-cool-from-a-java-guy/</guid>
			<description>I confess: I am a Java guy At least I used to be. Until I meet node.js. I still think the JVM is one of the greatest pieces of technology ever created by man, and I love the Spring Framework, the hundreds of Apache Java libraries or the over-six-hundred-page books about JEE patterns. It is great for big applications that are created by many developers, or applications that are made to last.</description>
			<content type="html"><![CDATA[

<h3 id="i-confess-i-am-a-java-guy">I confess: I am a Java guy</h3>

<p>At least I used to be. Until I meet node.js. I still think the JVM is one of the greatest pieces of technology ever created by man, and I love the Spring Framework, the hundreds of Apache Java libraries or the over-six-hundred-page books about JEE patterns. It is great for big applications that are created by many developers, or applications that are made to last.</p>

<p>But many applications today are not made to last. Sometimes you just want to test something fast. Fail fast, fail cheap, keep it simple&hellip; the &ldquo;be lean&rdquo; mantra, you know.</p>

<p>Moreover, open source has completely changed the way we build applications, moving from developing tons of code in monolithic applications to assembling <a href="http://mkhadikov.com/2012/02/02/programs-should-be-small.html">small programs</a> that use third-party components as middlewares (nosql databases, queues, caches).</p>

<h3 id="second-confession-i-hate-d-javascipt">Second confession: I hate(d) Javascipt</h3>

<p>Yes, Internet Explorer 4 made me hate Javascript. So the first time I heard about node.js and server-side Javascript I felt a shiver down my spine. It got worse when I started to play with the unfamiliar <a href="http://en.wikipedia.org/wiki/Continuation-passing_style">continuation-passing style</a>, the asynchronous callback hell did not take long to appear.</p>

<h3 id="a-simple-pattern-function-err-result">A simple pattern: function(err, result) {}</h3>

<p>But the absence of rules does not necessarily has to mean chaos. In fact, there is one pattern in node.js: your callbacks will have two arguments; the first argument will be an error object, the second one will be the result. This is your contract with the platform and, more important, with the community. Stick with it and you will be fine.</p>

<p>Using such a <strong>popular programming language</strong> plus this <strong>simple convention</strong> is what makes it so easy to start working with node.js. It makes building small modules that work together with other developers&rsquo; modules surprisingly easy. This is why we have more than 50K modules in the <a href="https://npmjs.org/">npm registry</a>. Most of them are probably worthless, but natural selection also applies here, and this evolutionary process is much faster than the Java Community Process (JCP).</p>

<p>With node.js I feel like a productive anarchist. I get shit done.</p>

<p><em>You should also read &ldquo;<a href="http://www.futurealoof.com/posts/broken-promises.html">Broken Promises</a>&rdquo;, &ldquo;<a href="http://www.quora.com/Node-js/Why-is-Node-js-becoming-so-popular">Why is node.js becoming so popular</a>&rdquo; (quora), and watch <a href="http://www.youtube.com/watch?v=2RXprpqRsfc">Mikeal Rogers&rsquo; talk on why is node so successful</a> (24 min).</em></p>
]]></content>
		</item>
		
		<item>
			<title>Big teams are not agile in the digital world</title>
			<link>https://guidogarcia.net/blog/2013/08/12/big-teams-are-not-agile-in-the-digital-world/</link>
			<pubDate>Mon, 12 Aug 2013 14:11:54 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2013/08/12/big-teams-are-not-agile-in-the-digital-world/</guid>
			<description>The post today is not so technical. I have been thinking about why many big corporations, with almost unlimited resources, are not able to deliver top quality products and services. Why companies with a small fraction of resources create new products faster?
I have found several sociopsychological causes, most of them related with an aspect of human activity: working in a team.
Diffusion of responsibility Diffusion of responsibility is a sociopsychological phenomenon whereby a person is less likely to take responsibility for action or inaction when others are present.</description>
			<content type="html"><![CDATA[

<p>The post today is not so technical. I have been thinking about why many big corporations, with almost unlimited resources, are not able to deliver top quality products and services. Why companies with a small fraction of resources create new products faster?</p>

<p>I have found several sociopsychological causes, most of them related with an aspect of human activity: working in a team.</p>

<h3 id="diffusion-of-responsibility">Diffusion of responsibility</h3>

<blockquote>Diffusion of responsibility is a sociopsychological phenomenon whereby a person is less likely to take responsibility for action or inaction when others are present. Considered a form of attribution, the individual assumes that others either are responsible for taking action or have already done so. The phenomenon tends to occur in groups of people above a certain critical size and when responsibility is not explicitly assigned. ([wikipedia](http://en.wikipedia.org/wiki/Diffusion_of_responsibility))</blockquote>

<p>This is a harmful situation, where everybody&rsquo;s responsibility becomes nobody&rsquo;s responsibility and tasks are just words instead of real actions.</p>

<h3 id="analysis-paralysis">Analysis paralysis</h3>

<blockquote>Analysis paralysis is the state of over-analyzing (or over-thinking) a situation so that a decision or action is never taken [...] rather than try something and change if a major problem arises. ([wikipedia](http://en.wikipedia.org/wiki/Analysis_paralysis))</blockquote>

<p>The perfect is the enemy of good in most cases, and the opportunity cost of decision analysis tends to be higher than taking some risks and launching a sub-optimal product. LinkedIn founder Raid Hoffman said <em>&ldquo;if you are not embarrassed by the first version of your product you&rsquo;ve launched too late&rdquo;</em>.</p>

<p>See also &ldquo;<a href="http://guidogarcia.net/blog/2014/01/18/performance-is-premature-optimization/">Performance is premature optimization</a>&ldquo;</p>

<h3 id="inertia-and-groupthink">Inertia and Groupthink</h3>

<blockquote>Inertia is the resistance of any physical object to any change in its motion (including a change in direction). In other words, it is the tendency of objects to keep moving in a straight line at constant linear velocity, or to keep still</blockquote>

<blockquote>Groupthink is a psychological phenomenon that occurs within a group of people, in which the desire for harmony or conformity in the group results in an incorrect or deviant decision-making outcome. Group members try to minimize conflict and reach a consensus decision without critical evaluation of alternative ideas or viewpoints, and by isolating themselves from outside influences. ([wikipedia](https://en.wikipedia.org/wiki/Groupthink))</blockquote>

<p>Do you remember the monkey banana and water spray experiment? It is hard to change the culture in a big corporation. It is not easy to innovate and disrupt when the main reason to keep doing something is that &ldquo;we have always done it that way&rdquo; or by coercion.</p>

<blockquote>The Milgram experiment on obedience to authority figures was a series of social psychology experiments, which measured the willingness of study participants to obey an authority figure who instructed them to perform acts that conflicted with their personal conscience. ([wikipedia](http://en.wikipedia.org/wiki/Milgram_experiment))</blockquote>

<h3 id="group-intercommunication">Group intercommunication</h3>

<p>The number of communication paths between a team of N people is N x (N – 1)/2. This means that time spent communicating (this includes <a href="http://gettingreal.37signals.com/ch07_Meetings_Are_Toxic.php">meetings</a>) increases exponentially while total productivity will only grow linearly.</p>

<p>I like the idea of <a href="http://lifehacker.com/5965280/follow-jeff-bezos-two-pizza-rule-to-avoid-the-dangers-of-groupthink">&ldquo;two pizza teams&rdquo;</a> coined by Jeff Bezos: if you can&rsquo;t feed a team with two pizzas, it&rsquo;s too large.</p>

<blockquote>When you’ve got a small group, you don’t need to constantly formalize things. You communicate and you know what’s going on. If you have a question about something, you ask someone. Formalized rules, deadlines, and documents start to seem silly. Everyone’s already on the same page anyway ([37signals](http://37signals.com/svn/posts/995-if-youre-working-in-a-big-group-youre-fighting-human-nature))</blockquote>

<h3 id="fear-of-failure">Fear of failure</h3>

<blockquote>Atychiphobia is the abnormal, unwarranted, and persistent fear of failure. As with many phobias, atychiphobia often leads to a constricted lifestyle, and is particularly devastating for its effects on a person’s willingness to attempt certain activities. ([wikipedia](http://en.wikipedia.org/wiki/Atychiphobia))</blockquote>

<p>I can think of at least four consequences of this fear of failure:</p>

<ul>
<li><strong>Overengineering</strong>: instead of <a href="http://en.wikipedia.org/wiki/KISS_principle">keeping a solution simple</a> engineers tend to overcomplicate a solution with <a href="http://en.wikipedia.org/wiki/You_aren't_gonna_need_it">unneeded features</a>, taking precautions to ensure not to be blamed if something goes wrong (see also <a href="http://gettingreal.37signals.com/ch04_Scale_Later.php">&ldquo;scale later&rdquo;</a>).</li>
<li><strong>Deliberate bad choices</strong>: &ldquo;no one gets fired for buying IBM&rdquo;. This applies to technological choices, selection of partners and support contracts that are slow, expensive and with questionable usefulness.</li>
<li><strong>Pessimistic attitude</strong> as a defense mechanism. If you put yourself in the worst scenario, from that point on everything would be better.</li>
<li><strong>Fear to <a href="http://gettingreal.37signals.com/ch05_Start_With_No.php">say no</a></strong> to authority figures.</li>
</ul>

<h3 id="emotional-contagion">Emotional contagion</h3>

<blockquote>Emotional contagion is a process in which a person or group influences the emotions or behavior of another person or group through the conscious or unconscious induction of emotion states and behavioral attitudes. ([wikipedia](http://en.wikipedia.org/wiki/Emotional_contagion))</blockquote>

<p>A whiner is somebody who complains a lot. This attitude is really infectious, and it spreads a negative karma almost impossible to erradicate. It diminishes passion and chances of success: <em>&ldquo;whether you think that you can, or that you can&rsquo;t, you are usually right&rdquo;</em>.</p>

<blockquote>"Little Eichmanns" is a phrase used to describe persons who participate in society in a way that, while on an individual scale may seem relatively innocuous even to themselves, taken collectively create destructive and immoral systems in which they are actually. ([wikipedia](http://en.wikipedia.org/wiki/Little_Eichmanns))</blockquote>

<h3 id="hierarchy">Hierarchy</h3>

<p>Excessive hierarchy is also dangerous. Too many hierarchical levels can stop or slow down decisions. Even making operative decisions that should take hours, take weeks.</p>

<p>Add more layers and employees will also stop feeling identified with the company. This is some kind of <strong>emotional detachment</strong>, workers do not think they can make significative contributions to the company, <a href="http://en.wikipedia.org/wiki/Collective_responsibility">collective responsibility</a> is lost, and problems in the company become someone else&rsquo;s problems.</p>

<blockquote>Somebody Else's Problem is a psychological effect where individuals/populations of individuals choose to dissociate themselves from an issue that may be in critical need of recognition. Such issues may be of large concern to the population as a whole but can easily be a choice of ignorance by an individual. ([wikipedia](http://en.wikipedia.org/wiki/Somebody_Else%27s_Problem))</blockquote>

<p>When roles are too much compartmentalized, some people stop being able to <a href="http://gettingreal.37signals.com/ch08_Get_Well_Rounded_Individuals.php">wear many hats</a>. I think this is because they start feeling that doing some tasks or getting their hands dirty would mean a step back in their professional careers, or just discredit. This is completely different in a small company, and clearly makes a difference in terms of speed.</p>

<p>I like passionated, small, flat, focused teams that really embrace agile and self-organization. Bureaucracy can kill agility. Big groups of people can be destructive for innovation and adaptation if not properly managed. The problem is even worse if objectives are not aligned in the company, but I will write about it in another post.</p>
]]></content>
		</item>
		
		<item>
			<title>Playing around with Meteor</title>
			<link>https://guidogarcia.net/blog/2013/03/01/playing-with-meteor-framewor/</link>
			<pubDate>Thu, 28 Feb 2013 23:38:42 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2013/03/01/playing-with-meteor-framewor/</guid>
			<description>I have been playing around with meteor, an open-source platform for building web apps. The result is a 200 LOC game ladder with a live demo.
The platform is built on top of nodejs, what is great. In my opinion, it is not ready for production environments yet, but I am really impressed with how fast you can create simple web applications with live page updates, automatic data synchronization and many other niceties I have never seen before in any other web framework.</description>
			<content type="html"><![CDATA[

<p>I have been playing around with <a href="http://meteor.com">meteor</a>, an open-source platform for building web apps. The result is a <a href="https://github.com/palmerabollo/game-ladder">200 LOC game ladder</a> with a <a href="http://ladder.meteor.com">live demo</a>.</p>

<p>The platform is built on top of nodejs, what is great. In my opinion, it is not ready for production environments yet, but I am really impressed with how fast you can create simple web applications with live page updates, automatic data synchronization and many other niceties I have never seen before in any other web framework.</p>

<h3 id="elo-algorithm">ELO algorithm</h3>

<p>There is an <a href="https://github.com/palmerabollo/game-ladder/issues/1">open issue</a> with the ranking algorithm. I am looking for a javascript implementation of the ELO algorithm. I am waiting for your pull requests!</p>
]]></content>
		</item>
		
		<item>
			<title>Deploy virtual machines on Instant Servers cloud with Java</title>
			<link>https://guidogarcia.net/blog/2013/02/17/deploy-virtual-machines-on-instant-servers-cloud-with-java/</link>
			<pubDate>Sun, 17 Feb 2013 20:23:26 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2013/02/17/deploy-virtual-machines-on-instant-servers-cloud-with-java/</guid>
			<description>Instant Servers is the infrastructure as a service (IaaS) system I have been working on during the last months in Telefónica Digital.
The service offers a public REST API (Cloud API) that is super simple to use. However, in this post I will show you how to manage your infrastructure using a Java client, without dealing with HTTP requests.
Build the Cloud API client Man does not live by nodejs alone.</description>
			<content type="html"><![CDATA[

<p><a href="http://cloud.telefonica.com/instantservers/">Instant Servers</a> is the infrastructure as a service (IaaS) system I have been working on during the last months in Telefónica Digital.</p>

<p>The service offers a public REST API (Cloud API) that is super simple to use. However, in this post I will show you how to manage your infrastructure using a Java client, without dealing with HTTP requests.</p>

<h3 id="build-the-cloud-api-client">Build the Cloud API client</h3>

<p>Man does not live by nodejs alone. There is an <a href="https://github.com/telefonicaid/instantservers.git">instantservers project at github</a> you can easily clone and compile (pull requests are also welcome). In the future it will be published as a proper maven artifact, so you can skip this point.</p>

<pre><code>git clone https://github.com/telefonicaid/instantservers.git
cd ./instantservers/instantservers-api-client
mvn install
</code></pre>

<p>That will generate an instantservers-api-client-1.0.0.M1.jar library you can use in your own applications.</p>

<h3 id="deploy-your-first-virtual-machine">Deploy your first virtual machine</h3>

<p>To deploy a virtual machine on Instant Servers cloud you only need to choose a <strong>name</strong> for the machine, a <strong>package</strong> that corresponds to the hardware configuration (cpu, mem, disk) you need, and a <strong>dataset</strong> that represents the image or template you want to use (i.e. ubuntu 12.04, mongodb, smartos, etc).</p>

<p>Let&rsquo;s code speak.</p>

<div class="highlight"><pre class="chroma"><code class="language-java" data-lang="java"><span class="kn">package</span> <span class="nn">net.guidogarcia</span><span class="o">;</span>

<span class="kn">import</span> <span class="nn">com.tdigital.instantservers.model.cloud.Machine</span><span class="o">;</span>

<span class="kd">public</span> <span class="kd">class</span> <span class="nc">InstantServersExample</span> <span class="o">{</span>
    <span class="c1">// there are several datacenters, I use Madrid &#34;eu-mad&#34; in this example
</span><span class="c1"></span>    <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">String</span> <span class="n">CLOUDAPI_URL</span> <span class="o">=</span>
            <span class="s">&#34;https://api-eu-mad-1.instantservers.telefonica.com&#34;</span><span class="o">;</span>

    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
        <span class="n">CloudAPIClient</span> <span class="n">client</span> <span class="o">=</span>
                <span class="k">new</span> <span class="n">CloudAPIClient</span><span class="o">(</span><span class="s">&#34;username&#34;</span><span class="o">,</span> <span class="s">&#34;password&#34;</span><span class="o">,</span> <span class="n">CLOUDAPI_URL</span><span class="o">);</span>

        <span class="n">Machine</span> <span class="n">machine</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Machine</span><span class="o">();</span>
        <span class="n">machine</span><span class="o">.</span><span class="na">setName</span><span class="o">(</span><span class="s">&#34;smallmachine&#34;</span><span class="o">);</span>
        <span class="n">machine</span><span class="o">.</span><span class="na">setPackage</span><span class="o">(</span><span class="s">&#34;g1_standard_1cpu_512mb&#34;</span><span class="o">);</span>
        <span class="n">machine</span><span class="o">.</span><span class="na">setDataset</span><span class="o">(</span><span class="s">&#34;sdc:sdc:smartos64:1.6.3&#34;</span><span class="o">);</span>

        <span class="n">Machine</span> <span class="n">deployed</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="na">createMachine</span><span class="o">(</span><span class="n">machine</span><span class="o">);</span>
        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">printf</span><span class="o">(</span><span class="s">&#34;Machine id is %s&#34;</span><span class="o">,</span> <span class="n">deployed</span><span class="o">.</span><span class="na">getId</span><span class="o">());</span>
    <span class="o">}</span>
<span class="o">}</span></code></pre></div>

<p>You will notice that virtual machines are up and running in a matter of seconds. This is due to the fact that the virtualization is based on rock solid <a href="http://en.wikipedia.org/wiki/Solaris_Containers">Solaris zones</a>.</p>

<p>You will need a username and a password to authenticate API calls, but you can <a href="http://cloud.telefonica.com/instantservers/">sign up for Instant Servers</a> for free (machines are still not free but you can try it for something like 6 cents per hour).</p>

<p>If anyone is interested in other API operations or about cloud computing in general, leave a comment and I will be happy to write more posts about it.</p>
]]></content>
		</item>
		
		<item>
			<title>Node.js running on my Raspberry Pi. A benchmark.</title>
			<link>https://guidogarcia.net/blog/2012/09/13/node-js-on-my-raspberry-pi-a-benchmark/</link>
			<pubDate>Thu, 13 Sep 2012 19:24:58 +0000</pubDate>
			
			<guid>https://guidogarcia.net/blog/2012/09/13/node-js-on-my-raspberry-pi-a-benchmark/</guid>
			<description>Few weeks ago I could not resist the temptation to buy a Raspberry Pi, the super-cheap 35$ computer that comes with 256MB of RAM and a ARM CPU running at 700MHz and fits in your pocket (more information in wikipedia).
See how nice it looks. I am more of a software guy, so the first thing I did was to install node.js (v0.6.19) develop the simplest web server you can create in node (5 lines, it simply returns a 200 HTTP response code without any contents) and put the beast to work.</description>
			<content type="html"><![CDATA[

<p>Few weeks ago I could not resist the temptation to buy a <a href="http://www.raspberrypi.org/">Raspberry Pi</a>, the super-cheap 35$ computer that comes with 256MB of RAM and a ARM CPU running at 700MHz and fits in your pocket (more information in <a href="http://en.wikipedia.org/wiki/Raspberry_Pi">wikipedia</a>).</p>

<p><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/3d/RaspberryPi.jpg/300px-RaspberryPi.jpg" alt="Raspberry Pi (wikipedia)" /></p>

<p>See how nice it looks. I am more of a software guy, so the first thing I did was to install <strong>node.js</strong> (v0.6.19) develop the simplest web server you can create in node (5 lines, it simply returns a 200 HTTP response code without any contents) and put the beast to work.</p>

<div class="highlight"><pre class="chroma"><code class="language-js" data-lang="js"><span class="kd">var</span> <span class="nx">http</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;http&#39;</span><span class="p">);</span>
<span class="nx">http</span><span class="p">.</span><span class="nx">createServer</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">res</span><span class="p">.</span><span class="nx">writeHead</span><span class="p">(</span><span class="mi">200</span><span class="p">);</span>
    <span class="nx">res</span><span class="p">.</span><span class="nx">end</span><span class="p">();</span>
<span class="p">}).</span><span class="nx">listen</span><span class="p">(</span><span class="mi">1337</span><span class="p">);</span>
</code></pre></div>

<h3 id="the-benchmark">The benchmark</h3>

<p>I was interested in testing the number of requests per second the application was able to handle running on the Raspberry in the most optimistic scenario. After having some problems running <a href="http://code.google.com/p/httperf/"><strong>httperf</strong></a> and <a href="https://github.com/menavaur/Autobench"><strong>autobench</strong></a> on Mac OS, I finally went with <a href="httpd.apache.org/docs/2.2/programs/ab.html"><strong>apachebench</strong></a> (ab), that can be used to do simple load testings.</p>

<p>These are the results of sending 5120 requests to the node web server, at different concurrency levels, using the following command:</p>

<pre><code>ab -n 5120 -c &lt;concurrency&gt; http://192.168.1.36:1337/
</code></pre>

<p><img src="/images/raspberry_concurrency.png" alt="raspberry benchmark results" /></p>

<p>Additional information: Each concurrency level has been executed three times from my laptop and using a wifi connection; the graph shows the average value. The Raspberry Pi was running the Raspbian “wheezy” image (<a href="http://www.raspberrypi.org/downloads">downloads</a>).</p>

<h3 id="open-points">Open points</h3>

<p>Almost <strong>200 requests per second</strong> in this non real world application that does nothing. It is not bad, enough to develop and try the ideas I have in mind. To be honest, I still do not know why the performance drops so much when the concurrency is 512, or which part (my laptop vs the raspberry) is the bottleneck and why. Any ideas?</p>

<p>I have to measure other aspects like CPU and memory usage. In a quick glance, it seems that the CPU quickly goes over 90% usage even with small concurrency leves. I still appreciate this piece of hardware, but in the future I will try to overclock the processor. The memory was under 10%, what is not strange in this simple application.</p>

<p>I am also waiting for the Java Virtual Machine, that is supposed to be included in the default file system in future releases, to repeat the benchmarks (and probably see how it eats the memory).</p>

<p>It seems interesting, from a research point of view, to <a href="http://www.zdnet.com/raspberry-pi-meets-lego-in-supercomputer-like-cluster-photos-7000004209/">build a cluster</a> and see how it scales. Donations for this purpose are highly appreciated :)</p>
]]></content>
		</item>
		
	</channel>
</rss>
