<?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>def Tenako.blog () end</title>
	<atom:link href="http://blog.tenako.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tenako.com</link>
	<description></description>
	<lastBuildDate>Sun, 10 Jul 2011 10:15:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>vim: ./configure and it&#8217;s fucking cache</title>
		<link>http://blog.tenako.com/2011/07/07/vim-configure-and-its-fucking-cache/</link>
		<comments>http://blog.tenako.com/2011/07/07/vim-configure-and-its-fucking-cache/#comments</comments>
		<pubDate>Thu, 07 Jul 2011 12:51:07 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[tweaks]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=376</guid>
		<description><![CDATA[If while configuring vim&#8216;s Makefile you have any problem with missing dependencies I give you and advice: After installing those dependencies, delete $VIM_SOURCE/src/config.cache or there&#8217;ll be variables set on that file that&#8217;ll fool ./configure into thinking that those dependencies are still missing. Fuck yeah!!]]></description>
			<content:encoded><![CDATA[<p>If while configuring <a href="http://www.vim.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.vim.org');">vim</a>&#8216;s Makefile you have any problem with missing dependencies I give you and advice:</p>
<p><strong>After installing those dependencies, delete $VIM_SOURCE/src/config.cache or there&#8217;ll be variables set on that file that&#8217;ll fool ./configure into thinking that those dependencies are still missing.</strong></p>
<p>Fuck yeah!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2011/07/07/vim-configure-and-its-fucking-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mac: Install MacVim</title>
		<link>http://blog.tenako.com/2011/07/06/mac-install-macvim/</link>
		<comments>http://blog.tenako.com/2011/07/06/mac-install-macvim/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 16:38:59 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[tweaks]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=367</guid>
		<description><![CDATA[Today, trying to compile MacVim I ran into a problem with some shared libraries: ... Undefined symbols: &#34;_iconv_close&#34;, referenced from: _buf_write in fileio.o _readfile in fileio.o _readfile in fileio.o ... The problem has to do with lib search path. I don&#8217;t know yet why isn&#8217;t used the system path (under /usr/lib) rather than the one used [...]]]></description>
			<content:encoded><![CDATA[<p>Today, trying to compile <a href="https://github.com/b4winckler/macvim" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">MacVim</a> I ran into a problem with some shared libraries:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
Undefined symbols:
  <span style="color: #ff0000;">&quot;_iconv_close&quot;</span>, referenced from:
      _buf_write <span style="color: #000000; font-weight: bold;">in</span> fileio.o
      _readfile <span style="color: #000000; font-weight: bold;">in</span> fileio.o
      _readfile <span style="color: #000000; font-weight: bold;">in</span> fileio.o
...</pre></div></div>

<p>The problem has to do with lib search path. I don&#8217;t know yet why isn&#8217;t used the system path (under /usr/lib) rather than the one used by macports.</p>
<p>Well, the thing is that the libiconv2.dylib under /opt/local/lib doesn&#8217;t have the _iconv_close function (among others):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>madtrick <span style="color: #7a0874; font-weight: bold;">&#123;</span> lib <span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>madtrick <span style="color: #7a0874; font-weight: bold;">&#123;</span> lib <span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #c20cb9; font-weight: bold;">nm</span> libiconv.2.dylib <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;iconv_close&quot;</span>
000163f0 T _libiconv_close</pre></div></div>

<p>While libiconv.2.dylib on /usr/lib does:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>madtrick <span style="color: #7a0874; font-weight: bold;">&#123;</span> lib <span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">pwd</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>madtrick <span style="color: #7a0874; font-weight: bold;">&#123;</span> lib <span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #c20cb9; font-weight: bold;">nm</span> libiconv.2.dylib <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;iconv_close&quot;</span>
0000b905 T _iconv_close
0000fcce T _libiconv_close</pre></div></div>

<p>So to fix this problem you have several choices:</p>
<ul>
<li> Deactivate libiconv on macports (and all its dependencies)</li>
<li>Prepend a lib path</li>
</ul>
<p>I went for the second one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LDFLAGS</span>=<span style="color: #ff0000;">&quot;-L/usr/lib&quot;</span> .<span style="color: #000000; font-weight: bold;">/</span>configure _your_options_here_</pre></div></div>

<p>There you go : )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2011/07/06/mac-install-macvim/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>git: bash-completion</title>
		<link>http://blog.tenako.com/2011/07/04/git-bash-completion/</link>
		<comments>http://blog.tenako.com/2011/07/04/git-bash-completion/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 17:10:42 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[tweaks]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=350</guid>
		<description><![CDATA[Looking for a way to easyly know if there&#8217;s something changed on my git repos I found out that git itself ships a bash script that perfectly satisfy my needs. Introducing: __git_ps1 Usage: Include a call to __git_ps1 in your promt string (for example in bash): PS1='[\u@\h \W$(__git_ps1 &#34; (%s)&#34;)]\$ ' This will show the [...]]]></description>
			<content:encoded><![CDATA[<p>Looking for a way to easyly know if there&#8217;s something changed on my git repos I found out that git itself ships a bash script that perfectly satisfy my needs.</p>
<p>Introducing: <strong>__git_ps1</strong></p>
<p><strong>Usage:</strong></p>
<p>Include a call to __git_ps1 in your promt string (for example in bash):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PS1</span>=<span style="color: #ff0000;">'[\u@\h \W$(__git_ps1 &quot; (%s)&quot;)]\$ '</span></pre></div></div>

<p>This will show the current branch on your prompt.</p>
<p><strong>Customization:</strong></p>
<p>__git_ps1 allows to customize its output using environment variables. Here is a list of avaliabl<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace;"><span style="line-height: 18px; white-space: pre;">e options:</span></span></p>
<ul>
<li>GIT_PS1_SHOWDIRTYSTATE.  When set to something not empty, __git_ps1 will display unstaged (*) and staged (+) next to the branch name.</li>
<li>GIT_PS1_SHOWSTASHSTATE.  When set to something no empty, __git_ps1 will display $ next to the branch name when something is staged.</li>
<li>GIT_PS1_SHOWUNTRACKEDFILES.  When set to something no empty, __git_ps1 will display % next to the branch name when there&#8217;re untracked files.</li>
<li>GIT_PS1_SHOWUPSTREAM.  This cat take several (comma separated) values: auto, verbose, legacy, git and svn. __git_ps1 will show the difference between HEAD and its upstream.</li>
</ul>
<p>Export them if your shell dotfile before calling __git_ps1.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2011/07/04/git-bash-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mac: tabswitching in Visor</title>
		<link>http://blog.tenako.com/2011/07/04/mac-tabswitching-in-visor/</link>
		<comments>http://blog.tenako.com/2011/07/04/mac-tabswitching-in-visor/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 16:44:16 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[tweaks]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=345</guid>
		<description><![CDATA[I tryed Visor, a quake-like terminal for Mac OS, in the past but left it because there wasn&#8217;t an easy way to switch between tabs. Until now&#8230; Today I found TerminalTabSwitching. A plugin to enable cmd + &#60;tab_number&#62; switching on Terminal.app. I&#8217;m a bit happier : )]]></description>
			<content:encoded><![CDATA[<p>I tryed <a title="visor homepage" href="http://visor.binaryage.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/visor.binaryage.com');">Visor</a>, a <em>quake-like</em> terminal for Mac OS, in the past but left it because there wasn&#8217;t an easy way to switch between tabs.</p>
<p>Until now&#8230;</p>
<p>Today I found <a title="terminaltabswitching on github" href="https://github.com/dabeeeenster/TerminalTabSwitching" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">TerminalTabSwitching</a>. A plugin to enable cmd + &lt;tab_number&gt; switching on Terminal.app.</p>
<p>I&#8217;m a bit happier : )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2011/07/04/mac-tabswitching-in-visor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jetty: Shit happens!!</title>
		<link>http://blog.tenako.com/2011/04/09/jetty-shit-happens/</link>
		<comments>http://blog.tenako.com/2011/04/09/jetty-shit-happens/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 12:11:47 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[shit]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=277</guid>
		<description><![CDATA[For the impatient readers: Don&#8217;t set Jetty&#8217;s &#60;stopPort&#62; to the same &#60;port&#62; where Jetty is running or you might run into some nasty-hard-to-debug problem. Now a full explanation: Imagine the following scenario, Here we have to web services, A and B, both running on the same machine on Jetty webserver and one of them is listening [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_localhost2.png" ></a>For the impatient readers:</p>
<p><strong>Don&#8217;t set Jetty&#8217;s &lt;stopPort&gt; to the same &lt;port&gt; where Jetty is running or you might run into some nasty-hard-to-debug problem.</strong></p>
<p><strong><span id="more-277"></span><br />
</strong></p>
<p>Now a full explanation:</p>
<p>Imagine the following scenario,</p>
<p><a href="http://blog.tenako.com/wp-content/uploads/2011/04/scenary2.png" ><img class="aligncenter size-full wp-image-311" title="scenary" src="http://blog.tenako.com/wp-content/uploads/2011/04/scenary2.png" alt="" width="500" height="175" /></a></p>
<p>Here we have to web services, A and B, both running on the same machine on <em>Jetty </em>webserver and one of them is listening for petitions on port 9090 (configured via de maven-jetty-plugin). Web service A has to request some data to B and process its reply. Nothing unusual.</p>
<p>So A issue a request to <strong>http://localhost:9090/&lt;path&gt; </strong>expecting an XML response as a result of doing it. But it gets nothing, <em>nada, nichts.</em></p>
<p><em><span style="font-style: normal;"><a href="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_localhost2.png" ><img class="aligncenter size-full wp-image-312" style="display: block; margin-left: auto; margin-right: auto; border: 0px initial initial;" title="empty_response_localhost" src="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_localhost2.png" alt="" width="500" height="175" /></a></span> </em></p>
<div><em><br />
</em></div>
<p>Well, at this moment the first thing that came through my mind was that I did something wrong while coding or configurating any of the web services. So I checked everything, but it seemed right. My next move was to create a fake request with <em>curl </em>just to see what happened.</p>
<p>What happened misleaded me even more: web service B was responding. WTF!!</p>
<p><a href="http://blog.tenako.com/wp-content/uploads/2011/04/response_with_curl3.png" ><img class="aligncenter size-full wp-image-316" title="response_with_curl" src="http://blog.tenako.com/wp-content/uploads/2011/04/response_with_curl3.png" alt="" width="500" height="189" /></a></p>
<p>So I went one level down. I ran <em>tcpdump. </em>And what I got? I discovered that the main difference between the requests issued by web service A and <em>curl</em> was the ip version they used: web service A was using ipv4 and <em>curl</em> ipv6.</p>
<p>To force both requests (from the web service and curl) to use ipv4, I run <em>curl</em> against the web service B but now instead of <em>localhost </em>I used 127.0.0.1. And the response was empty, just like if the request came from web service A.</p>
<p><a href="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_curl_127001.png" ></a><a href="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_curl_1270011.png" ><img class="aligncenter size-full wp-image-317" title="empty_response_curl_127001" src="http://blog.tenako.com/wp-content/uploads/2011/04/empty_response_curl_1270011.png" alt="" width="500" height="189" /></a><br />
So I thought that all of my troubles had to do with the ip stack beeing used. And I wasted some hours<br />
trying to figure out what was wrong with it.<br />
As I was really desperate with all this, I download Jetty sources to debug it on eclipse. I wanted to know<br />
what was happening with my requests. And here was were light came to me by chance. While debugging Jetty,<br />
an incomming connection from  internet arraived to my &lt;public_ip&gt;:9090  (I guess it was someone doing some kind of portscanning) and got stuck on my breakpoints&#8230;</p>
<p>Mmmm, wait a moment&#8230;</p>
<div><a href="http://blog.tenako.com/wp-content/uploads/2011/04/suspicious-template.jpg" ><img class="aligncenter size-full wp-image-299" title="suspicious-template" src="http://blog.tenako.com/wp-content/uploads/2011/04/suspicious-template.jpg" alt="" width="273" height="233" /></a></div>
<p>Yep, internet addresses are ipv4 only (for most of us), so this ruled out any kind of problem with the ipv4 stack or shit. Now I began to see the light. This was some mess with the adresses.</p>
<p>Just to check I did an alias in my loopback interface to 127.0.0.2 and run again the request with <em>curl </em>to that ip<em>. </em>This time being successful. Ooook.</p>
<p>So, whats wrong with 127.0.0.1:9090?</p>
<p>Netstat output,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">13</span>:<span style="color: #000000;">29</span>:<span style="color: #000000;">46</span> ~ $ <span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-f</span> inet <span style="color: #660033;">-an</span>
Active Internet connections <span style="color: #7a0874; font-weight: bold;">&#40;</span>including servers<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Proto Recv-Q Send-Q  Local Address          Foreign Address        <span style="color: #7a0874; font-weight: bold;">&#40;</span>state<span style="color: #7a0874; font-weight: bold;">&#41;</span>
tcp4       <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>  127.0.0.1.9090         <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span>                    LISTEN
tcp46      <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">*</span>.9090                 <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span>                    LISTEN
...</pre></div></div>

<p>Lsof output,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">13</span>:<span style="color: #000000;">49</span>:<span style="color: #000000;">39</span> ~ $ lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">9090</span>
COMMAND PID     USER   FD   TYPE     DEVICE SIZE<span style="color: #000000; font-weight: bold;">/</span>OFF NODE NAME
java    <span style="color: #000000;">239</span> madtrick   94u  IPv6 0x08c10f80      0t0  TCP <span style="color: #000000; font-weight: bold;">*</span>:websm <span style="color: #7a0874; font-weight: bold;">&#40;</span>LISTEN<span style="color: #7a0874; font-weight: bold;">&#41;</span>
java    <span style="color: #000000;">239</span> madtrick   95u  IPv6 0x08c11460      0t0  TCP <span style="color: #7a0874; font-weight: bold;">&#91;</span>::127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>:websm <span style="color: #7a0874; font-weight: bold;">&#40;</span>LISTEN<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>I have two sockets listening on port 9090 and both belong to the same process (as reported by lsof), my Jetty Server.  But requests to 127.0.0.1:9090 are lost meanwhile requests to &lt;any_other_ip&gt;:9090 are processed by the server.</p>
<p>Lets try something, lets change the &lt;stopPort&gt; to 9091 and see what happens&#8230;<br />
Request from web service A, OK.<br />
Request from <em>curl, </em>OK.</p>
<p>Run netstat again,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">13</span>:<span style="color: #000000;">59</span>:<span style="color: #000000;">50</span> ~ $ <span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-f</span> inet <span style="color: #660033;">-an</span>
Active Internet connections <span style="color: #7a0874; font-weight: bold;">&#40;</span>including servers<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Proto Recv-Q Send-Q  Local Address          Foreign Address        <span style="color: #7a0874; font-weight: bold;">&#40;</span>state<span style="color: #7a0874; font-weight: bold;">&#41;</span>
tcp4       <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>  127.0.0.1.9091         <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span>                    LISTEN
tcp46      <span style="color: #000000;">0</span>      <span style="color: #000000;">0</span>  <span style="color: #000000; font-weight: bold;">*</span>.9090                 <span style="color: #000000; font-weight: bold;">*</span>.<span style="color: #000000; font-weight: bold;">*</span>                    LISTEN
...</pre></div></div>

<p>And lsof for ports 9090 and 9091,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">14</span>:00:<span style="color: #000000;">48</span> ~ $ lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">9090</span>
COMMAND PID     USER   FD   TYPE     DEVICE SIZE<span style="color: #000000; font-weight: bold;">/</span>OFF NODE NAME
java    <span style="color: #000000;">301</span> madtrick   93u  IPv6 0x08c10f80      0t0  TCP <span style="color: #000000; font-weight: bold;">*</span>:websm <span style="color: #7a0874; font-weight: bold;">&#40;</span>LISTEN<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">14</span>:00:<span style="color: #000000;">55</span> ~ $ lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">9091</span>
COMMAND PID     USER   FD   TYPE     DEVICE SIZE<span style="color: #000000; font-weight: bold;">/</span>OFF NODE NAME
java    <span style="color: #000000;">301</span> madtrick   94u  IPv6 0x08c11460      0t0  TCP <span style="color: #7a0874; font-weight: bold;">&#91;</span>::127.0.0.1<span style="color: #7a0874; font-weight: bold;">&#93;</span>:xmltec-xmlmail <span style="color: #7a0874; font-weight: bold;">&#40;</span>LISTEN<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>So you see, Jetty opens another socket which listens on 127.0.0.1:&lt;stopPort&gt;  (lets call it jetty stop daemon) and being that an explicit address it has precedence over the catch all 0.0.0.0:9090 (where Jetty is listening). That&#8217;s why my requests to 127.0.0.1:9090 returned nothing.</p>
<p>This is what was happening before,</p>
<div><a href="http://blog.tenako.com/wp-content/uploads/2011/04/scenary_daemon_bad1.png" ><img class="aligncenter size-full wp-image-313" title="scenary_daemon_bad" src="http://blog.tenako.com/wp-content/uploads/2011/04/scenary_daemon_bad1.png" alt="" width="500" height="215" /></a></div>
<p>And this is whats happens now,</p>
<div><a href="http://blog.tenako.com/wp-content/uploads/2011/04/scenary_daemon_well1.png" ><img class="aligncenter size-full wp-image-339" title="scenary_daemon_well" src="http://blog.tenako.com/wp-content/uploads/2011/04/scenary_daemon_well1.png" alt="" width="500" height="215" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2011/04/09/jetty-shit-happens/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>erlang: mochiweb + BOSH</title>
		<link>http://blog.tenako.com/2010/08/11/erlang-mochiweb-bosh/</link>
		<comments>http://blog.tenako.com/2010/08/11/erlang-mochiweb-bosh/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 19:49:09 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[erlang]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=215</guid>
		<description><![CDATA[I&#8217;ve been playing with mochiweb for a while and I found it a nice way to improve my Erlang knowledge. For making things more interesting I want to use mochiweb to implement a BOSH manager. If you are not tempted to read the spec documentation about BOSH I can give you this excerpt: BOSH, the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with <a title="mochiweb at github" href="http://github.com/mochi/mochiweb" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');" target="_blank">mochiweb</a> for a while and I found it a nice way to improve my <em>Erlang</em> knowledge. For making things more interesting I want to use mochiweb to implement a <a title="BOSH spect" href="http://xmpp.org/extensions/xep-0124.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/xmpp.org');">BOSH</a> manager. If you are not tempted to read the spec documentation about <em>BOSH </em>I can give you this excerpt:</p>
<blockquote><p>BOSH, the technology defined in this specification, essentially provides  a &#8220;drop-in&#8221; alternative to a long-lived, bidirectional TCP connection &#8230;</p>
<p>For applications that require both &#8220;push&#8221; and &#8220;pull&#8221; semantics, BOSH is  significantly more bandwidth-efficient and responsive than most other  bidirectional HTTP-based transport protocols and the techniques now  commonly known as &#8220;Ajax&#8221;&#8230;</p></blockquote>
<p>That is, BOSH is quite similar to <a title="WebSockets spec" href="http://dev.w3.org/html5/websockets/" onclick="javascript:pageTracker._trackPageview('/outbound/article/dev.w3.org');">WebSockets</a></p>
<p>So, at this point is where mochiweb comes in. It will provide the framework for handling the HTTP requests where the BOSH requests themselves are wrapped. But before going any further lets explain how mochiweb works, with a picture:</p>
<p><a href="http://blog.tenako.com/wp-content/uploads/2010/08/mochiweb_400W3.png" ><img class="aligncenter size-full wp-image-228" title="mochiweb_400W" src="http://blog.tenako.com/wp-content/uploads/2010/08/mochiweb_400W3.png" alt="" width="400" height="333" /></a></p>
<p>What do we have here?</p>
<ol>
<li>An HTTP request comes in, to the address and port <em>mochiweb </em>is configured.</li>
<li>If it&#8217;s a valid HTTP request, a mochiweb_request &#8220;object&#8221; is created and the handler function at the callback module (which is provided when mochiweb starts) is invoked with this <em>mochiweb_request </em>as a parameter. Give a look to <a title="parameterized erlang modules" href="http://userprimary.net/posts/2009/03/04/two-erlang-finds-atomic-names-and-parameterized-modules/" onclick="javascript:pageTracker._trackPageview('/outbound/article/userprimary.net');">this</a> and <a title="parameterized erlang modules proposal" href="http://www.google.es/url?sa=t&amp;source=web&amp;cd=2&amp;ved=0CBwQFjAB&amp;url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.58.79%26rep%3Drep1%26type%3Dpdf&amp;ei=FPdiTNDiAYXl4Ab59LS2Cg&amp;usg=AFQjCNF1B71sV5kf_cGAZx7f8eNm9w5XlQ&amp;sig2=lEngi35jymjdZ0TxxCDUbQ" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.google.es');">this</a> to get a grasp at parameterized modules if you wish to know more about &#8220;objects&#8221; on <em>Erlang</em>.</li>
</ol>
<p>Easy, huh?</p>
<p>And what is all that about a BOSH manager? The BOSH manager handles the connection between the resource-client (for example a browser) and the resource-owner (for example a server). It has to keep HTTP connections opened to fake this bidirectional comunication. That is, the client ask for something about the resource and so it sends a request to the BOSH manager, the BOSH manager sends this same request to the server and waits for a reply. If a reply arrives, then it&#8217;s forwarded to the client. But aside from this, which is no more than plain-old AJAX, BOSH offers PUSH technologies. If any event happens at the server and the client has to be notified, the BOSH manager forwards the event to the client. That&#8217;s why it has to keep HTTP connections opened, it must have a valid path.</p>
<p>In <em>Erlang, </em>creating and destroying processes is extremely cheap, so what I wanted was  to spawn a new process for each single BOSH session (between one client and one or multiple servers). Lets give another picture:</p>
<p><a href="http://blog.tenako.com/wp-content/uploads/2010/08/bosh_manager_500.png" ><img class="aligncenter size-full wp-image-234" title="bosh_manager_500" src="http://blog.tenako.com/wp-content/uploads/2010/08/bosh_manager_500.png" alt="" width="500" height="241" /></a></p>
<p>On the picture above, there are two separate BOSH managers (each of them is a <em>Erlang</em> process) BM1 and BM2 which handler connections from one client to one server (BM1 ) and from another different client to two servers (BM2)</p>
<p>To complete the setup I used, I have to talk about <a title="strophejs home page" href="http://code.stanziq.com/strophe/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.stanziq.com');">StropheJS</a> which is a library for writing xmpp clients (BOSH is an xmpp extension).</p>
<p>Well, once I have explained more or less what I&#8217;m doing with mochiweb and BOSH, lets got to the details.</p>
<p>First, lets talk about my callback module for mochiweb. It&#8217;s not a ver big one nor a complicated one, not because I don&#8217;t know how to move on but was the error I&#8217;ll talk later which didn&#8217;t allow me to progress. So ladys and gentleman here is my litle callback module:</p>
<pre class="brush: erlang;">

-module(mochibosh).

-export([start/0, start/1, stop/0]).
-export([handler/1]).

-export([init/0]).

-record(mochibosh_state,{procs, xml_models}).

handler(Req) -&gt;
 io:format(&quot;CALLBACK. Petition on port ~p  ~n&quot;, [inet:port(Req:get(socket))]),
 mochibosh ! Req,
 ok.

start() -&gt;
 erlang:register(mochibosh, spawn_link(?MODULE, init, [])),
 start([{ip,&quot;192.168.1.110&quot;}, {port, 8888}]).

start(Options) -&gt;
 Options2 = [{loop, {?MODULE, handler}} | Options],
 mochiweb_http:start(Options2).

stop() -&gt;
 mochibosh ! exit,
 mochiweb_http:stop().

% Internal API

init() -&gt;
 Models = init_xml_models(),
 loop(#mochibosh_state{procs = dict:new(), xml_models = Models}).

loop(State = #mochibosh_state{procs = Procs, xml_models = Models}) -&gt;
 receive
 Request -&gt;
 io:format(&quot;SPAWNED PROCESS. Request received on port ~p ~n&quot;, [inet:port(Request:get(socket))]),
 loop(State)
 end.

init_xml_models()-&gt;
 [{bosh_init, init_xml_model(&quot;bosh_init.xsd&quot;)}].

init_xml_model(Xsdfile) -&gt;
 {ok, Model} = erlsom:compile_xsd_file(Xsdfile),
 Model.
</pre>
<p>It very easy. If want to use it, you cant fire a <em>Erlang</em> terminal and type <em>mochibosh:start() </em>and it will be up and running. The loop<br />
option in the tuple that is passed to <em>mochiweb_http:start </em>is used to provide the callback module. In this case is the mochibosh module itself (?MODULE)</p>
<p>So what would happen if we try it&#8230;.</p>
<p>In one terminal we fire the <em>Erlang</em> shell (erl) and start mochibosh:</p>
<pre class="brush: bash;">

20:38:25 mochibosh $ erl
Erlang R14A (erts-5.8) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8  (abort with ^G)
1&gt; mochibosh:start().
{ok,&lt;0.34.0&gt;}
</pre>
<p>In another terminal we issue a simple request with <a title="curl homepage" href="http://curl.haxx.se/" onclick="javascript:pageTracker._trackPageview('/outbound/article/curl.haxx.se');">curl</a>&#8230;</p>
<pre class="brush: bash;">

20:40:19 mochibosh $ curl -v http://192.168.1.110:8888
* About to connect() to 192.168.1.110 port 8888 (#0)
*   Trying 192.168.1.110... connected
* Connected to 192.168.1.110 (192.168.1.110) port 8888 (#0)
&gt; GET / HTTP/1.1
&gt; User-Agent: curl/7.21.0 (i386-apple-darwin10.2.0) libcurl/7.21.0 OpenSSL/1.0.0a zlib/1.2.5 libidn/1.19
&gt; Host: 192.168.1.110:8888
&gt; Accept: */*
&gt;
^C
</pre>
<p>And meanwhile in the <em>Erlang </em>shell..</p>
<pre class="brush: bash;">

{ok,&lt;0.34.0&gt;}
CALLBACK. Petition on port {ok,8888}
SPAWNED PROCESS. Request received on port {ok,8888}

2&gt;
</pre>
<p>GREAT!! Everything seems to work. So now, I decided to move on and begin to develop my BOSH manager.</p>
<p>As I sayed, I&#8217;ll be using StropheJS for the browser/client side. For testing purpouses I began using one of the examples shipped with the library: <a title="echobot at github" href="http://github.com/metajack/strophejs/blob/master/examples/echobot.js" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">echobot.js </a>.This example will issue a request for starting a BOSH session (among other things) and that is perfect for my testing pourposes. So lets, try.</p>
<p>(Imagin that the request is sent from echobot to the BOSH manager)</p>
<p>And I expecto to get the same reply from my callback module as when I tryed it with curl. Lets see:</p>
<pre class="brush: bash;">

CALLBACK. Petition on port {ok,8888}
SPAWNED PROCESS. Request received on port {error,einval}
</pre>
<p>WTF!!!!! What&#8217;s that of {error, einval}. Well, I can see that&#8217;s an error, but why? As this post is getting really big, I&#8217;ll leave the explanation for another one.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2010/08/11/erlang-mochiweb-bosh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install mochiweb with macports</title>
		<link>http://blog.tenako.com/2010/07/19/install-mochiweb-with-macports/</link>
		<comments>http://blog.tenako.com/2010/07/19/install-mochiweb-with-macports/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 17:32:02 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/2010/07/19/install-mochiweb-with-macports/</guid>
		<description><![CDATA[Just two things: I installed this on a MacBook with a CoreDuo processor. By default macports will try to use all avaliable processors for the building stuff (2 on my case) with the -j option of Make. On my case this ended up with weird compilation errors (something like a race condition between the to [...]]]></description>
			<content:encoded><![CDATA[<p>Just two things:</p>
<ol>
<li>I installed this on a MacBook with a CoreDuo processor. By default macports will try to use all avaliable processors for the building stuff (2 on my case) with the -j option of Make. On my case this ended up with weird compilation errors (something like a race condition between the to make jobs). I fixed it setting the <em>buildmakejobs</em> to 1 (at /opt/etc/macports/macports.conf) so it used just one make job</li>
<li>The Makefile rule for the documentation at <em>&lt;package&gt;/support/include.mk</em> is wrong. The function that make should call at the <em>edoc</em> module is <em>files/3</em> not <em>file</em> as it&#8217;s deprecated.</li>
</ol>
<p>Enjoy!!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2010/07/19/install-mochiweb-with-macports/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby: gmaps-geocode 0.1.0 is out !!</title>
		<link>http://blog.tenako.com/2009/07/04/ruby-gmaps-geocode-0-1-0-is-out/</link>
		<comments>http://blog.tenako.com/2009/07/04/ruby-gmaps-geocode-0-1-0-is-out/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 20:12:24 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/2009/07/04/ruby-gmaps-geocode-0-1-0-is-out/</guid>
		<description><![CDATA[Disponible en github]]></description>
			<content:encoded><![CDATA[<p>Disponible en <a title="gmaps-geocode at github" href="http://github.com/madtrick/gmaps-geocode/tree/master" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');" target="_blank">github</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/07/04/ruby-gmaps-geocode-0-1-0-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby: ¡Cállate IRB!</title>
		<link>http://blog.tenako.com/2009/06/22/ruby-%c2%a1callate-irb/</link>
		<comments>http://blog.tenako.com/2009/06/22/ruby-%c2%a1callate-irb/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 09:45:46 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=194</guid>
		<description><![CDATA[¿Harto de que en alguna ocasión IRB sea demasiado verboso? Yo si. Por defecto, IRB siempre &#8220;escupirá&#8221; el valor resultante de evaluar la expresión introducida por el usuario. Aunque la mayoría de las veces eso está bien, hay otras en las que sacarias el corazón con una cucharilla de Té  a quien tuvieras delante por [...]]]></description>
			<content:encoded><![CDATA[<p>¿Harto de que en alguna ocasión IRB sea demasiado verboso? Yo si.</p>
<p>Por defecto, IRB siempre &#8220;escupirá&#8221; el valor resultante de evaluar la expresión introducida por el usuario. Aunque la mayoría de las veces eso está bien, hay otras en las que sacarias el corazón con una cucharilla de Té  a quien tuvieras delante por la crispación que produce esta &#8220;verbosidad&#8221;.</p>
<p>Me refiero a situaciones del tipo &#8220;quiero recorrer un array y listar el nombre de sus elementos con puts&#8221;, ejemplo:</p>
<pre class="brush: ruby;">
ArrayEnorme.each do |element| puts &quot;#{element.name}\n&quot; end
</pre>
<p>Con el código anterior vamos a mostrar el nombre de cada elemento del Array. Hasta aquí todo normal. El problema de evaluar esto en IRB es que, si ArrayEnorme tiene bastantes elementos y cada elemento tiene bastantes atributos, las lineas que imprimos con el nombre de cada elemento quedaran &#8220;sepultadas&#8221; por un mont<span>ón</span> de datos inutiles. Es decir, si el buffer de nuestra consola no se ha llenado con estos datos inutiles (perdiendo así las lineas con el nombre de cada elemento) tendremos que hacer scroll <em>ad-infinitum</em>, que para el caso es casí como si se hubierán perdido.</p>
<p>Para evitar esto, os presento mi solución de andar por casa:</p>
<pre class="brush: ruby;">

def toggle_output
context.return_format == &quot;Output canceled\n&quot; ? IRB.conf[:PROMPT][context.prompt_mode][:RETURN] : context.return_format = &quot;Output canceled\n&quot;
end

alias tgo toggle_output
</pre>
<p>Después de copiar las lineas anteriores en nuestro .irbrc podemos hacer pruebas:</p>
<pre class="brush: bash;">
madtrick::madtrick::$irb
irb(main):001:0&gt; 2 + 1
=&gt; 3
irb(main):002:0&gt; toggle_output
Output canceled
irb(main):003:0&gt; 2 + 1
Output canceled
irb(main):004:0&gt; toggle_output
=&gt; &quot;=&gt; %s\n&quot;
irb(main):005:0&gt; 2 + 1
=&gt; 3
</pre>
<p>Y <em>voila</em>, ya podemos callar y dar voz a IRB cuando nos plazca.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/06/22/ruby-%c2%a1callate-irb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby: Sketches en IRB</title>
		<link>http://blog.tenako.com/2009/06/19/ruby-sketches-en-irb/</link>
		<comments>http://blog.tenako.com/2009/06/19/ruby-sketches-en-irb/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 16:47:14 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[sketches]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=188</guid>
		<description><![CDATA[Hoy descubrí una gema m-a-r-a-v-i-l-l-o-s-a: Sketches. El concepto que implementa sketches es sencillo: las modificicaciones que hagamos en nuestro editor de texto, se reflejan al instante en la sesión de irb. Es decir, si en el editor de texto creamos una clase y guardamos los cambios, la clase estará disponible automaticamente en la sesión de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy descubrí una gema m-a-r-a-v-i-l-l-o-s-a: <a href="http://sketches.rubyforge.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/sketches.rubyforge.org');" target="_blank">Sketches</a>.</p>
<p>El concepto que implementa sketches es sencillo: las modificicaciones que hagamos en nuestro editor de texto, se reflejan al instante en la sesión de irb. Es decir, si en el editor de texto creamos una clase y guardamos los cambios, la clase estará disponible automaticamente en la sesión de irb.</p>
<p>Su utilización es sencilla: arrancamos el IRB y lanzamos nuestro editor favorito con el comando sketch. A partir de ahí, el funcionamiento es como expliqué antes.</p>
<p>Mola : )</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/06/19/ruby-sketches-en-irb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

