<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sergio Veiga</title>
	<atom:link href="http://sergioveiga.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://sergioveiga.com</link>
	<description></description>
	<lastBuildDate>Fri, 16 Jul 2010 15:04:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Great Programming Quotations</title>
		<link>http://sergioveiga.com/index.php/2010/07/16/great-programming-quotations/</link>
		<comments>http://sergioveiga.com/index.php/2010/07/16/great-programming-quotations/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 15:04:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=172</guid>
		<description><![CDATA[&#8220;Measuring programming progress by lines of code is like measuring
aircraft building progress by weight.&#8220;Bill Gates
&#8220;Nine people can&#8217;t make a baby in a month.&#8221; Fred Brooks
&#8220;Weeks of coding can save you hours of planning.&#8221; unknown
You can find a lot more here

&#160;Share now!]]></description>
			<content:encoded><![CDATA[<p>&#8220;<strong>Measuring programming progress by lines of code is like measuring<br />
aircraft building progress by weight.</strong>&#8220;<em>Bill Gates</em></p>
<p>&#8220;<strong>Nine people can&#8217;t make a baby in a month.</strong>&#8221; <em>Fred Brooks</em></p>
<p>&#8220;<strong>Weeks of coding can save you hours of planning.</strong>&#8221; <em>unknown</em></p>
<p>You can find a lot more <a href="http://www.linfo.org/q_programming.html">here</a></p>
<p><a href="http://www.linfo.org/q_programming.html"></a></p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Great+Programming+Quotations&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2010%2F07%2F16%2Fgreat-programming-quotations%2F&b=Reading %22Great+Programming+Quotations%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2010/07/16/great-programming-quotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebSocket Handshake 76 in Erlang</title>
		<link>http://sergioveiga.com/index.php/2010/06/17/websocket-handshake-76-in-erlang/</link>
		<comments>http://sergioveiga.com/index.php/2010/06/17/websocket-handshake-76-in-erlang/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 12:09:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=166</guid>
		<description><![CDATA[Websocket get update and handshacke get broken&#8230; this is not for sure and end version of the protocol, but since newer versions of chrome are using it and its not compatible with previous version its a good option to implement both.
In order to understand what changed, i recommend you to read the great resume done [...]]]></description>
			<content:encoded><![CDATA[<p>Websocket get update and handshacke get broken&#8230; this is not for sure and end version of the protocol, but since newer versions of chrome are using it and its not compatible with previous version its a good option to implement both.</p>
<p>In order to understand what changed, i recommend you to read the great resume done in <a href="http://axod.blogspot.com/2010/06/websocket-gets-update-and-it-breaks.html">Axod&#8217;s Hack</a> . </p>
<p>Mainly you need to get 3 keys, 2 of them are send in the headers and the 3rd is sent after the headers. Then you need to do some &#8220;weird&#8221; transformation with the 3 and send them back after the header.</p>
<p>After having the 3 keys, here is the code in erlang to build the challenge to send back to client:</p>
<script src="http://gist.github.com/442019.js"></script>
<p>Now that you have the challenge just build the response like this :</p>
<pre>

Challenge = build_challenge(Key1,Key2,Key3),

HandshakeServer = [
        "HTTP/1.1 101 Web Socket Protocol Handshake\r\n",
	"Upgrade: WebSocket\r\n",
	"Connection: Upgrade\r\n",
	"Sec-WebSocket-Origin: ", Origin , "\r\n",
	"Sec-WebSocket-Location: ws://", Location , "\r\n\r\n",
	Challenge
],
</pre>
<p>As soon i can i will create a new branch on <a href="http://github.com/ostinelli/misultin">misultin web server</a>  so you can see the code working.</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=WebSocket+Handshake+76+in+Erlang&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2010%2F06%2F17%2Fwebsocket-handshake-76-in-erlang%2F&b=Reading %22WebSocket+Handshake+76+in+Erlang%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2010/06/17/websocket-handshake-76-in-erlang/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Erlang lists:keyfind VS proplists:get_value</title>
		<link>http://sergioveiga.com/index.php/2010/05/14/erlang-listskeyfind-vs-proplistsget_value/</link>
		<comments>http://sergioveiga.com/index.php/2010/05/14/erlang-listskeyfind-vs-proplistsget_value/#comments</comments>
		<pubDate>Fri, 14 May 2010 12:06:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=161</guid>
		<description><![CDATA[Other Day @fdmananatold me that he discover that lists key find was much more fast then proplists. Since i use a lot of proplists on my code, i did some tests to check how much fast it is and i was shocked!

(af83@dakua.local)34> timer:tc(proplists,get_value,[99999,List]).
{8685,99999}
(af83@dakua.local)35> timer:tc(lists,keyfind,[99999,1,List]).
{829,{99999,99999}}

WOW! for a list of 100.000 elements proplists:get_value can be 10x slower [...]]]></description>
			<content:encoded><![CDATA[<p>Other Day <a rel="nofollow" target="_blank" href="http://twitter.com/fdmanana">@fdmanana</a>told me that he discover that lists key find was much more fast then proplists. Since i use a lot of proplists on my code, i did some tests to check how much fast it is and i was shocked!</p>
<pre>
(af83@dakua.local)34> timer:tc(proplists,get_value,[99999,List]).
{8685,99999}
(af83@dakua.local)35> timer:tc(lists,keyfind,[99999,1,List]).
{829,{99999,99999}}
</pre>
<p>WOW! for a list of 100.000 elements proplists:get_value can be 10x slower then lists:key_find!</p>
<p>So now i&#8217;m using this encapsulation in order to maintain proplists syntax and avoid extra typing <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>
proplist_get_value(Key,List)->
  case lists:keyfind(Key,1,List) of
    {_K,V}->
      V;
    false->
      undefined
  end.
</pre>
<p>Now the question is Why? why lists is much more faste then proplists? Our guess is that since lists functions are BIF&#8217;s, they must be build in C and proplists no, but this is just a guess, if someone has a better explanation please share.</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+lists%3Akeyfind+VS+proplists%3Aget_value&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2010%2F05%2F14%2Ferlang-listskeyfind-vs-proplistsget_value%2F&b=Reading %22Erlang+lists%3Akeyfind+VS+proplists%3Aget_value%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2010/05/14/erlang-listskeyfind-vs-proplistsget_value/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Context is a bitch&#8230;</title>
		<link>http://sergioveiga.com/index.php/2010/04/19/context-is-a-bitch/</link>
		<comments>http://sergioveiga.com/index.php/2010/04/19/context-is-a-bitch/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 03:54:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=159</guid>
		<description><![CDATA[
&#160;Share now!]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone" src="http://img.skitch.com/20100419-8iifewkdhr15wp2de8q9x71iex.jpg" alt="" width="540" height="190" /><img class="alignnone" src="http://img.skitch.com/20100419-bb9y29jeqgjhj2rhmxc73pf765.jpg" alt="" width="596" height="334" /></p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Context+is+a+bitch%E2%80%A6&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2010%2F04%2F19%2Fcontext-is-a-bitch%2F&b=Reading %22Context+is+a+bitch%E2%80%A6%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2010/04/19/context-is-a-bitch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang Code to UnShort Tiny Url&#8217;s</title>
		<link>http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/</link>
		<comments>http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 04:57:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=150</guid>
		<description><![CDATA[A simple erlang gen_server to return original url from short ones.
It accepts any kind of of url, retrieving zero or one redirect location.
Just copy the code and give it a test :
darkua:~ sergioveiga$ erl
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]
Eshell V5.7.4  (abort with ^G)
1> c(unshort_srv).
{ok,unshort_srv}
2> unshort_srv:start_link().
{ok,}
3> unshort_srv:unshort(&#8221;http://tarpipe.com/kE&#8221;).
{ok,&#8221;http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/&#8221;}
4> unshort_srv:unshort(&#8221;http://google.com&#8221;).
{ok,&#8221;http://www.google.com/&#8221;}
5>
&#160;Share now!]]></description>
			<content:encoded><![CDATA[<p>A simple erlang gen_server to return original url from short ones.</p>
<p>It accepts any kind of of url, retrieving zero or one redirect location.</p>
<script src="http://gist.github.com/310121.js"></script>
<p>Just copy the code and give it a test :</p>
<p>darkua:~ sergioveiga$ erl<br />
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]</p>
<p>Eshell V5.7.4  (abort with ^G)<br />
1> c(unshort_srv).<br />
{ok,unshort_srv}<br />
2> unshort_srv:start_link().<br />
{ok,<0.39.0>}<br />
3> unshort_srv:unshort(&#8221;http://tarpipe.com/kE&#8221;).<br />
{ok,&#8221;http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/&#8221;}<br />
4> unshort_srv:unshort(&#8221;http://google.com&#8221;).<br />
{ok,&#8221;http://www.google.com/&#8221;}<br />
5></p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+Code+to+UnShort+Tiny+Url%E2%80%99s&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2010%2F02%2F21%2Ferlang-code-to-unshort-urls%2F&b=Reading %22Erlang+Code+to+UnShort+Tiny+Url%E2%80%99s%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2010/02/21/erlang-code-to-unshort-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erlang kicks C++ ass</title>
		<link>http://sergioveiga.com/index.php/2009/12/28/erlang-kicks-c-ass/</link>
		<comments>http://sergioveiga.com/index.php/2009/12/28/erlang-kicks-c-ass/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 17:39:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=145</guid>
		<description><![CDATA[I just read a paper from Ericsson about Productivity and Quality, where they compare Erlang and C++, and guess what&#8230; erlang rules with 4 to 10 times less code and less errors!!! You can read the full paper here, but i copy paste some of the conclusions :
&#8220;Comparisons between Ericsson-internal development projects indicate similar line/hour
productivity, [...]]]></description>
			<content:encoded><![CDATA[<p>I just read a paper from Ericsson about Productivity and Quality, where they compare Erlang and C++, and guess what&#8230; erlang rules with 4 to 10 times less code and less errors!!! You can read the full paper <a href="http://www.erlang.se/publications/Ulf_Wiger.pdf">here</a>, but i copy paste some of the conclusions :</p>
<p><em>&#8220;Comparisons between Ericsson-internal development projects indicate similar line/hour<br />
productivity, including all phases of software development, rather independently of which<br />
language (Erlang, PLEX, C, C++ or Java) was used. What differentiates the different<br />
languages then becomes source code volume. </em></p>
<p><em><br />
Some concrete comparisons of source code volume have been made, as applications<br />
written in C++ have been rewritten in Erlang, resulting in a ten-fold reduction in the<br />
number of lines of uncommented source code. Other comparisons have indicated a four-<br />
fold reduction. A reasonable conclusion is that productivity increases by the same factor,<br />
given the same line/hour programmer productivity.<br />
</em></p>
<p><em>When measuring product quality in number of reported errors per 1000 lines of source<br />
code, the same relationship seems to exist: similar error density, but given the difference<br />
in code volume, roughly 4-10 times fewer errors in Erlang-based products.<br />
Furthermore, experiences from maintaining some Erlang-based products in the field<br />
indicates that error corrections usually do not give rise to unwanted side-effects. This is in<br />
line with what one would expect from using a mostly side-effect free declarative<br />
language.<br />
</em></p>
<p><em>These comparisons do not pretend to hold up to scientific scrutiny, but they are collected<br />
from indicators which show a rather consistent pattern. They also seem consistent with<br />
opinions offered by non-Ericsson developers [one2one],[sendmail].<br />
While AXD 301 consists of programs written in C, C++ and Java as well as Erlang, and<br />
each language is used where it fits best, practically all the complex work is done in<br />
Erlang. This is usually decided by the designers themselves – many of our most skilled C<br />
programmers prefer Erlang for complex tasks, and consider it the obvious choice for<br />
anything that involves concurrency or distribution.<br />
</em></p>
<p><em>Finally, we have seen that programmers – even those with no previous exposure to<br />
functional languages – learn Erlang quickly, and become productive within a matter of<br />
weeks.&#8221;</em></p>
<p>I had exactly the same feeling when started to code erlang comparing to my previous most used languages, Java and  PHP.</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+kicks+C%2B%2B+ass&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2009%2F12%2F28%2Ferlang-kicks-c-ass%2F&b=Reading %22Erlang+kicks+C%2B%2B+ass%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2009/12/28/erlang-kicks-c-ass/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Idea 73</title>
		<link>http://sergioveiga.com/index.php/2009/12/17/idea-73/</link>
		<comments>http://sergioveiga.com/index.php/2009/12/17/idea-73/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 18:55:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=143</guid>
		<description><![CDATA[Twiiter Im : the idea is transform twitter social relations, into a Distributed Instant Message Network. In other words, we could build something close to facebook chat system, that works in any website by just inserting a simple js script. So you would be able to see what friends are current online, and engage deeper [...]]]></description>
			<content:encoded><![CDATA[<p>Twiiter Im : the idea is transform twitter social relations, into a Distributed Instant Message Network. In other words, we could build something close to facebook chat system, that works in any website by just inserting a simple js script. So you would be able to see what friends are current online, and engage deeper discussions that are not possible in 140 chars.</p>
<p>So mainly its similar to meebo/mashable integration, but without needing to register in any place, and much more simpler.</p>
<p>The best part of this idea, to me, is that would be a great project to push erlang to the max <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What you think?</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Idea+73&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2009%2F12%2F17%2Fidea-73%2F&b=Reading %22Idea+73%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2009/12/17/idea-73/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Erlang Web Development with Nitrogen</title>
		<link>http://sergioveiga.com/index.php/2009/12/03/erlang-web-development-with-nitrogen/</link>
		<comments>http://sergioveiga.com/index.php/2009/12/03/erlang-web-development-with-nitrogen/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 15:49:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[erlang]]></category>
		<category><![CDATA[nitrogen]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=129</guid>
		<description><![CDATA[I willl be presenting @codebits tomorrow by 11am in stage 1, my Erlang On Nitro talk.
It will be a simple introduction to erlang, and how you can use it for building web applications. With erlang and nitrogen you can very easily start building real-time web applications, using comet, that are fault-tolerant. I will assume that [...]]]></description>
			<content:encoded><![CDATA[<p>I willl be presenting @<a href="http://codebits.eu/">codebits</a> tomorrow by 11am in stage 1, my <a href="http://codebits.eu/intra/s/session/89">Erlang On Nitro</a> talk.</p>
<p>It will be a simple introduction to erlang, and how you can use it for building web applications. With erlang and nitrogen you can very easily start building real-time web applications, using comet, that are fault-tolerant. I will assume that you have never heard of erlang before, so don&#8217;t be afraid to join us.</p>
<p>The talk will follow the <a href="http://sergioveiga.com/index.php/2009/12/02/erlang-on-nitro-erlang-web-development-tutorial-part-13/">tutorial</a> i published some hours ago <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , so i you are attending i suggest a quick read, in order to make the talk more productive!</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+Web+Development+with+Nitrogen&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2009%2F12%2F03%2Ferlang-web-development-with-nitrogen%2F&b=Reading %22Erlang+Web+Development+with+Nitrogen%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2009/12/03/erlang-web-development-with-nitrogen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Erlang On Nitro &#8211; Erlang Web Development Tutorial &#8211; Part 3/3</title>
		<link>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-33/</link>
		<comments>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-33/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 15:32:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[erlang]]></category>
		<category><![CDATA[nitrogen]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=117</guid>
		<description><![CDATA[So now you that know already how to start developing your web projects using erlang, i want to present to you a resume of tools, tips, applications and some erlang resources that will make your life easier.
Tools &#38; Tips
Toolbar : a very simple visual toolbar for the most used tools in erlang. Type on your [...]]]></description>
			<content:encoded><![CDATA[<p>So now you that know already how to start developing your web projects using erlang, i want to present to you a resume of tools, tips, applications and some erlang resources that will make your life easier.</p>
<h2>Tools &amp; Tips</h2>
<p><strong>Toolbar</strong> : a very simple visual toolbar for the most used tools in erlang. Type on your erlang shell toolbar:start(). You should see 4 icons representing this tools:</p>
<ul>
<li><strong>Table Viewer:</strong> An ETS and MNESIA graphical table visualizer. With this you can view and change data inside a ets or mnesia table. On shell you can call it using tv:start().</li>
</ul>
<p><a href="http://img.skitch.com/20091202-nfyejf2hnsuf5qgda916ci74m.jpg"><img class="alignnone" src="http://img.skitch.com/20091202-nfyejf2hnsuf5qgda916ci74m.jpg" alt="" width="505" height="269" /></a></p>
<ul>
<li><strong>Process Manager</strong> : A process manager used to inspect the state of an Erlang system. Call on erlang shell : pman:start(). X11 window will open showing the running processes for this node.</li>
</ul>
<p><a href="http://img.skitch.com/20091203-tahd1bid96sbdk2ajaj8mfgnc5.jpg"><img class="alignnone" src="http://img.skitch.com/20091203-tahd1bid96sbdk2ajaj8mfgnc5.jpg" alt="" width="512" height="282" /></a></p>
<ul>
<li><strong>Debugger</strong> : A debugger for debugging and testing of Erlang programs. Call on erlang shell : debugger:start(). A window will open like this one</li>
</ul>
<p><a href="http://img.skitch.com/20091202-m68ie1tk7etyew2cr3tth6a2fc.jpg"><img class="alignnone" src="http://img.skitch.com/20091202-m68ie1tk7etyew2cr3tth6a2fc.jpg" alt="" width="514" height="403" /></a></p>
<ul>
<li><strong>Application Monito</strong>r : A utility used to supervise Applications executing on several Erlang nodes. Very useful when you start deploying cluster of application in different nodes <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  On shell use appmon:start().</li>
</ul>
<p><a href="http://img.skitch.com/20091202-bw1t96316418qfkhbxpkr1tx58.jpg"><img class="alignnone" src="http://img.skitch.com/20091202-bw1t96316418qfkhbxpkr1tx58.jpg" alt="" width="517" height="564" /></a></p>
<p>Some other useful tips:</p>
<p><strong>Tip1 :</strong> if you have no internet to search, you can use erlang manual. Just type this in your terminal</p>
<pre>erl -man lists</pre>
<p><strong>Tip2</strong> : in order to let an application running in background, all you need is to add this to your start script</p>
<pre>-detached \</pre>
<p><strong>Tip3</strong> : you probably have notice that we are using error_logger module. This is the best way to deal with errors, and for example get warned by email each time your application is in trouble. Please read more <a href="http://www3.erlang.org/documentation/doc-5.4.2.1/lib/kernel-2.10.2/doc/html/error_logger.html">here</a></p>
<h2>Applications</h2>
<p>As you probably noticed i did not talk about any data-store mechanisms, in order to avoid to much detail. In erlang there are many options to store data. Erlang has two system modules ets and dets that are used for efﬁcient storage of large numbers of Erlang terms. <strong>ETS</strong> is short for Erlang term storage,<br />
and <strong>DETS</strong> is short for disk ets. ETS and DETS perform basically the same task: they provide large key-value lookup tables. ETS is memory resident, while DETS is disk resident. You can use ETS or DETS directly or you can use erlang database : <strong>MNESIA</strong>, a distributed DataBase Management System, with a relational/object hybrid data model. Mnesia is really cool because it maps directly to records, and you have a nice query language to it.</p>
<p>Another great way to store info in erlang is using one of the coolest erlang projects: <a href="http://couchdb.apache.org/">couchdb</a> is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript. In other words you don&#8217;t need a schema to your data, and since its json its very easy to write/read. This is very useful for example when you are saving 3rd party data that you don&#8217;t control, like tweets. In order to make the interaction between erlang and couchdb or any other service, before you start coding, look first at github (another great project using erlang), where you can find a lot erlang code, that will make you life even easier.</p>
<h2>Some useful Erlang Resources</h2>
<p>You can find a lot of stuff on the web about erlang, but here are some of our favorite bookmarks about erlang :</p>
<ul>
<li><a href="http://erlang.org/doc/man/">http://erlang.org/doc/man/</a></li>
<li><a href="http://nitrogenproject.com/">http://nitrogenproject.com/</a></li>
<li><a href="http://trapexit.org/">http://trapexit.org/</a></li>
<li><a href="http://www.planeterlang.org/">http://www.planeterlang.org/</a></li>
<li><a href="http://blog.socklabs.com/">http://blog.socklabs.com/</a></li>
<li><a href="http://yarivsblog.com/">http://yarivsblog.com/</a></li>
<li><a href="http://spawnlink.com/">http://spawnlink.com/</a></li>
<li><a href="http://medevyoujane.com/">http://medevyoujane.com/</a></li>
<li><a href="http://metajack.im/">http://metajack.im/</a></li>
<li><a href="http://anders.conbere.org/blog/">http://anders.conbere.org/blog/</a></li>
<li><a href="http://kungfooguru.wordpress.com/">http://kungfooguru.wordpress.com/</a></li>
<li><a href="http://beebole.com/erlang/en/">http://beebole.com/erlang/en/</a></li>
<li><a href="http://erlanganswers.com/web/mcedemo">http://erlanganswers.com/web/mcedemo</a></li>
<li><a href="http://schemecookbook.org/Erlang/AllRecipes">http://schemecookbook.org/Erlang/AllRecipes</a></li>
<li><a href="http://www.undefined.org/c4-1/slides/slides.html">http://www.undefined.org/c4-1/slides/slides.html</a></li>
<li><a href="http://jeremy.marzhillstudios.com/">http://jeremy.marzhillstudios.com/</a></li>
<li><a href="http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong">http://www.infoq.com/presentations/Systems-that-Never-Stop-Joe-Armstrong</a></li>
</ul>
<h2>Resume</h2>
<p>Erlang it has been around for a long time now, but the buzz around erlang started around 2007 with the publication of Programming Erlang: <a href="http://pragprog.com/titles/jaerlang/programming-erlang">Software for a Concurrent World by Joe Armstrong</a>, erlang creator and the use of erlang in really projects, like ejabberd, couchdb or facebook chat system. With this buzz erlang community start to grow outside the Telecom world specially in the web world.</p>
<p>Erlang is not just another programming language,  for me that have been programming more then 5 years with OO, its new paradigm, a new way to think, a new form of coding. And we are deeply in love with it&#8230; we hope you come to.</p>
<p>If you are not yet sold, just watch <a href="http://www.youtube.com/watch?v=uKfKtXYLG78">erlang demo video from the 80&#8217;s</a> and you will for sure <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+On+Nitro+%E2%80%93+Erlang+Web+Development+Tutorial+%E2%80%93+Part+3%2F3&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2009%2F12%2F03%2Ferlang-on-nitro-erlang-web-development-tutorial-part-33%2F&b=Reading %22Erlang+On+Nitro+%E2%80%93+Erlang+Web+Development+Tutorial+%E2%80%93+Part+3%2F3%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-33/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Erlang On Nitro &#8211; Erlang Web Development Tutorial &#8211; Part 2/3</title>
		<link>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-23/</link>
		<comments>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-23/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:14:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sergioveiga.com/?p=106</guid>
		<description><![CDATA[So now that you have already know nitrogen basics in part 1 of this tutorial, lets see what he can real do with it. So lets see a real simple web application that will track a keyword and wait for twitter to push &#8220;tweets&#8221; that contains this keyword, and stream them in a never ending [...]]]></description>
			<content:encoded><![CDATA[<p>So now that you have already know nitrogen basics in part 1 of this tutorial, lets see what he can real do with it. So lets see a real simple web application that will track a keyword and wait for twitter to push &#8220;tweets&#8221; that contains this keyword, and stream them in a never ending stream. So lets grab our code :</p>
<p>Clone this <a href="http://github.com/darkua/ErlanOnNitro_TwitterStream">git repositorium</a> :</p>
<pre>darkua:~ sergioveiga$ git clone git://github.com/darkua/ErlanOnNitro_TwitterStream.git
Initialized empty Git repository in /Users/sergioveiga/ErlanOnNitro_TwitterStream/.git/
remote: Counting objects: 72, done.
remote: Compressing objects: 100% (68/68), done.
remote: Total 72 (delta 4), reused 0 (delta 0)
Receiving objects: 100% (72/72), 144.83 KiB | 182 KiB/s, done.
Resolving deltas: 100% (4/4), done.
darkua:~ sergioveiga$ cd ErlanOnNitro_TwitterStream
darkua:ErlanOnNitro_TwitterStream sergioveiga$ ./start.sh</pre>
<p><strong>NOTE : </strong>in this project we will be use a lib packed with mochiweb project, so please check if already you have mochiweb intalled. (say thanks to <a rel="nofollow" target="_blank" href="http://twitter.com/bpedro">@bpedro</a>, for pointing this out <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<pre>twitter_stream@localhost)4&gt; mochijson2:encode(&lt;&lt;"hello"&gt;&gt;).
[34,&lt;&lt;"hello"&gt;&gt;,34]</pre>
<p>if you don&#8217;t see this, you need to install mochiweb first. Its very easy:</p>
<pre>darkua:twitterstream sergioveiga$ echo $ERL_LIBS
/opt/local/lib/erlang/lib/:/usr/lib/erlang/lib/:/Users/sergioveiga/erlangProjects/tedi
darkua:twitterstream sergioveiga$ cd /opt/local/lib/erlang/lib/
darkua:lib sergioveiga$ sudo svn checkout http://mochiweb.googlecode.com/svn/trunk/ mochiweb-read-only
darkua:lib sergioveiga$ cd mochiweb-read-only/
darkua:mochiweb-read-only sergioveiga$ make</pre>
<p>Now you probably need to kill erlang shell, just hit ctr-c twice. Start it again and now mochijson should already be available.</p>
<p>Before you go and check your browser you need to enter your twitter credentials, needed for twitter stream. So please go to include/include.hrl and add your own credentials, and compile the project.</p>
<p>Make sure you dont any other server running on port 8000, and go to your browser http://localhost:8000/. Here you will find some descriptions and links to both examples we will follow in this part.</p>
<p>Now choose you favorite IDE, we are using textmate, and open the project dir.</p>
<p>So this is ver similar with your previous nitrogen project, with some little changes. Open your project app file inside ebin dir. Here we have added templateroot so we can put all templates inside a different directory.</p>
<p>We have created an include dir, where we will put all our include files, and on src, we divide the pages, from the libs, that will hold &#8220;hard-core&#8221; code.</p>
<h2>Example 1 &#8211; Twitter Stream</h2>
<p>A screenshot of how twitter stream looks like :</p>
<p><a href="http://img.skitch.com/20091203-xe8bgq557gykk1yc48gtcnbye8.jpg"><img class="alignnone" src="http://img.skitch.com/20091203-xe8bgq557gykk1yc48gtcnbye8.jpg" alt="" width="505" height="447" /></a></p>
<p>Now open /src/pages/web_index.erl. You can see that we almost don&#8217;t do nothing here, because this is a static file, so we are only are adding the page title, and saying witch template will be used to render the page. All the code you can see its on index.html template file.</p>
<p>Now open web_stream page.</p>
<p>Lets check body function</p>
<pre>body() -&gt;

 %%builds the stream
 Stream = start_stream(),

 %% the html to render
 Body= [
 #panel{class="header", body=[
 #h1{text="Erlang on Nitro - Twitter Stream"},
 #panel{id=feedback,class="feedback", body=[
 "Calling Twitter...pls wait..."
 ]},
 #panel{id=control,body=[#button{text="Stop", postback={stop,Stream}}]}
 ]},
 #panel{id=stream,body=[]}
 ],

 wf:render(Body).</pre>
<p>Here we are calling stream_start() to open stream connections and building the page html structure. Now check the start_stream() to see where is the magic.</p>
<pre>start_stream()-&gt;
 Pid = wf:comet(fun()-&gt; ?MODULE:loop() end),</pre>
<pre>%%check for track
 case wf:get_path_info() of
 []-&gt;
 twitter_stream:sample(Pid);
 Track-&gt;
 twitter_stream:track(Track,Pid)
 end.</pre>
<p>When calling wf:comet, we are building a comet connection to this page, and passing what function will be used to &#8220;comunicate&#8221; with the browser. Then we use wf:get_path_info() to get extra info on path, that we will use to call twitter, for example the twitter or hello keyword from the examples. All the connection to twitter stream api happens inside twitter_stream, and for now you can look at it as a black box that streams tweets for you, later you can check it out and try to understand what is happening.</p>
<p>Now before checking loop function, its time to better undersand one of erlang top features, creating and communicating with processes. When we did wf:comet, what is happening in resume, is that we have spawned loop function into a new process, and now we can comunicate with it by sending to the Process Id messages. And to do that we just need to do this :</p>
<pre>Pid ! message</pre>
<p>In order to put a process waiting for messages is also very simple, just do this :</p>
<pre>receive
 Message-&gt;
 ...
 end.</pre>
<p>When creating a receive block, you are telling erlang to wait there until he receives a new message, that he will try to match to execute the respective code.</p>
<p>Now lets check a very simple example in order to better understand this. Open file spawn_example inside libs. You can see that we just have 2 functions, start and loop. On start we are spawning function loop, and registering the process with a name to be easier to call them after, like your fathers did with you <img src='http://sergioveiga.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now go to erlang shell and call this:</p>
<pre>(twitter_stream@localhost)2&gt; spawn_example:start().
true
(twitter_stream@localhost)3&gt; bot ! hello.
Hello. How are you?
hello
(twitter_stream@localhost)4&gt;</pre>
<p>Very simple and cool, but now try to call it again</p>
<pre>(twitter_stream@localhost)15&gt; bot ! hello.
** exception error: bad argument
 in operator  !/2
 called as bot ! hello
(twitter_stream@localhost)16&gt;</pre>
<p>Humm&#8230; the reason it failed its very simple. After the process received the first message he executed the code matched to hello and it ended. So when you try to send a new message to it, it no longer exists, and it fails. So if you want to create process that after processing a message continues waiting for other you need to recall the function. So in the end of the loop add a call to loop.</p>
<pre>loop()-&gt;
 receive
 hello -&gt;
 io:format("Hello. How are you?~n",[]);
 _-&gt;
 void
 end,
 loop().</pre>
<p>Now lets try again</p>
<pre>(twitter_stream@localhost)16&gt; sync:go().
Recompile: ./src/libs/spawn_example
ok
(twitter_stream@localhost)17&gt; spawn_example:start().
true
(twitter_stream@localhost)18&gt; bot ! hello.
Hello. How are you?
hello
(twitter_stream@localhost)19&gt; bot ! hello.
Hello. How are you?
hello</pre>
<p>As you can see now the process no longer dies. Now lets see another great feature of erlang: hot code swapping, the ability to change the code without stopping the system. Try to change the text on the message, for example to:</p>
<pre>io:format("Hot swapping rocks!~n",[])</pre>
<p>sync:go and lets see what happens:</p>
<pre>(twitter_stream@localhost)24&gt; sync:go().
Recompile: ./src/libs/spawn_example
ok
(twitter_stream@localhost)25&gt; bot ! hello.
Hello. How are you?
hello</pre>
<p>Humm&#8230; the old message is still there. The reason this happens is very simple. If we dont call &#8220;externally&#8221; by  prefixing the module name we are saying to erlang to “use this version of this method” and not the current version. So all we need to do is add the ?MODULE to the loop call, in the start function and also in the end of the loop. Now sync your code, and start your bot again.</p>
<pre>(twitter_stream@localhost)38&gt; sync:go().
Recompile: ./src/libs/spawn_example
ok
(twitter_stream@localhost)39&gt; spawn_example:start().
true
(twitter_stream@localhost)40&gt; bot ! hello.
Hot swapping rocks!
hello</pre>
<p>Now lets change the message again, to &#8220;Hot swapping really rocks&#8221;. Sync your code again and send him a message.</p>
<pre>(twitter_stream@localhost)41&gt; sync:go().
Recompile: ./src/libs/spawn_example
ok
(twitter_stream@localhost)42&gt; bot ! hello.
Hot swapping rocks!
hello
(twitter_stream@localhost)43&gt; bot ! hello.
Hot swapping really rocks!
hello</pre>
<p>As you can see the first message the bot receives the old code will be executed, because the process was already blocked waiting for a message, but when it run again it will already be using the current version of the code. You can see final version of spawn_example <a href="http://gist.github.com/raw/247001/c912f04cc9a4faedfda62cf8043d1ede23951e7c/spawn_example">here</a>.</p>
<p>Now back to our example, you can see exactly this happening with the loop function inside web_stream module. As you can see the loop function will be waiting for a subset of messages that twitter stream will send to him, and according to each we will be doing something different. Now what is important to understand is how nitrogen communicates with the client browser.</p>
<p>We are using 2 nitrogen functions  wf:update(id, content) and wf:insert_top(id, content) that will update and insert on the top of a DOM element. Nitrogen will translate this to the corresponding javascript, using jquery lib, and send it to the browser when we call wf:comet_flush(). So only when call this function inside a comet loop, we will be sending all previous javascript code built with wf:update/wf:insert_top&#8221; as a response to the comet connection.</p>
<pre>loop()-&gt;
 receive
 {unauthorized,Message}-&gt;
 io:format("~p~n",[Message]),
 wf:update(feedback,"Your twitter credentials are wrong, check include.htr file!");
 {start,_Message}-&gt;
 wf:update(feedback,"Stream Running...");
 {stream,Message}-&gt;
 get_tweet_info(Message);
 {stream_end,_Message}-&gt;
 restart_button(),
 wf:update(feedback,"Stream Ended...");
 {stop,_Reason}-&gt;
 restart_button(),
 wf:update(feedback,"Stream Stoped...");
 {error,Reason}-&gt;
 error_logger:error_msg("Error : ~p~n",[Reason]),
 restart_button(),
 wf:update(feedback,#panel{class="error",body=wf:f("Error : ~s !",[Reason])});
 Any-&gt;
 error_logger:info_msg("ANY : ~p~n",[Any])
 after 55000 -&gt;
 wf:update(feedback,"to quiet for me...")
 end,
 wf:comet_flush(),
 ?MODULE:loop().</pre>
<p>With this simple code you have learn the basic blocks to create parallel computing, and the possibility to push content to users without the need to be constantly polling a service. And this is really cool because is all you need to create cool real-time / multi-user applications.</p>
<h2>Example 2 &#8211; Twitter Cloud</h2>
<p>Twitter Cloud Screenshot :</p>
<p><a href="http://img.skitch.com/20091203-rbk3krubtky9pey747chxe85b4.jpg"><img class="alignnone" src="http://img.skitch.com/20091203-rbk3krubtky9pey747chxe85b4.jpg" alt="" width="505" height="387" /></a></p>
<p>Nitrogen does already lot of work for us on erlang/javascript interaction, making easier  the creation of appealing  and rich web applications. Check web_cloud example where we have created another visualization for twitter stream, but now its a cloud of twitter users, where the size of the pictures is related to the ratio following/followers, where you can click to see the status update.</p>
<p>if you open web_cloud.erl, you can see that its very closed to web_stream, but now instead of building the html on the server we are passing the info to the the browser and will will build the dom with javascript. This can be achieved very easily with nitrogen using wf:wire constructor. As you can check on line 126 of web_cloud</p>
<pre>wf:wire(wf:f("buildTweet({id:'~s',screen_name:'~s',picture:'~s',text:\"~s\",size:'~p'})",
[Tweet#tweet.id,
Tweet#tweet.screen_name,
Tweet#tweet.picture,
wf_utils:js_escape(Tweet#tweet.text),
Tweet#tweet.size])
).</pre>
<p>Mainly we are calling the js function buildTweet that you can find on /js/main.js a js object with all the tweet function. We also use another great nitrogen function wf:f, that helps you build complex strings.</p>
<p>Another thing really useful is giving to an event different actions, like you can see in line 27.</p>
<pre>#panel{id=control,body=[#button{text="Stop", actions=#event{actions="$.growl('','Stream is Stoping...');"}, postback={stop,Stream}}]}</pre>
<p>Inside each event you can define your postback, and you can also use actions parameters to execute javascript. So if you click on the stop button, we will be calling event({stop,Stream}) and also calling jquery-growl plugin that will show a message to the user.  We can even define more than one event type to the same element. For example change control panel this on body function</p>
<pre>#panel{id=control,body=[#button{text="Stop", actions=[</pre>
<pre>#event{actions="$.growl('','Stream is Stoping...');", postback={stop,Stream}},</pre>
<pre>#event{type=mouseover,actions="$.growl('','Click if you are a mouse!...');"}]
}]}</pre>
<p>sync:go, and check your example. You should be seeing a message appear when you put your mouse over stop button and other when you click it.<br />
As you can imagine this is a very simple example of all you can do with nitrogen . So please check nitrogen project where will have a lot of <a href="http://nitrogenproject.com/web/samples">cool examples</a> ,  <a href="http://nitrogenproject.com/web/reference/api">nitrogen api</a> with all functions available, and you can check some more documentation on on <a href="http://wiki.github.com/rklophaus/nitrogen/installing-nitrogen">github wiki</a>.</p>
<p>So now you know already enough to start coding your own ideas and projects, but before read <a href="http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-33/">last part </a>of this tutorial, where we will resume some of the tools erlang has to help on your adventure.</p>
<p style="white-space:nowrap"><img style="border:0px" src="http://tarpipe.com/img/tarpipe.png" />&nbsp;<a target="_blank" href="http://tarpipe.com/share/?t=Erlang+On+Nitro+%E2%80%93+Erlang+Web+Development+Tutorial+%E2%80%93+Part+2%2F3&u=http%3A%2F%2Fsergioveiga.com%2Findex.php%2F2009%2F12%2F03%2Ferlang-on-nitro-erlang-web-development-tutorial-part-23%2F&b=Reading %22Erlang+On+Nitro+%E2%80%93+Erlang+Web+Development+Tutorial+%E2%80%93+Part+2%2F3%22">Share now!</a></p>]]></content:encoded>
			<wfw:commentRss>http://sergioveiga.com/index.php/2009/12/03/erlang-on-nitro-erlang-web-development-tutorial-part-23/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
