<?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 &#187; programacion</title>
	<atom:link href="http://blog.tenako.com/category/programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tenako.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jul 2010 17:32:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 make [...]]]></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 la [...]]]></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 irb.
Su [...]]]></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>
		<item>
		<title>Ruby: callcc</title>
		<link>http://blog.tenako.com/2009/06/03/ruby-callc/</link>
		<comments>http://blog.tenako.com/2009/06/03/ruby-callc/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 15:04:00 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[callcc]]></category>
		<category><![CDATA[continuations]]></category>
		<category><![CDATA[frame]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=160</guid>
		<description><![CDATA[callcc, es la abreviatura de call-with-current-continuation, algo así como un goto con esteroides.
En el rdoc nos encontramos con la siguiente definición:


callcc &#123;&#124;cont&#124; block &#125; =&#62; obj

Generates a Continuation object, which it passes to the associated block. Performing a cont.call will cause the callcc to return (as will falling through the end of the block). The [...]]]></description>
			<content:encoded><![CDATA[<p><strong>callcc</strong>, es la abreviatura de call-with-current-continuation, algo así como un goto con esteroides.</p>
<p>En el <a href="http://www.ruby-doc.org/core/classes/Kernel.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ruby-doc.org');" target="_blank">rdoc</a> nos encontramos con la siguiente definición:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">callcc <span style="color:#006600; font-weight:bold;">&#123;</span>|cont| block <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> obj</pre></div></div>

<p>Generates a Continuation object, which it passes to the associated block. Performing a cont.call will cause the callcc to return (as will falling through the end of the block). The value returned by the callcc is the value of the block, or the value passed to cont.call. See class Continuation for more details. Also see Kernel::throw for an alternative mechanism for unwinding a call stack.
</p></blockquote>
<p>Un tanto críptico, ¿No?. Basicamente, callcc almacena la dirección de memoria y el contexto  (en un objeto <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_continuation.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ruby-doc.org');" target="_blank">Continuation</a>) de donde se le llamo. Sigue siendo raro,¿No?</p>
<p>Mejor un ejemplo. Sea el siguiente metodo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">&nbsp;
counter = 0
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> foo
<span style="color:#CC0066; font-weight:bold;">exit</span> <span style="color:#9966CC; font-weight:bold;">if</span> callcc<span style="color:#006600; font-weight:bold;">&#123;</span>|$cont| <span style="color:#006600; font-weight:bold;">&#125;</span> == <span style="color:#006666;">3</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;hello world&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
foo
&nbsp;
<span style="color:#ff6633; font-weight:bold;">$cont</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>counter <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>(Si ya se que las variables globales son malignas : ( )</p>
<p>Ejecutando el ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">madtrick::madtrick::<span style="color: #007800;">$ruby</span> test3.rb
hello world
hello world
hello world</pre></div></div>

<p>Como se puede apreciar, se imprimen tres &#8220;hello world&#8221; con sólo una llamada al método foo. </p>
<p>¿Qué podemos extraer del ejemplo anterior?</p>
<ul>
<li> Cada llamada a la continuación ($cont) nos vuelve a llevar a linea donde se definió.</li>
<li> Si en la llamada a la continuación pasamos algun parámetro, este es devuelto por callcc</li>
</ul>
<p>Tambien podríamos utilizar los ejemplos del post anterior (<a href="http://blog.tenako.com/2009/06/01/ruby-tco-tail-call-optimization/"  target="_blank">Tail Call Optimization</a>) para explicar el funcionamiento de callcc:</p>
<p>Calculo del factorial de un número:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> TCOTest
  <span style="color:#008000; font-style:italic;"># tail-recursive factorial</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fact<span style="color:#006600; font-weight:bold;">&#40;</span> n, acc = <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> n <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">then</span>
      acc
    <span style="color:#9966CC; font-weight:bold;">else</span>
       fact<span style="color:#006600; font-weight:bold;">&#40;</span> n<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>, n<span style="color:#006600; font-weight:bold;">*</span>acc <span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> fact_cc<span style="color:#006600; font-weight:bold;">&#40;</span> n, acc = <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    cont = callcc<span style="color:#006600; font-weight:bold;">&#123;</span>|cont| cont<span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> n <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">then</span>
      acc
    <span style="color:#9966CC; font-weight:bold;">else</span>
       n, acc = n<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>, n<span style="color:#006600; font-weight:bold;">*</span>acc
       cont.<span style="color:#9900CC;">call</span> cont 
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># length of factorial</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fact_size<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>
    fact<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">size</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span>
    $!
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
  <span style="color:#008000; font-style:italic;"># length of factorial</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fact_size_cc<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>
    fact_cc<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">size</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span>
    $!
  <span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Si lo probamos en el irb vemos que fact_size_cc no da ningún tipo de problema mientras que la función fact_size (sí, por carecer Ruby de TCO) ya que nos quedamos sin espacio en la stack.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">...
irb<span style="color: #7a0874; font-weight: bold;">&#40;</span>main<span style="color: #7a0874; font-weight: bold;">&#41;</span>:009:0<span style="color: #000000; font-weight: bold;">&gt;</span> t.fact_size <span style="color: #000000;">10000</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #666666; font-style: italic;">#&lt;SystemStackError: stack level too deep&gt;</span>
irb<span style="color: #7a0874; font-weight: bold;">&#40;</span>main<span style="color: #7a0874; font-weight: bold;">&#41;</span>:010:0<span style="color: #000000; font-weight: bold;">&gt;</span> t.fact_size_cc <span style="color: #000000;">10000</span>
=<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">14808</span></pre></div></div>

<p>El otro ejemplo del post anterior, la función de Fibonacci:</p>
<p>En el ejemplo anterior, utilizábamos la palabra reservada <strong>redo</strong> junto con  un método definido ad-hoc para poder realizar el cálculo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">  define_method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:acc</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |i, n, result|
    <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>
      result
    <span style="color:#9966CC; font-weight:bold;">else</span>
      i, n, result = i <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span>, n <span style="color:#006600; font-weight:bold;">+</span> result, n
      <span style="color:#9966CC; font-weight:bold;">redo</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> fib_redo<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
   acc i,<span style="color:#006666;">1</span>,0
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Pero tambien se podria haber hecho de esta otra forma:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> fib_call_cc<span style="color:#006600; font-weight:bold;">&#40;</span>i, n = <span style="color:#006666;">1</span>, result = 0<span style="color:#006600; font-weight:bold;">&#41;</span>
  cont = callcc<span style="color:#006600; font-weight:bold;">&#123;</span>|cont| cont<span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>
    result
  <span style="color:#9966CC; font-weight:bold;">else</span>
    i, n, result = i <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span>, n <span style="color:#006600; font-weight:bold;">+</span> result, n
    cont.<span style="color:#9900CC;">call</span> cont
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>En el ejemplo anterior se puede apreciar como el contexto se mantiene. En este caso para los valores <strong>i</strong>,<strong>n</strong> y <strong>result</strong>.</p>
<p>Si ejecutamos un simple benchmark (para n en 50000) para comparar redo vs callcc, obtenemos los siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">&nbsp;
madtrick::madtrick::<span style="color: #007800;">$ruby</span> test.rb 
Time <span style="color: #000000; font-weight: bold;">for</span> fib_redo:      <span style="color: #000000;">0.390000</span>   <span style="color: #000000;">0.010000</span>   <span style="color: #000000;">0.400000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>  <span style="color: #000000;">0.403986</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Time <span style="color: #000000; font-weight: bold;">for</span> fib_call_cc:   <span style="color: #000000;">0.500000</span>   <span style="color: #000000;">0.000000</span>   <span style="color: #000000;">0.500000</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>  <span style="color: #000000;">0.519504</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>redo (  0.403986) es un poco más rápido que callcc (  0.519504). Echándole un vistazo rapido al codigo de la máquina virtual de Ruby se entiende rápidamente el porque. <strong>redo</strong> esta implentado utilizando goto&#8217;s mientras que callcc es una llamada a una función que se encarga de guardar toda la información necesaria en un objeto Continuation, por lo que necesita más tiempo.</p>
<p>Para mas información sobre callcc, su funcionamiento y los continuations:</p>
<ul>
<li><a href="http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.intertwingly.net');">Continuations</a></li>
<li><a href="http://www.madore.org/~david/computers/callcc.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.madore.org');">Callcc</a></li>
<li><a href="http://www.cs.utk.edu/~huangj/cs360/360/notes/Setjmp/lecture.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.cs.utk.edu');">Setjmp/longjmp</a>, funciones en C con las que se puede implementar un comportamiento similar</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/06/03/ruby-callc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby: TCO (Tail Call Optimization)</title>
		<link>http://blog.tenako.com/2009/06/01/ruby-tco-tail-call-optimization/</link>
		<comments>http://blog.tenako.com/2009/06/01/ruby-tco-tail-call-optimization/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 22:21:13 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[recursividad]]></category>
		<category><![CDATA[tco]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=130</guid>
		<description><![CDATA[Leyendo el libro de Programming Erlang descubrí un concepto que no conocia: funciones tail-recursive.
En esta pagina lo explican bastante bien (entre otros tipos de recursividad), pero basicamente una función tail-recursive es aquella que no tiene ninguna operación pendiente de ejecutar tras la llamada recursiva. En estas funciones, la llamada recursiva puede ser substituida simplemente por [...]]]></description>
			<content:encoded><![CDATA[<p>Leyendo el libro de <a href="http://www.pragprog.com/titles/jaerlang/programming-erlang" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.pragprog.com');" target="_blank">Programming Erlang</a> descubrí un concepto que no conocia: funciones <em>tail-recursive</em>.</p>
<p>En <a href="http://triton.towson.edu/~akayabas/COSC455_Spring2000/Recursion_Iteration.htm" onclick="javascript:pageTracker._trackPageview('/outbound/article/triton.towson.edu');" target="_blank">esta pagina</a> lo explican bastante bien (entre otros tipos de recursividad), pero basicamente una función <em>tail-recursive</em> es aquella que no tiene ninguna operación pendiente de ejecutar tras la llamada recursiva. En estas funciones, la llamada recursiva puede ser substituida simplemente por un salto al comienzo de la función que se llama, con lo que se ahorra espacio en el <em>stack</em>. De esto ultimo se encarga el compilador y es lo que se conoce como <a href="http://c2.com/cgi/wiki?TailCallOptimization" onclick="javascript:pageTracker._trackPageview('/outbound/article/c2.com');" target="_blank">Tail Call Optimization</a> (TCO a partir de ahora).</p>
<p>Así que aparentemente la TCO mola, ¿No?</p>
<p>El problema es que <a href="http://www.ruby-lang.org/es/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ruby-lang.org');" targe="_blank">Ruby</a> no tiene implementada  TCO en su maquina virtual con lo que independientemente de como estructuremos nuestras funciones recursivas, siempre estaremos limitados por el tamaño de nuestra Stack.</p>
<p>Pero siempre hay solución para todo y con Ruby, más. En <a href="http://judofyr.net/posts/tailin-ruby.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/judofyr.net');" target="_blank">ésta página</a> dan dos soluciones para tener una pseudo-TCO.</p>
<p>Copio y pego la primera solución:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#9966CC; font-weight:bold;">Class</span>
  <span style="color:#008000; font-style:italic;"># Sweet stuff!</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> tailcall_optimize<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>methods <span style="color:#006600; font-weight:bold;">&#41;</span>
    methods.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |meth|
      org = instance_method<span style="color:#006600; font-weight:bold;">&#40;</span> meth <span style="color:#006600; font-weight:bold;">&#41;</span>
      define_method<span style="color:#006600; font-weight:bold;">&#40;</span> meth <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |*args|
        <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#91;</span> meth <span style="color:#006600; font-weight:bold;">&#93;</span>
          throw<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:recurse</span>, args <span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#91;</span> meth <span style="color:#006600; font-weight:bold;">&#93;</span> = org.<span style="color:#9900CC;">bind</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">self</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
          result = <span style="color:#CC0066; font-weight:bold;">catch</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:done</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
            <span style="color:#CC0066; font-weight:bold;">loop</span> <span style="color:#9966CC; font-weight:bold;">do</span>
              args = <span style="color:#CC0066; font-weight:bold;">catch</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:recurse</span> <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
                throw<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:done</span>, <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#91;</span> meth <span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">*</span>args <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
              <span style="color:#9966CC; font-weight:bold;">end</span>
            <span style="color:#9966CC; font-weight:bold;">end</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
          <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">current</span><span style="color:#006600; font-weight:bold;">&#91;</span> meth <span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
          result
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> TCOTest
  <span style="color:#008000; font-style:italic;"># tail-recursive factorial</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fact<span style="color:#006600; font-weight:bold;">&#40;</span> n, acc = <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> n <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006666;">2</span> <span style="color:#9966CC; font-weight:bold;">then</span> acc <span style="color:#9966CC; font-weight:bold;">else</span> fact<span style="color:#006600; font-weight:bold;">&#40;</span> n<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>, n<span style="color:#006600; font-weight:bold;">*</span>acc <span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># length of factorial</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> fact_size<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>
    fact<span style="color:#006600; font-weight:bold;">&#40;</span> n <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">size</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span>
    $!
  <span style="color:#9966CC; font-weight:bold;">end</span>   
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
t = TCOTest.<span style="color:#9900CC;">new</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># normal method</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> t.<span style="color:#9900CC;">fact_size</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">10000</span> <span style="color:#006600; font-weight:bold;">&#41;</span>  <span style="color:#008000; font-style:italic;"># =&gt; stack level too deep</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># enable tail-call optimization</span>
<span style="color:#9966CC; font-weight:bold;">class</span> TCOTest
  tailcall_optimize <span style="color:#ff3333; font-weight:bold;">:fact</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># tail-call optimized method</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> t.<span style="color:#9900CC;">fact_size</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006666;">10000</span> <span style="color:#006600; font-weight:bold;">&#41;</span>  <span style="color:#008000; font-style:italic;"># =&gt; 14808</span></pre></div></div>

<p>Esta solución consiste en jugar con catch&#8217;s,throw&#8217;s y Thread.current para relanzar el mismo método una y otra vez sin tener que crear un nuevo frame en el Stack, ya que el codigo del metodo se encuentra definido en un bloque y por tanto reutiliza el codigo. </p>
<p>La segunda opción:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> fib<span style="color:#006600; font-weight:bold;">&#40;</span>i, n = <span style="color:#006666;">1</span>, result = 0<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>
    result
  <span style="color:#9966CC; font-weight:bold;">else</span>
    i, n, result = i <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span>, n <span style="color:#006600; font-weight:bold;">+</span> result, n
    <span style="color:#9966CC; font-weight:bold;">redo</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
fib<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10000</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Esta solución consiste en hacer uso de la palabra <a href="http://www.rubyist.net/~slagell/ruby/control.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.rubyist.net');" target="_blank">redo</a> la cual reinicia la ejecución de cualquier loop o iterador. El problema con redo es que, como acabo de decir, solo se puede utilizar en loops o iteradores y el método fib anterior no es ninguno de ellos. Por lo que el autor de la página de que se extrajeron las soluciones dice:</p>
<blockquote><p>Unfortunately, “The redo statement restarts the current iteration of a loop or iterator”, so it only throws a LocalJumpError</p></blockquote>
<p><img src="http://blog.tenako.com/wp-content/uploads/2009/06/ruby_spartan1.png" alt="ruby_spartan1" title="ruby_spartan1" width="550" height="343" class="aligncenter size-full wp-image-153" /></p>
<p>Gracias señor espartano. </p>
<p>Así es, esto es Ruby y siempre hay un workaround para todo. En este caso, consiste en crear un nuevo método cuyo cuerpo este contenido en un bloque.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">define_method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:acc</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |i, n, result|
  <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>
    result
  <span style="color:#9966CC; font-weight:bold;">else</span>
    i, n, result = i <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span>, n <span style="color:#006600; font-weight:bold;">+</span> result, n
    <span style="color:#9966CC; font-weight:bold;">redo</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> fib<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
  acc<span style="color:#006600; font-weight:bold;">&#40;</span>i, <span style="color:#006666;">1</span>, 0<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
fib<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10000</span><span style="color:#006600; font-weight:bold;">&#41;</span>  <span style="color:#008000; font-style:italic;"># Yeah!</span></pre></div></div>

<p>Y ya podemos utilizar redo. Fin!!</p>
<p>Para mas información, hay un thread en esta lista de correo en el que debaten sobre este tema: <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/171075" onclick="javascript:pageTracker._trackPageview('/outbound/article/blade.nagaokaut.ac.jp');" target="_blank">Ruby tail recursion</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/06/01/ruby-tco-tail-call-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby: Expirar los mensajes de Starling en 3 comodos pasos</title>
		<link>http://blog.tenako.com/2009/03/20/expirar-mensajes-starling/</link>
		<comments>http://blog.tenako.com/2009/03/20/expirar-mensajes-starling/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 17:12:12 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[expiry]]></category>
		<category><![CDATA[starling]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=113</guid>
		<description><![CDATA[Si te pasa como a mi, que quieres almacenar mensajes en el starling pero que algunos de ellos lleven &#8220;fecha de caducidad&#8220;, sigue los siguiente pasos.

Paso 1 : Abrir en un editor el fichero handler.rb perteneciente a la gema starling-starling.
Paso 2 : En el método Handler#set_data añadir la siguiente linea justo antes de hacer el [...]]]></description>
			<content:encoded><![CDATA[<p>Si te pasa como a mi, que quieres almacenar mensajes en el starling pero que algunos de ellos lleven &#8220;<a href="http://www.deveiate.org/code/Ruby-MemCache/classes/MemCache.html#M000009" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.deveiate.org');">fecha de caducidad</a>&#8220;, sigue los siguiente pasos.</p>
<ul>
<li><strong>Paso 1 :</strong> Abrir en un editor el fichero handler.rb perteneciente a la gema <a href="http://github.com/starling/starling/tree/master" onclick="javascript:pageTracker._trackPageview('/outbound/article/github.com');">starling-starling</a>.</li>
<li><strong>Paso 2 :</strong> En el método <em>Handler#set_data</em> añadir la siguiente linea justo antes de hacer el pack para generar la variable <em>internal_data</em>.</li>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">  ...
  <span style="color:#9900CC;">expiry</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">+</span> expiry.<span style="color:#9900CC;">to_i</span> <span style="color:#9966CC; font-weight:bold;">unless</span> expiry.<span style="color:#9900CC;">to_i</span> == 0
  ...</pre></div></div>

<li><strong>Paso 3 :</strong> Guarda y re-arranca el starling.Todo debería de ir como la seda.</li>
</ul>
<p>Con esto, lo único que hemos hecho es corregir un pequeño bug que hay en <em>Handler#get</em> ya que en este método solo se devuelve un mensaje si su expiry es 0 o si expiry es mayor que now (now en este contexto es Time.now.to_i ). El fallo viene de comparar a now (valor <a href="http://en.wikipedia.org/wiki/Unix_time" onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');">unix time</a>) con expiry el cual es solo un offset desde el momento en el que decidimos guardar un mensaje en starling.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">  ...
  <span style="color:#9966CC; font-weight:bold;">break</span> <span style="color:#9966CC; font-weight:bold;">if</span> expiry == 0 || expiry <span style="color:#006600; font-weight:bold;">&gt;</span>= now
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@expiry_stats</span><span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006666;">1</span>
  expiry, data = <span style="color:#0000FF; font-weight:bold;">nil</span>
  ...</pre></div></div>

<p>Con la linea que añadimos al método <em>Handler#set_data</em> forzamos que la comparación sea entre dos valores unix time.Uno refiriéndose al momento actual (now) y otro al momento en el que expirara el mensaje (la suma de Time.now.to_i en el momento del almacenarlo y el tiempo de vida del mensaje).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/03/20/expirar-mensajes-starling/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mac &amp; Git &amp; Ssh : Un poquillo de scripting</title>
		<link>http://blog.tenako.com/2009/02/26/mac-os-x-scripting/</link>
		<comments>http://blog.tenako.com/2009/02/26/mac-os-x-scripting/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 21:54:23 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[configd]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[kicker]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=85</guid>
		<description><![CDATA[Planteemos el siguiente problema:
Tenemos que hacer push&#8217;es y pull&#8217;es a un repositorio git (mediante ssh).
Sencillo, ¿no?.Ahora tengamos en cuenta las siguientes consideraciones:

Estas operaciones las vamos a realizar tanto desde nuestra casa (a través de internet) como desde la red donde se encuentra el repositorio, siendo la dirección del repositorio &#8211; git.frusfrusfrus.net, la misma en ambos [...]]]></description>
			<content:encoded><![CDATA[<p>Planteemos el siguiente problema:</p>
<p>Tenemos que hacer push&#8217;es y pull&#8217;es a un repositorio git (mediante ssh).</p>
<p>Sencillo, ¿no?.Ahora tengamos en cuenta las siguientes consideraciones:</p>
<ol>
<li>Estas operaciones las vamos a realizar tanto desde nuestra casa (a través de internet) como desde la red donde se encuentra el repositorio, siendo la dirección del repositorio &#8211; git.frusfrusfrus.net, la misma en ambos casos.</li>
<li>Por culpa de las hadas y de los proxies reversos, si las operaciones la realizamos desde casa el puerto sera el 2280 mientras que si las operaciones las realizamos desde la oficina el puerto será el 22.</li>
<li>Queremos que cualquier tipo de cambio en la configuración sea automático</li>
</ol>
<p>La consideración tres es el motivo de este post, ya que la dos (la unica que plantea algún problema) se podria resolver con un parámetro en la linea de comandos.Es más cómodo  no tener que preocuparse ni de donde estamos, ni tener que acordarse de como era la estructura del comando.</p>
<p>Mi primera opción fue la de crear un script que se ejecutase cada vez que encendiera el ordenador, para lo cual ya le habia hechado un vistazo a <a title="apple's startup item documentation" href="http://developer.apple.com/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/StartupItems.html#//apple_ref/doc/uid/20002132" onclick="javascript:pageTracker._trackPageview('/outbound/article/developer.apple.com');" target="_blank">esta documentación.</a> Pero como <a title="david's webpage" href="http://www.davidbarral.com" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.davidbarral.com');" target="_blank">David</a> tuvo bien a decirme, quizás seria mejor hacerlo siempre que la interfaz de red se levantara.Realmente esto está mucho mejor ya que cubria un abanico de opciones más amplio (volver de hibernación, desactivar y activar de nuevo la tarjeta de red&#8230;) que la idea de crear  un Startup item.</p>
<p>¿Y como co%&amp;o se yo cuando se levanta o se cae una interfaz de red en Mac OS X?</p>
<p>&#8230;google&#8230;google&#8230;google&#8230;google</p>
<p>Resulta que en Mac OS X  la gestión de las interfaces de red (entre otras muchas más cosas) las lleva un demonio: <a title="configd manpage" href="http://www.manpagez.com/man/8/configd/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.manpagez.com');" target="_blank">configd</a>. Este demonio monitoriza el siguiente fichero, /Library/Preferences/SystemConfiguration/preferences.plist. Configd reacciona ante cualquier cambio que se refleje en este fichero, derivando a quien corresponda  la tarea de manejar el evento.</p>
<p>Si el evento tiene que ver con la red del sistema, configd hace entrar en juego al  Kicker.bundle &#8211; que se puede encontrar en /System/library/SystemConfiguration/Kicker.bundle.Lo interesante de este bundle es su fichero de configuración: Kicker.xml en el cual se especifica ante que eventos reaccionar y lo que es más importante, como.</p>
<p>Este es mi fichero Kicker.xml original</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pre</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;xml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execCommand<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>$BUNDLE/Contents/Resources/enable-network<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execUID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>keys<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/IPv4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>enable-network<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>keys<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/DNS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/IPv4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/IPv6<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/NetInfo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>network_change<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>postName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.apple.system.config.network_change<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execCommand<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/sbin/AppleFileServer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execUID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>keys<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>daemon:AppleFileServer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AppleFileServer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>La primera sección dict , indica que se debe de ejecutar el script enable-network cada vez que se reciba un evento de tipo State:/Network/Global/IPv4 lo cual puede indicar que la interfaz se levantó y ha obtenido una ip, que se ha realizado un cambio de ip, que la interfaz se ha desconectado&#8230;etc.</p>
<p>La segunda sección dict indica que ante todos esos eventos : State:/Network/Global/IPv4 , State:/Network/Global/IPv6 &#8230; se va a emitir una notificación con el nombre com.apple.system.config.network_change.Decir que principalmente quien hará uso de este notificación sera <a href="http://www.manpagez.com/man/8/lookupd/" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.manpagez.com');" target="_blank">lookupd,</a> como se puede observar en este extracto del sytem.log:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">Feb <span style="color: #000000;">26</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">52</span> madtrick configd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">39</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: posting notification com.apple.system.config.network_change
Feb <span style="color: #000000;">26</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">52</span> madtrick lookupd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">538</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: lookupd <span style="color: #7a0874; font-weight: bold;">&#40;</span>version <span style="color: #000000;">369.8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> starting - Thu Feb <span style="color: #000000;">26</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">52</span> <span style="color: #000000;">2009</span>
...
Feb <span style="color: #000000;">26</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">46</span>:<span style="color: #000000;">16</span> madtrick configd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">39</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: posting notification com.apple.system.config.network_change
Feb <span style="color: #000000;">26</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">46</span>:<span style="color: #000000;">16</span> madtrick lookupd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">667</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: lookupd <span style="color: #7a0874; font-weight: bold;">&#40;</span>version <span style="color: #000000;">369.8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> starting - Thu Feb <span style="color: #000000;">26</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">46</span>:<span style="color: #000000;">16</span> <span style="color: #000000;">2009</span></pre></div></div>

<p>La tercera y ultima sección no es relevante a lo que estamos hablando, así que nada que comentar.</p>
<p>Bien.Llegados a este punto se me plantean dos opciones:</p>
<ul>
<li> Primera. Crear una nueva entrada en el fichero Kicker.xml para que un script se ejecute ante cualquier evento de tipo  State:/Network/Global/IPv4.</li>
<li>Segunda. Capturar la notificacion com.apple.system.config.network_change y actuar en consecuencia.</li>
</ul>
<p>Aparentemente la más interesante es la segunda.Es menos intrusiva y mas versatil,peeero tambien bastante mas complicada de afrontar de primeras.Por ello queda aplazada a la espera de que algún dia decida leer <a title="mac notification system" href="http://developer.apple.com/documentation/Darwin/Conceptual/MacOSXNotifcationOv/Introduction/chapter_1_section_1.html#//apple_ref/doc/uid/TP40005947-CH1-DontLinkElementID_27" onclick="javascript:pageTracker._trackPageview('/outbound/article/developer.apple.com');" target="_blank">esto</a> y  me plantee hacerlo.</p>
<p>Así que nos queda la primera opcion, ejecutar un script ante cada evento.</p>
<blockquote><p><strong>OJO: ANTES DE EDITAR Kicker.xml, HAZ UNA COPIA DE SEGURIDAD</strong></p></blockquote>
<p>Asi que nos ponemos manos a la obra y añadimos la siguiente sección dict al fichero Kicker.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execCommand<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/bin/ssh-config<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execUID<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>501<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/integer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>keys<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>State:/Network/Global/IPv4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ssh-config<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Donde /usr/bin/ssh-config es el script que se ejecutara ante cada cambio que afecte a la pila IPv4.</p>
<p>Para que los cambios tengan efecto, necesitamos matar el demonio configd y luego volver a levantarlo.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">madtrick::madtrick::<span style="color: #007800;">$sudo</span> <span style="color: #c20cb9; font-weight: bold;">killall</span> configd
madtrick::madtrick::<span style="color: #007800;">$sudo</span> configd
madtrick::madtrick::<span style="color: #007800;">$ps</span> aux | <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>c<span style="color: #7a0874; font-weight: bold;">&#93;</span>onfigd</pre></div></div>

<blockquote><p>Nota:</p>
<p>Una par de ocasiones en las que realicé estas operaciones sobre configd la terminal se quedo &#8220;frita&#8221; y el ordenador no queria reiniciarse correctamente.</p>
<p>En otra, system.log indicaba (algo que no se, solo supongo) que se desactivaba la ejecucion del script  enable-network y ssh-config, motivando que cualquier cambio sobre las interfaces de red, no se viera reflejado en la ejecución de estos scripts</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">Feb <span style="color: #000000;">26</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">53</span> madtrick configd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4698</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: posting notification com.apple.system.config.network_change
Feb <span style="color: #000000;">26</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">53</span> madtrick lookupd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4707</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: lookupd <span style="color: #7a0874; font-weight: bold;">&#40;</span>version <span style="color: #000000;">369.8</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> starting - Thu Feb <span style="color: #000000;">26</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">53</span> <span style="color: #000000;">2009</span>
Feb <span style="color: #000000;">26</span> <span style="color: #000000;">13</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">53</span> madtrick configd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4698</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>:   <span style="color: #007800;">target</span>=enable-network: disabled</pre></div></div>

<p>Desde mi punto de vista, considero esto normal ya que configd es un componente esencial para el correcto funcionamiento del sistema, por ello cualquier alteración en su funcionamiento (matarlo es un cambio bastante importante, ¿no?) es más que probable que derive en inestabilidad en el sistema.</p></blockquote>
<p>Llegados a este punto, solo nos queda reiniciar el ordenador (por eso de no jugar mas con configd) y comprobar que nuestro script se ejecuta correctamente.</p>
<p>Por si alguien le interesa el script ssh-config , <a href="http://www.tenako.com/upload/ssh-config.sh" >aqui esta</a>.Lo unico que hace este script es cambiar el puerto para el host git.frusfrusfrus.net de 22 a 2280 o de 2280 a 22 dependiendo de si estoy trabajando desde la red donde se encuentra el repo  o desde casa, respectivamente.</p>
<p>Para terminar, aqui dejo una lista de los enlaces que me fueron utiles.</p>
<p><a title="mac networking tips" href="http://www.afp548.com/article.php?story=20041015131913324" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.afp548.com');" target="_blank">Networking on OS X </a></p>
<p><a title="configd tips" href="http://www.radiotope.com/content/os-x-how-perform-action-during-fast-user-switch" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.radiotope.com');" target="_blank">OS X: How to perform an action during fast user switch</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/02/26/mac-os-x-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Any fool&#8230;</title>
		<link>http://blog.tenako.com/2009/02/22/any-fool/</link>
		<comments>http://blog.tenako.com/2009/02/22/any-fool/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 16:09:55 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[cita]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=78</guid>
		<description><![CDATA[Any fool can write code that a computer can understand. Good programmers write code that humans can understand
Martin Fowler dixit
]]></description>
			<content:encoded><![CDATA[<blockquote><p>Any fool can write code that a computer can understand. Good programmers write code that humans can understand</p></blockquote>
<p><a title="Martin Fowler webpage" href="http://martinfowler.com/" onclick="javascript:pageTracker._trackPageview('/outbound/article/martinfowler.com');" target="_blank">Martin Fowler</a> dixit</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/02/22/any-fool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim: Ficheros *~</title>
		<link>http://blog.tenako.com/2009/02/20/vim-ficheros/</link>
		<comments>http://blog.tenako.com/2009/02/20/vim-ficheros/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 11:44:19 +0000</pubDate>
		<dc:creator>farruco</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://blog.tenako.com/?p=60</guid>
		<description><![CDATA[Cada vez que edito algún fichero con Vim en mi macbook voy dejando restos en forma de ficheros con terminación ~. Es decir, si edito el fichero foo tras guardar y salir me encuentro que ahora tambiÃ©n tengo el fichero foo~.
¿Soluciones? Varias.
De todas formas yo opte por la mas sencilla -aunque menos drástica, deshabilitar la [...]]]></description>
			<content:encoded><![CDATA[<p>Cada vez que edito algún fichero con Vim en mi macbook voy dejando restos en forma de ficheros con terminación ~. Es decir, si edito el fichero foo tras guardar y salir me encuentro que ahora tambiÃ©n tengo el fichero foo~.</p>
<p>¿Soluciones? Varias.</p>
<p>De todas formas yo opte por la mas sencilla -aunque menos drástica, deshabilitar la opción escribir ficheros de backup, que no guardar una copia temporal  mientras editamos.</p>
<p>Extracto de la <a title="Vim online documentation" href="http://vimdoc.sourceforge.net/htmldoc/help.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/vimdoc.sourceforge.net');" target="_blank">documentación</a> de <a title="Vim webpage" href="www.vim.org/" target="_blank">Vim</a></p>
<blockquote><p>If you write to an existing file (but do not append) while the &#8216;backup&#8217;,<br />
&#8216;writebackup&#8217; or &#8216;patchmode&#8217; option is on, a backup of the original file is<br />
made.  The file is either copied or renamed (see &#8216;backupcopy&#8217;).  After the<br />
file has been successfully written and when the &#8216;writebackup&#8217; option is on and<br />
the &#8216;backup&#8217; option is off, the backup file is deleted.  When the &#8216;patchmode&#8217;<br />
option is on the backup file may be renamed.</p>
<p>*backup-table*<br />
<strong>&#8216;backup&#8217;  &#8217;writebackup&#8217;	   action</strong><br />
off                off	               no backup made<br />
off	                    on                backup current file, deleted afterwards<br />
on	                    off	               delete old backup, backup current file<br />
on	                    on		               delete old backup, backup current file</p></blockquote>
<p>Es decir, en mi .vimrc tengo las siguientes lineas</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> nobackup</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> writebackup</pre></div></div>

<p>Con ello, y atendiendo  a la anterior tabla, se creara un fichero *.swp mientras editamos y este sera borrado al finalizar.Lo cual por lo menos para mi, es suficiente.</p>
<p>Existen otras soluciones, como crear directorios donde almacenar estos ficheros,&#8230; comentadas <a title="Vim tips" href="http://vim.wikia.com/wiki/VimTip20" onclick="javascript:pageTracker._trackPageview('/outbound/article/vim.wikia.com');" target="_blank">aqu<span>í</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tenako.com/2009/02/20/vim-ficheros/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
