<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Roberto Aloi]]></title>
  <link href="http://roberto-aloi.com/atom.xml" rel="self"/>
  <link href="http://roberto-aloi.com/"/>
  <updated>2013-04-29T13:46:37+02:00</updated>
  <id>http://roberto-aloi.com/</id>
  <author>
    <name><![CDATA[Roberto Aloi]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Erlang User Conference 2013]]></title>
    <link href="http://roberto-aloi.com/blog/2013/04/29/euc/"/>
    <updated>2013-04-29T13:35:00+02:00</updated>
    <id>http://roberto-aloi.com/blog/2013/04/29/euc</id>
    <content type="html"><![CDATA[<div style="text-align:center">
     <a href="http://www.erlang-factory.com/conference/ErlangUserConference2013" target="_blank"><img src="http://roberto-aloi.com/images/seeyouthere.jpg" alt="EUC 2013" /></a>
</div>


<br />


<p>Hej, hej! I will be training at the Erlang User Conference 2013 in Stockholm, Sweden.<br />
Looking forward to see you all there.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Erlang Workshop in Rome, Italy]]></title>
    <link href="http://roberto-aloi.com/blog/2013/02/26/erlang-workshop/"/>
    <updated>2013-02-26T12:43:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2013/02/26/erlang-workshop</id>
    <content type="html"><![CDATA[<div style="text-align:center">
<a href="http://rome.codemotionworld.com/workshop/erlang-multi-core-e-massive-scalability/" target="_blank">
<img style="width:60%" src="http://roberto-aloi.com/images/erlang-workshop.png" alt="Erlang Workshop Codemotion - Rome 2013" />
</a>
</div>


<br />


<p>For the third year in a row, Erlang Solutions will be present at Codemotion, one of the biggest IT conferences in Italy which focuses on innovative programming languages.This year, we propose a one day hands-on workshop on the Erlang programming language. I will hold the workshop in Rome on the 20th March. The workshop is titled&#8221;Erlang: multi-core and massive scalability&#8221; and it consists of a practical overview of the Erlang programming language.</p>

<p>You can register to the workshop <a href="http://rome.codemotionworld.com/workshop/erlang-multi-core-e-massive-scalability/">here</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Ever wondered which application a given Erlang module belongs to?]]></title>
    <link href="http://roberto-aloi.com/blog/2012/12/12/ever-wondered-which-application-a-given-erlang-module-belongs-to/"/>
    <updated>2012-12-12T16:12:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2012/12/12/ever-wondered-which-application-a-given-erlang-module-belongs-to</id>
    <content type="html"><![CDATA[<p>For example, wouldn&#8217;t it be awesome to have the following:</p>

<pre><code>./efind.sh cover
tools
</code></pre>

<p>Well, here is a little script which might allow you to save some time:</p>

<div><script src='https://gist.github.com/4268342.js?file=efind.sh'></script>
<noscript><pre><code>#!/bin/sh
 
ROOTDIR=`which erl | sed -ne '/^ROOTDIR=/s///p'`
find $ROOTDIR -name $1.erl | awk -F / '{print $(NF-2)}' | awk -F - '{print $1}'</code></pre></noscript></div>


<p>Enjoy.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA['Erlang and the Cloud' Codemotion slides available online]]></title>
    <link href="http://roberto-aloi.com/blog/2012/11/17/slides-from-my-erlang-codemotion-talk-available-online/"/>
    <updated>2012-11-17T17:38:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2012/11/17/slides-from-my-erlang-codemotion-talk-available-online</id>
    <content type="html"><![CDATA[<p>The slides from my <em>Erlang and the Cloud</em> talk are now available on <a href="https://speakerdeck.com/robertoaloi/erlang-and-the-cloud" target="_blank">Speakerdeck</a>.</p>

<p>Enjoy.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Codemotion Venice 2012: Erlang and the Cloud]]></title>
    <link href="http://roberto-aloi.com/blog/2012/11/15/codemotion-venice-2012-erlang-and-the-cloud/"/>
    <updated>2012-11-15T11:09:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2012/11/15/codemotion-venice-2012-erlang-and-the-cloud</id>
    <content type="html"><![CDATA[<div style="text-align:center">
<a href="http://www.codemotion.it" target="_blank">
<img src="http://roberto-aloi.com/images/codemotion-logo.png" alt="Codemotion Venice 2012" />
</a>
</div>




<br />


<p>A special edition of the Codemotion conference <a href="http://www.codemotion.it" target="_blank"> will be held this year in Venice on Saturday the 17th November</a>. The event is free to attend.</p>

<p>I will give a talk at 15.40, titled <em>&#8220;Erlang and the Cloud&#8221;</em>. I will be discussing the suitability of the Erlang programming language for scenarios such as cloud computing and multi-core, explaining how the concurrency model of Erlang maps to multicore architectures and what principles should be kept in mind when designing a scalable application. The Twitter hashtag for my talk is <em>#lang06</em>.</p>

<p>The talk should be interesting on its own - well, I&#8217;ll do my best - but, in case you&#8217;re still dubious about attending, let me give you three extra reasons why you should join us:</p>

<h3>1. Erlang Solutions is hiring</h3>

<p>We have many positions open for Erlang enthusiasts in Sweden, UK, Poland and USA. I will be able to provide you more information about our hiring process. Also, feel free to leave me a copy of your CV.</p>

<h3>2. Free Erlang E-learning</h3>

<p>Erlang Solutions, in collaboration with the University of Kent, has developed an e-learning platform dedicated to Erlang. The system tries to deliver, at a distance, the same high-quality interactive experience that is delivered in our face-to-face training courses. <strong>During the conference, I will give away 25 e-learning vouchers</strong> which will give you <strong>free</strong> access to our online <em>Erlang Express</em> course, featuring 6 hours of video lectures, exercises, quizzes and more.</p>

<h3>3. Giveaways</h3>

<div style="text-align:center">
<a href="http://roberto-aloi.com/images/codemotion-giveaways.jpg" target="_blank">
<img src="http://roberto-aloi.com/images/codemotion-giveaways.jpg" alt="Erlang Giveaways" />
</a>
</div>


<p>Giveaways are always a pleasant surprise. Ask me for pens, stickers and weird white stuff, before I run out of stock!</p>

<p>See you all in Venice.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to Checkout GitHub Pull Requests Locally]]></title>
    <link href="http://roberto-aloi.com/blog/2012/11/12/checkout-github-pull-requests-locally/"/>
    <updated>2012-11-12T10:36:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2012/11/12/checkout-github-pull-requests-locally</id>
    <content type="html"><![CDATA[<p>I&#8217;ve recently bumped into the following useful <a href="https://gist.github.com/3342247" target="_blank">gist</a>, which I decided to share with all of you.</p>

<p>It&#8217;s possible to instruct git to fetch pull requests together with the other project branches. Simply open the <code>.git/config</code> file for your project and add the following line under the <code>[remote "origin"]</code> section:</p>

<pre><code>fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
</code></pre>

<p>To enable this behaviour for all of your git projects, simply run:</p>

<pre><code>git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
</code></pre>

<p>To fetch all the pull requests for a project:</p>

<pre><code>git fetch origin
</code></pre>

<p>To checkout a specific pull request (say, #53):</p>

<pre><code>git checkout pr/53
</code></pre>

<p>Enjoy!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[History of a Generation]]></title>
    <link href="http://roberto-aloi.com/blog/2012/09/12/history-of-a-generation/"/>
    <updated>2012-09-12T18:36:00+02:00</updated>
    <id>http://roberto-aloi.com/blog/2012/09/12/history-of-a-generation</id>
    <content type="html"><![CDATA[<p>I wanted to translate <a href="http://torto45.wordpress.com/2010/10/29/hello-world/" target="_blank">this blog post</a> into English, cause I believe it renders an almost perfect picture of Italy as it is today. This is a free translation and all the rights for the original blog post belong to the original author.</p>

<p>When I was a child, I was told:</p>

<blockquote><p>&#8220;Study, or you’ll go nowhere.&#8221;</p></blockquote>

<p>So I’ve studied.</p>

<p>After completing my academic career, I’ve been told:</p>

<blockquote><p>&#8220;Why did you spend so much time on a degree? Don’t you know that’s a useless piece of paper? You’d better to learn a trade.&#8221;</p></blockquote>

<p>I’ve learned a trade. Then, I’ve been told:</p>

<blockquote><p>&#8220;What a shame. You’ve studied so many years for that trade?”</p></blockquote>

<p>I moved ahead, and I left my job. I became penniless.</p>

<p><em>One day I was too young and inexperienced. The day after I was too old, with too much experience and too many titles.</em></p>

<p>I finally found a job. Well, not a permanent one. A temporary one, with no paid leave, no insurance, no pension, no bonuses, no severance, no rights. And I had to fight hard to keep that not-a-job. I decided not to have children, because of some sense of responsibility, and I grew up. Then I’ve been told, <a href="http://www.dailymail.co.uk/news/article-1289005/Rise-bamboccioni-big-babies--Why-young-Italians-choosing-live-home.html" target="_blank">by someone who got his job in the 60s, when it was easy to get a job, despite of your education level</a>:</p>

<blockquote><p>“You are a fool, a dupe who didn’t want to grow up and raise a family&#8221;.</p></blockquote>

<p>In the meantime, I was paying his very own pension, saying a final goodbye to mine. Tired and grown up, I decided to have a baby. I’ve been told that:</p>

<blockquote><p>“Only an irresponsible person would have a child without a proper job and without a good economical background”.</p></blockquote>

<p>Given that I could not kill my son, I decided to emigrate. I went somewhere else. I found a safe place, and a good job. I was feeling good. I was feeling home. But one day, when the Italian system went bankrupt, I’ve then been told:</p>

<blockquote><p>“Why the hell did you flee? Why didn’t you help your Country?”.</p></blockquote>

<p>At that point, There was only one very reply:</p>

<blockquote><p>“Fuck off!”.</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How they tried to fool tryerlang.org]]></title>
    <link href="http://roberto-aloi.com/blog/2010/10/14/how-they-tried-to-fool-tryerlang-org/"/>
    <updated>2010-10-14T00:00:00+02:00</updated>
    <id>http://roberto-aloi.com/blog/2010/10/14/how-they-tried-to-fool-tryerlang-org</id>
    <content type="html"><![CDATA[<h2>Preface</h2>


<p><a title="tryerlang.org" href="http://tryerlang.org" target="_blank">tryerlang.org</a> is an <em>interactive Erlang Shell</em> which allows users to try the power of Erlang directly in a browser, without requiring them to install an Erlang runtime system on their machine. Even if intended for Erlang newbies, tryerlang.org has been subjected to a countless number of attacks conducted by Erlang experts who wanted to circumvent its sandboxing mechanism and to bring down the Erlang node running the application. I must admit that going through the tryerlang.org&#8217;s logs is being an highly interesting and constructive experience.</p>

<p>In this blog post I will present one of the most elaborated attacks performed on tryerlang.org. The attack, which exploits the Erlang <em>External Term Representation</em>, has been performed by a former <a href="http://www.erlang-solutions.com" target="_blank">Erlang Solutions</a>&#8217; employee who had access to the tryerlang.org source code. To understand how the attack works, we need to introduce the Erlang <em>External Term Representation</em>.</p>

<h2>External Term Representation</h2>


<p>In Distributed Erlang, terms can be transferred from an Erlang node to another one using the so-called <em>binary</em> format. Generic terms are encoded in binary from the sender using the built-in function <code>term_to_binary/1</code> and restored from the receiver using the complementary function <code>binary_to_term/2</code>. A binary message looks like this:</p>

<pre>
<<131,100,0,6,112,105,103,101,111,110>>
</pre>


<p>Which, as you can see, represents the binary encoding of the atom <code>pigeon</code>.</p>

<pre>
1&gt; term_to_binary(pigeon).
&lt;&lt;131,100,0,6,112,105,103,101,111,110&gt;&gt;
2&gt; binary_to_term(&lt;&lt;131,100,0,6,112,105,103,101,111,110&gt;&gt;).
pigeon
</pre>


<p>The <em>External Term Representation</em> of Erlang terms is extensively documented in <a title="Erlang External Term Representation" href="http://www.erlang.org/doc/apps/erts/erl_ext_dist.html" target="_blank">the official Erlang Documentation</a>. Let&#8217;s see how the attacker used this concept in his own interest.</p>

<h2>Halting the Erlang Node</h2>


<p>To stop the Erlang node running tryerlang.org, the attacker tries at first the following command:</p>

<pre>
&gt; erlang:halt().
</pre>


<p>This function, documented <a title="Erlang Halt" href="http://www.erlang.org/doc/man/erlang.html#halt-0" target="_blank">here</a>, is supposed to <em>halt</em> an Erlang runtime system, indicating a normal exit to the calling environment. The function has been disabled in tryerlang.org for security reasons, so the only result the user get is the following annoying message:</p>

<pre>
"This functionality has been disabled for security reasons in tryerlang.org.".
</pre>


<p>So, the Erlang node is still up and attacker prepares himself a good cup of Swedish coffee. After a couple of minutes playing with the tryerlang.org shell, the attcker notices that tryerlang.org allows you to define custom <a title="Erlang Funs" href="http://www.erlang.org/doc/programming_examples/funs.html" target="_blank">funs</a>. Then, the intuition. A <em>fun</em>, as any other Erlang term, <a title="export_ext" href="http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#id83276" target="_blank">can be encoded using the External Terms Representation</a>. The encoded fun could then be executed. This could hopefully fool the sandboxing mechanism protecting the tryerlang.org and could open a world of possibilities to the attacker.</p>

<p>According to the documentation, the external representation of the fun (in the <code>fun M:F/A</code> format) is the following:</p>

<pre>
113 | Module | Function | Arity
</pre>


<p>Where <code>Module</code> and <code>Function</code> are atoms and <code>Arity</code> is an integer.</p>

<p>Atoms themselves can be encoded using the <a title="atom ext" href="http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#ATOM_EXT" target="_blank">ATOM_EXT</a> format:</p>

<pre>
100 | Len | AtomName
</pre>


<p>Where <code>Len</code> is the length of <code>AtomName</code>, expressed using two bytes.</p>

<p>For the atom <code>erlang</code>, which is composed of 6 characters (the letters <code>e</code>, <code>r</code>, <code>l</code>, <code>a</code>, <code>n</code> and <code>g</code>) we obtain:</p>

<pre>
100 | 0, 6 | 101, 114, 108, 97, 110, 103
</pre>


<p>Where the integers in the third section are the ASCII codes for each of the letters composing the word &#8220;erlang&#8221;.</p>

<p>Applying the same reasoning to the atom <code>halt</code>, we obtain:</p>

<pre>
100 | 0, 4 | 104, 97, 108, 116
</pre>


<p>Finally, the arity (an integer) can be encoded using the <a title="small integer ext" href="http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#id80902" target="_blank">SMALL_INTEGER_EXT</a> format:</p>

<pre>
97 | Int
</pre>


<p>So, in our case (arity = 0) we obtain:</p>

<pre>
97 | 0
</pre>


<p>Putting all the pieces together and considering that, in the External Term Representation, the byte <code>131</code> needs to be prepended to the final term, we can encode the <code>erlang:halt/</code>0 function into binary, obtaining:</p>

<pre>
&lt;&lt;131,113,100,0,6,101,114,108,97,110,103,100,0,4,104,97,108,116,97,0&gt;&gt;
</pre>


<p>Let&#8217;s verify that we didn&#8217;t do any mistake:</p>

<pre>
&gt; binary_to_term(&lt;&lt;131,113,100,0,6,101,114,108,97,110,103,100,0,4,104,97,108,116,97,0&gt;&gt;).
&gt; #Fun&lt;erlang.halt.0&gt;
</pre>


<p>Since tryerlang.org doesn&#8217;t support copy-and-paste from the clipboard, we need to insert the sequence above by hand.</p>

<p>We can bind the binary to a new variable:</p>

<pre>
&gt; B = &lt;&lt;131,113,100,0,6,101,114,108,97,110,103,100,0,4,104,97,108,116,97,0&gt;&gt;.
</pre>


<p>We now need to convert the binary into an Erlang term. Originally, tryerlang.org was allowing <a title="Erlang Safe Binary To Term" href="http://www.erlang.org/doc/man/erlang.html#binary_to_term-2" target="_blank">the binary_to_term function in safe mode</a>. This function has been now completely disabled after this attack. If you want to try what follows you will need to do it in your own Erlang shell.</p>

<pre>
&gt; F = binary_to_term(B, [safe]).
</pre>


<p>Let&#8217;s now try to launch the fun as:</p>

<pre>
&gt;F().
</pre>


<p>Well, that didn&#8217;t work as expected. tryerlang.org actually realized that the <code>erlang:halt/0</code> function was going to be called and the sandboxing mechanism managed to block the execution of the command. We need to do something slightly different. For example, we might pass the newly defined fun as an argument (after all, Erlang is a functional language) to a function who would take care of executing it. As an example, we could use the library function <code>lists:map/2</code>. There&#8217;s only a little tiny problem with that. The <code>list:map/2</code> function, in fact, requires that the fun passed as an argument receives <em>exactly one argument</em>. This is not the case of the <code>erlang:halt/0</code> function, which has arity equal to zero. Fortunately <a href="http://www.erlang.org/doc/man/erlang.html#halt-1" target="_blank">an alternative version of <code>erlang:halt/0</code> exists, taking exactly one argument</a>. The external representation for the new function differs from the previous one by only the very last byte. Let&#8217;s <em>forget</em> the old value of the variable <code>B</code> and let&#8217;s bind it to the new binary:</p>

<pre>
&gt; f(B).
&gt; B = &lt;&lt;131,113,100,0,6,101,114,108,97,110,103,100,0,4,104,97,108,116,97,1&gt;&gt;.
</pre>


<p>We can now pass the new fun as an argument to the <code>lists:map</code> function:</p>

<pre>
&gt; f(F).
&gt; F = binary_to_term(B, [safe]).
&gt;lists:map(F, [0]).
</pre>


<p>And the node dies. Well, in reality the node is almost immediately brought back by <a title="Erlang Heart" href="http://www.erlang.org/doc/man/heart.html" target="_blank">heart</a> which is listening for heartbeats from the Erlang node itself but, hey, I have to pay a beer to this guy! :)</p>

<p>I wanted to share this experience with all of you. I consider it highly constructive, since it leads to reflect on several aspects of Erlang. Comments and feedback are more than welcome.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Emacs Tips and Tricks]]></title>
    <link href="http://roberto-aloi.com/blog/2009/02/19/emacs-tips-and-tricks/"/>
    <updated>2009-02-19T00:00:00+01:00</updated>
    <id>http://roberto-aloi.com/blog/2009/02/19/emacs-tips-and-tricks</id>
    <content type="html"><![CDATA[<p>In this blog post I collect some miscellaneous Emacs tips and tricks.</p>

<h2>Playing with Macros</h2>


<p>In Emacs, you can <em>record</em> a set of actions that you can then apply to a selected region. As an example, let&#8217;s transform the following three lines:</p>

<pre>
First Line
Second Line
Third Line
</pre>


<p>into a list of items, using a macro:</p>

<pre>
- First Line
- Second Line
- Third Line
</pre>


<p>Put your cursor on the <code>First line</code>, then start recording a new keyboard macro by typing:</p>

<pre>C-x (</pre>


<p>Jump to the beginning of the line (<code>C-a</code>), insert a dash followed by a space (<code>- </code>) and then move your cursor down one line, so it resides on the <code>Second Line</code>.</p>

<p>Stop recording the macro:</p>

<pre>C-x )</pre>


<p>Now select the lines <code>Second Line</code> and <code>Third Line</code> and apply the newly recorded macro to the selected region by pressing:</p>

<pre>C-x C-k r</pre>


<p>You should now see the desired output.</p>

<h2>Swapping Words</h2>


<p>Say that you want to reverse the order of the parameter for the following function:</p>

<pre>
foo(Second, First) -&gt;
    ok.
</pre>


<p>Position the cursor between the words <code>Second</code> and <code>First</code>. Then, press:</p>

<pre>M-t</pre>


<p>You should obtain the following:</p>

<pre>
foo(First, Second) -&gt;
    ok.
</pre>




<h2>Swapping Lines</h2>


<p>Given the following two lines:</p>

<pre>
Second Line
First Line
</pre>


<p>Put the cursor at the beginning of <code>First Line</code> and press:</p>

<pre>C-x C-t</pre>


<p>You should get:</p>

<pre>
First Line
Second Line
</pre>




<h2>Version Control</h2>


<p>Emacs has support for the most common Version Control systems (e.g. <em>SVN</em>).</p>

<p>To check-in a single file directly from Emacs, simply follow the steps below:</p>

<ul>
<li>Press <code>C-x v v</code></li>
<li>Write a meaningful <em>change comment</em></li>
<li>Press <code>C-c C-c</code></li>
</ul>


<p>To revert changes for the current buffer:</p>

<p><code>C-x v u</code></p>

<p>To see the differences for a buffer before committing it:</p>

<p><code>C-x v =</code></p>

<h2>Executing a Shell Command</h2>


<p>If you want to execute a shell command within Emacs, you can simply type:</p>

<pre>M-!</pre>


<p>If you want to include the output into the current buffer, then:</p>

<pre>C-u M-!</pre>




<h2>Clipboard History</h2>


<p>Emacs keeps a clipboard history, allowing you to paste old clipboard entries. To utilize this function:</p>

<p>Press the following to paste:</p>

<pre>C-y</pre>


<p>And then browse the clipboard history by repeatedly typing:</p>

<pre>M-y</pre>




<h2>Create a Numbered List</h2>


<p>Say that you have a list of items that you want to convert into a numbered list:</p>

<pre>
first
second
third
</pre>




<pre>
1. first
2. second
3. third
</pre>


<p>There are many ways to achieve this. One is to use <a
href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macro-Counter.html#Keyboard-Macro-Counter"
target="_blank">the Emacs Keyboard Macro Counter</a>.</p>

<p>Position the cursor one line <em>above</em> your list and start registering a new macro:</p>

<pre>C-x (</pre>


<p>Insert a new counter value:</p>

<pre>C-x C-k C-i.</pre>


<p>A <code>0</code> will appear. Append a dot and a space:</p>

<pre>. </pre>


<p>Move the cursor to the next line and stop registering the macro:</p>

<pre>C-x )</pre>


<p>Select the list of items and apply the macro to the selected region:</p>

<pre>C-x C-k r</pre>


<p>Delete the <code>0</code> that you added at the beginning of the list and enjoy your brand new numbered list.</p>
]]></content>
  </entry>
  
</feed>
