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

  <title><![CDATA[carlos@blog ~/notes>]]></title>
  <link href="http://blog.carloslima.name/atom.xml" rel="self"/>
  <link href="http://blog.carloslima.name/"/>
  <updated>2015-05-31T20:39:35+08:00</updated>
  <id>http://blog.carloslima.name/</id>
  <author>
    <name><![CDATA[Carlos Lima]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[External commands - Vim Tricks]]></title>
    <link href="http://blog.carloslima.name/blog/2015/05/31/external-commands-vim-tricks/"/>
    <updated>2015-05-31T13:37:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2015/05/31/external-commands-vim-tricks</id>
    <content type="html"><![CDATA[<p>While editing code, I frequently cycle between changing the code and running some commands: running
unit tests, linting tools, style checker, restarting services, etc.</p>

<p>I generaly do that directly from inside vim with <code>:!command</code> and then repeating it with <code>:!(up arrow)</code></p>

<p>While this is good, I learned a trick a while ago that still ranks as one of my favorites.</p>

<h1>The trick</h1>

<p>Add this to your <code>.vimrc</code></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>map \] :wa&lt;bar&gt;&lt;UP&gt;&lt;CR&gt;</span></code></pre></td></tr></table></div></figure>


<p>Then run your command as <code>:wa|!command</code> and repeat it with just <code>\]</code> directly on normal mode.</p>

<p>If <code>\</code> and <code>]</code> are not next to each other on your keyboard layout, just change the mapping
to something that is very easy and convenient to type :)</p>

<h1>The advantage</h1>

<p>This is quicker to type, it saves all the files before running the command and it still allows you
to run that one-off <code>:!command</code> in between your cycle without it getting in the way of your repetition.</p>

<p>That&rsquo;s it.
Happy Vimming!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[iDrac virtual console crashing on linux]]></title>
    <link href="http://blog.carloslima.name/blog/2015/05/21/idrac-virtual-console-crashing-on-linux/"/>
    <updated>2015-05-21T02:13:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2015/05/21/idrac-virtual-console-crashing-on-linux</id>
    <content type="html"><![CDATA[<h2>iDrac</h2>

<p><a href="https://en.wikipedia.org/wiki/Dell_DRAC">iDrac</a> (or any other <a href="https://en.wikipedia.org/wiki/Intelligent_Platform_Management_Interface">IPMI</a>) is great and can really save your time and your life, but
it is really frustrating to find out that your out-of-band virtual console crashes on you at
the moment you need it the most.</p>

<p>Given that this particular problem has struck me a few times already I decided to write a
post to my future self and save me some trouble.</p>

<h2>Scenario</h2>

<p>After receiving an alert and failing to connect to the host, you log into the iDrac&rsquo;s web
interface and click &ldquo;Launch&rdquo; on the Virtual Console option.<br/>
It downloads a file called <code>viewer.jnlp</code>.<br/>
You start it with <code>javaws viewer.jnlp</code> and, after a few confirmation dialogs, it explodes!</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>carlos@multi ~/Downloads&gt; javaws viewer.jnlp
</span><span class='line'>This application does not specify a Codebase in its manifest. Please verify with the applet's vendor. Continuing. See: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/no_redeploy.html for details.
</span><span class='line'>This application does not specify a Codebase in its manifest. Please verify with the applet's vendor. Continuing. See: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/no_redeploy.html for details.
</span><span class='line'>Application title was not found in manifest. Check with application vendor
</span><span class='line'>KVM/VM Client Version: 5.01.01 (Build 22)
</span><span class='line'>ProtocolAPCP.receieveSessionSetup : reconType = 101
</span><span class='line'>capabilities..4
</span><span class='line'>#
</span><span class='line'># A fatal error has been detected by the Java Runtime Environment:
</span><span class='line'>#
</span><span class='line'>#  SIGSEGV (0xb) at pc=0x00007f1268a72550, pid=14296, tid=139717301577472
</span><span class='line'>#
</span><span class='line'># JRE version: OpenJDK Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14)
</span><span class='line'># Java VM: OpenJDK 64-Bit Server VM (25.45-b02 mixed mode linux-amd64 compressed oops)
</span><span class='line'># Problematic frame:
</span><span class='line'># C  0x00007f1268a72550
</span><span class='line'>#
</span><span class='line'># Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
</span><span class='line'>#
</span><span class='line'># An error report file with more information is saved as:
</span><span class='line'># /home/carlos/Downloads/hs_err_pid14296.log
</span><span class='line'>#
</span><span class='line'># If you would like to submit a bug report, please visit:
</span><span class='line'>#   http://bugreport.java.com/bugreport/crash.jsp
</span><span class='line'>#
</span><span class='line'>fish: Job 1, “javaws viewer.jnlp ” terminated by signal SIGABRT (Abort)</span></code></pre></td></tr></table></div></figure>


<p>Looking into the log file gives no better clue.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>---------------  T H R E A D  ---------------
</span><span class='line'>
</span><span class='line'>Current thread (0x00007f1289ae0000):  JavaThread "iDRAC7 Virtual Console Client" [_thread_in_native, id=14329, stack(0x00007f1278112000,0x00007f1278213000)]
</span><span class='line'>
</span><span class='line'>siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x00007f1268a72550
</span><span class='line'>
</span><span class='line'>Registers:
</span><span class='line'>RAX=0x00007f1268a72550, RBX=0x0000000000000378, RCX=0x0000000000000000, RDX=0x00007f12782102cf
</span><span class='line'>RSP=0x00007f12782102e8, RBP=0x00007f1278210550, RSI=0x00007f12698cf477, RDI=0x00007f12698cf590
</span><span class='line'>R8 =0x00007f1298984908, R9 =0x0000000000000000, R10=0x00007f1268d5e380, R11=0x0000000000000202
</span><span class='line'>R12=0x0000000000000000, R13=0x00007f1269e15eb0, R14=0x00007f12782107b8, R15=0x00007f1289ae0000
</span><span class='line'>RIP=0x00007f1268a72550, EFLAGS=0x0000000000010206, CSGSFS=0x0000000000000033, ERR=0x0000000000000014
</span><span class='line'>  TRAPNO=0x000000000000000e
</span><span class='line'>
</span><span class='line'>Top of Stack: (sp=0x00007f12782102e8)
</span><span class='line'>0x00007f12782102e8:   00007f1269800440 0000000000000000
</span><span class='line'>(...)</span></code></pre></td></tr></table></div></figure>


<p>There is a lot of information there but going thru java stacktraces of your virtual console tool while
your server is down is undesired at best.</p>

<h2>Solution</h2>

<p>Fortunately the solution is simple.</p>

<p>Open the <code>viewer.jnlp</code> file.<br/>
There will be a bunch of OS and architecture-specific lines like this:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'> &lt;resources os="Windows" arch="x85"&gt;
</span><span class='line'>   &lt;nativelib href="https://server.example.com:443/software/avctKVMIOWin32.jar" download="eager"/&gt;
</span><span class='line'>   &lt;nativelib href="https://server.example.com:443/software/avctVMAPI_DLLWin32.jar" download="eager"/&gt;
</span><span class='line'> &lt;/resources&gt;
</span><span class='line'> &lt;resources os="Windows" arch="amd64"&gt;
</span><span class='line'>   &lt;nativelib href="https://server.example.com:443/software/avctKVMIOWin64.jar" download="eager"/&gt;
</span><span class='line'>   &lt;nativelib href="https://server.example.com:443/software/avctVMAPI_DLLWin64.jar" download="eager"/&gt;
</span><span class='line'> &lt;/resources&gt;
</span><span class='line'> (...)</span></code></pre></td></tr></table></div></figure>


<p>Delete all of them, except for the relevant one. In my case:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>  &lt;resources os="Linux" arch="x86_64"&gt;
</span><span class='line'>    &lt;nativelib href="https://server.example.com:443/software/avctKVMIOLinux64.jar" download="eager"/&gt;
</span><span class='line'>   &lt;nativelib href="https://server.example.com:443/software/avctVMAPI_DLLLinux64.jar" download="eager"/&gt;
</span><span class='line'>  &lt;/resources&gt;</span></code></pre></td></tr></table></div></figure>


<p>That&rsquo;s it. Running <code>javaws viewer.jnlp</code> should work fine now.</p>

<p>I believe this is not the &ldquo;correct&rdquo; solution but it gets you going.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Talk: Feedback]]></title>
    <link href="http://blog.carloslima.name/blog/2014/07/08/talk-feedback/"/>
    <updated>2014-07-08T01:01:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2014/07/08/talk-feedback</id>
    <content type="html"><![CDATA[<p><em>This is a talk I gave at work. It&rsquo;s the second time I give a similar talk so I&rsquo;ve decided to post it up. Unfortunately I have no slides nor video so I&rsquo;m posting my notes :&ndash;)</em></p>

<h1>Feedback</h1>

<blockquote><p>Feedback: collecting information about present and past of
a process to drive changes to the process itself</p></blockquote>

<p>Crucial to improve, if you don&rsquo;t know at what speed you&rsquo;re
running you can&rsquo;t adjust to the speed limit.<br/>
If you&rsquo;re not aware of problems, you can&rsquo;t fix them.<br/>
If you don&rsquo;t see logs and exception stacktraces you won&rsquo;t
know that your application crashes every time someone from
Russia visits your website.</p>

<p>Phrased like this sounds like a good thing but when you
think about the actual process of giving/receiving feedback
it changes a bit.<br/>
Who likes performance appraisals? Code reviews?
Submitting the system you worked on for 6 months to 3rd party review and scrutiny?</p>

<h1>Why are we afraid of giving feedback?</h1>

<p>When we ask for opinion/review, generally get &ldquo;it&rsquo;s ok/cool/nice&rdquo;.<br/>
People point out obvious problems but it usually doesn&rsquo;t go further.</p>

<p>There are usually something that could be different.<br/>
A better way, an alternative way, an experimental way.<br/>
Not necessarily better but if you look at something and
think &ldquo;I would have done it differently&rdquo;, maybe you should
say that.<br/>
The other person might like your idea or it might trigger
another idea in her head.</p>

<p>Another example.<br/>
You know that person who always do something when presenting
that distracts people from the presentation?<br/>
They repeat the
same phrase again and again or they mispronounce a word or
whatever and at the end of the talk everybody is whispering
about how many times he did this or that?<br/>
That person could be a much better presenter if he could fix
that behavior but it won&rsquo;t happen if he is not aware of it!</p>

<p>So, why are we so bad at giving feedback?</p>

<p>To answer that we need to look at another question.</p>

<h1>Why are we so bad at receiving feedback?</h1>

<p>People don&rsquo;t like being criticized.<br/>
Humans are wired like that :(<br/>
Hearing criticism doesn&rsquo;t change who you are but we don&rsquo;t like it anyway.<br/>
We go into defensive mode, we need to show we did the best
thing. We need to prove the person wrong!</p>

<p>To avoid confrontation, nobody wants to give nor receive feedback.</p>

<h1>Why is it bad?</h1>

<p>If you both don&rsquo;t give feedback not to hurt or make others angry
and you don&rsquo;t actively seek feedback, it only happens when a problem
occurs (or someone explodes). That&rsquo;s the time when emotions are high
and openness is low.</p>

<p>That makes people less willing to seek improvement generating a vicious cycle.</p>

<h1>How to fix it, then?</h1>

<p>Ermm..</p>

<ul>
<li>Improve on how we provide feedback</li>
<li>Improve on how we receive feedback</li>
</ul>


<h1>How to receive feedback</h1>

<p>You can&rsquo;t force people to be nicer or to do things in a way that pleases you.<br/>
But you can improve on how you handle it, so focus on that.</p>

<p>First, don&rsquo;t take it personally.<br/>
Face everything as an opportunity to revisit a topic and think if anything
could be improved.<br/>
Be open. You don&rsquo;t have to agree but be willing to consider ideas.<br/>
If it is a complain or an aggressive criticism, try to filter out the
offending part and think about the root cause of that complain; Could you
have done anything different so that there would be no complain?</p>

<h1>How to give feedback</h1>

<p>Avoid doing it if you&rsquo;re angry or in bad mood.<br/>
Consider what is the goal of your feedback and focus on having a
constructive conversation.<br/>
Don&rsquo;t expect the person to agree. You will
be lucky if they at least listen :&ndash;)<br/>
Consider that your idea/suggestion might not be better or might be
missing parts of the picture.<br/>
Even better, assume you&rsquo;re wrong; that there is something you don&rsquo;t know.<br/>
Guide the conversation to try to understand where you&rsquo;re wrong.</p>

<h1>Wrap up</h1>

<p>Feedback is good, is crucial to improve (as person, as professional, as team).<br/>
Most people are bad at both giving and receiving and avoid it as much as possible.<br/>
There is no silver bullet, no easy solution.<br/>
Be aware of the problem. Consider how you could do it better.<br/>
Search about the topic, find more information :)<br/>
And most important, practice. Stop avoiding it.</p>

<h1>Extra</h1>

<h2>Focus on the right stuff!</h2>

<blockquote><p>Criticism is driven by the frustration and fears of the giver, not from the needs of the recipient. The underlying assumption is that the recipient somehow &ldquo;should know better&rdquo; and needs to be set straight. The implied message is that the recipient&rsquo;s intentions are questionable, that there is something wrong with the recipient that the giver of criticism knows how to fix. In criticism, the problem is all in the recipient.<br/>
In contrast, feedback has an air of caring concern, respect, and support. Far from being a sugar cookie, feedback is an honest, clear, adult to adult exchange about specific behaviors and the effects of those behaviors. The assumption is that both parties have positive intentions, that both parties want to be effective and to do what is right for the company and other people. Another assumption is that well-meaning people can have legitimate differences in perception. The person offering the feedback owns the feedback as being his reaction to the behavior of the other person. That is, the giver recognizes the fact that what is being offered is a perception, not absolute fact.<br/>
&mdash; Gary R. Casselman &amp; Timothy C. Daughtry</p></blockquote>

<p><div /></p>

<blockquote><p>Punishing honest mistakes stifles creativity. I want people moving and shaking the earth and they&rsquo;re going to make mistakes.<br/>
&mdash; Ross Perot</p></blockquote>

<h2>Links</h2>

<ul>
<li><a href="http://www.drjeffspar.com/fearoffeedback.pdf">http://www.drjeffspar.com/fearoffeedback.pdf</a></li>
<li><a href="http://www.lifehack.org/articles/productivity/how-give-constructive-feedback-and-avoid-ugly-confrontations.html">http://www.lifehack.org/articles/productivity/how-give-constructive-feedback-and-avoid-ugly-confrontations.html</a></li>
</ul>


<p>Those are generally written for managers but the reasoning is the same.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Running Perl Workers on Iron.IO]]></title>
    <link href="http://blog.carloslima.name/blog/2013/11/05/running-perl-workers-on-iron-dot-io/"/>
    <updated>2013-11-05T00:37:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2013/11/05/running-perl-workers-on-iron-dot-io</id>
    <content type="html"><![CDATA[<p>Despite not being listed as an option on their documentation, it is possible to run <a href="http://www.perl.org/">perl</a> on their <a href="http://www.iron.io/worker">IronWorker</a> service.</p>

<blockquote><p>TL;DR (or Show Me The Code): <a href="https://github.com/carloslima/iron-play">working example, full sources</a>.</p></blockquote>

<h1>Quick start</h1>

<h2>IronWorkerNG (their upload/management tool)</h2>

<p>We will need their management tool to upload code.</p>

<pre><code>gem install iron_worker_ng
</code></pre>

<h2>The credentials</h2>

<p>IronWorkerNG reads the credentials from a file named <code>iron.json</code>.<br/>
To get it, we need to login to <a href="https://hud.iron.io/dashboard,">https://hud.iron.io/dashboard,</a> click on the key-icon and download <code>iron.json</code> to the root directory of the project.</p>

<h2>Resolving dependencies on CPAN modules</h2>

<p>Iron.IO doesn&rsquo;t come with any perl module other than what is in <a href="http://perldoc.perl.org/5.14.2/index-modules-A.html">core</a>, so we need to bring in all our dependencies.</p>

<p>For that we will use <a href="https://metacpan.org/pod/Carton">Carton</a></p>

<pre><code>$ cpanm -nq Carton   # install carton
</code></pre>

<p>add our dependencies to <code>cpanfile</code></p>

<pre><code>$ cat cpanfile
requires 'Data::Printer';
requires 'File::Slurp';
requires 'Mojolicious';
</code></pre>

<p>and install them to a ./local/ directory</p>

<pre><code>$ carton install
</code></pre>

<h2>Seting up the worker</h2>

<p>The configuration for the worker is defined in a <code>&lt;service&gt;.worker</code> file, so we create a simple one that tells it to run our perl script and to upload our dependencies (generated by Carton, above) together with the code.</p>

<pre><code>$ cat iron-pl.worker
runtime 'perl'
exec 'iron-pl.pl'
dir 'local/lib/perl5'
</code></pre>

<p>This will upload our code together with the <code>./local/lib/perl5</code> directory (as <code>./perl5</code> on their system)</p>

<p>For more information, check the <a href="http://dev.iron.io/worker/reference/dotworker/">.worker documentation</a>.</p>

<h2>Writing the code!</h2>

<p>This is what will be run when you schedule some tasks.<br/>
We can go crazy on that one, but here I&rsquo;d like to highlight just a few things:</p>

<pre><code>#!/usr/bin/env perl
use 5.010; use utf8; use strict; use warnings;
(...)

use lib 'perl5';
</code></pre>

<p>We need to load the dependencies from the local directory, thus the <code>use lib</code> above.</p>

<pre><code>(...)
my %args = @ARGV;
</code></pre>

<p>They pass arguments as <code>('-d', '/task/', '-e', 'production', '-id', '5277ca9ed16f93360109d0aa', '-payload', '/task/task_payload.json')</code> so we can load them as a Hash and access it as <code>$args{-d}</code> :&ndash;)</p>

<p>The data passed from the scheduled task to the worker comes in a <code>.json</code> file, so we need to parse that</p>

<pre><code>my $payload = Mojo::JSON-&gt;new-&gt;decode( read_file($args{-payload}) );
</code></pre>

<p>For more info (and executable code), check the <a href="https://github.com/carloslima/iron-play">full sources</a> on github.</p>

<h2>Deploy</h2>

<p>With all pieces ready, we can upload the code to their platform using their management tool.</p>

<pre><code>$ iron_worker upload iron-pl.worker
    ------&gt; Creating client
            Project 'ironing-board' with id='5277a2b987a3b90005000044'
    ------&gt; Creating code package
            Found workerfile with path='iron-pl.worker'
            Detected exec with path='iron-pl.pl' and args='{}'
            Merging dir with path='local/lib/perl5' and dest=''
            Code package name is 'iron-pl'
    ------&gt; Uploading code package 'iron-pl'
            Code package uploaded with id='5277af07c7abc62bd5098755' and revision='4'
            Check 'https://hud.iron.io/tq/projects/5277a2b987a3b90005000044/code/5277af07c7abc62bd5098755' for more info
</code></pre>

<h2>Add tasks to the queue</h2>

<pre><code>$ iron_worker queue iron-pl -p '{"tags":["iron.io","perl"]}'
    ------&gt; Creating client
            Project 'ironing-board' with id='5277a2b987a3b90005000044'
    ------&gt; Queueing task
            Code package 'iron-pl' queued with id='5277ca9ed16f93360109d0aa'
            Check 'https://hud.iron.io/tq/projects/5277a2b987a3b90005000044/jobs/5277ca9ed16f93360109d0aa' for more info
</code></pre>

<h2>Check results</h2>

<p>We can either go straight to the web interface using the url listed above or use their management tool:</p>

<pre><code>    $ iron_worker log 5277ca9ed16f93360109d0aa
    ------&gt; Creating client
            Project 'ironing-board' with id='5277a2b987a3b90005000044'
    ------&gt; Getting log for task with id='5277ca9ed16f93360109d0aa'
    Iron-Play v0.0.1
    2013-11-04T16:26:10
    Environment: {
        HOME              "/task",
        LANG              "en_US.UTF-8",
        LD_LIBRARY_PATH   ".:./lib:./__debs__/usr/lib:./__debs__/usr/lib/x86_64-linux-gnu:./__debs__/lib:./__debs__/lib/x86_64-linux-gnu",
        LOGNAME           "nobody",
        MAIL              "/var/mail/nobody",
        OLDPWD            "/task",
        PATH              ".:./bin:./__debs__/usr/bin:./__debs__/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games",
        PWD               "/task",
        SHELL             "/bin/sh",
        SUDO_COMMAND      "/usr/bin/ruby run.rb --sleep 60 -e production -n 1 -j /mnt/iron-jail",
        SUDO_GID          1000,
        SUDO_UID          1000,
        SUDO_USER         "ubuntu",
        TERM              "unknown",
        USER              "nobody",
        USERNAME          "root"
    }
    Arguments: {
        -d         "/task/",
        -e         "production",
        -id        "5277ca9ed16f93360109d0aa",
        -payload   "/task/task_payload.json"
    }
    Payload (/task/task_payload.json): \ {
        tags   [
            [0] "iron.io",
            [1] "perl"
        ]
    }

    Top users for tag 'iron.io':
    AnaelFavre: 417
    thousandsofthem: 446
    Travis R: 6935

    Top users for tag 'perl':
    ikegami: 106098
    mpapec: 10324
    TLP: 40585

    Done.
</code></pre>

<h2>But, but..</h2>

<p>Of course, this example is not very useful, manually scheduling tasks and getting results from calling <code>iron_worker log &lt;id&gt;</code> is not really something interesting :&ndash;)</p>

<p>To be useful it would need to be automatically triggered by some event and produce usable results (updating a databse, notifying another service, etc..) but I assume you already know this if you&rsquo;re searching for how to run perl on IronWorker.</p>

<p>So, go crazy and drop me a hello on the comments bellow if this post was somehow helpful.</p>

<p>Cheers! \o/</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[dns and ptr records quick notes]]></title>
    <link href="http://blog.carloslima.name/blog/2013/10/18/dns-and-ptr-records-quick-notes/"/>
    <updated>2013-10-18T03:18:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2013/10/18/dns-and-ptr-records-quick-notes</id>
    <content type="html"><![CDATA[<p>Every once in a blue moon I get to troubleshoot, help someone with or explain how reverse dns works but somehow it keeps getting misplaced inside my brain.</p>

<p>So, for my future self, here it is:</p>

<p>As example, lets pick github&rsquo;s IP.</p>

<pre><code>[carlos@multi ~]$ host github.com
github.com has address 192.30.252.129
</code></pre>

<p>The key thing to remember is that it is the same as forward dns, just on a &ldquo;funny&rdquo; zone name.</p>

<p>In our example, the reverse dns record is: <code>129.252.30.192.in-addr.arpa</code><br/>
(and the zone <code>252.30.192.in-addr.arpa</code>)</p>

<h2>Find the authority over that zone:</h2>

<pre><code>[carlos@multi ~]$ dig 129.252.30.192.in-addr.arpa

; &lt;&lt;&gt;&gt; DiG 9.8.1-P1 &lt;&lt;&gt;&gt; 129.252.30.192.in-addr.arpa
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 21414
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;129.252.30.192.in-addr.arpa.   IN      A

;; AUTHORITY SECTION:
252.30.192.in-addr.arpa. 60     IN      SOA     ns1.p16.dynect.net. ops.github.com. 7 3600 600 604800 60

;; Query time: 72 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri Oct 18 03:25:41 2013
;; MSG SIZE  rcvd: 113
</code></pre>

<h2>Get the PTR record for that ip:</h2>

<pre><code>[carlos@multi ~]$ dig PTR 129.252.30.192.in-addr.arpa

; &lt;&lt;&gt;&gt; DiG 9.8.1-P1 &lt;&lt;&gt;&gt; PTR 129.252.30.192.in-addr.arpa
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 29787
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;129.252.30.192.in-addr.arpa.   IN  PTR

;; ANSWER SECTION:
129.252.30.192.in-addr.arpa. 3189 IN    PTR ip1b-lb3-prd.iad.github.com.

;; Query time: 29 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri Oct 18 03:28:44 2013
;; MSG SIZE  rcvd: 86
</code></pre>

<h3>Directly from authority</h3>

<p>And if you&rsquo;re trying to troubleshoot whether your ISP correctly updated the PTR records you requested, you can ask the authority directly and avoid waiting for propagation:</p>

<pre><code>[carlos@multi ~]$ dig PTR 129.252.30.192.in-addr.arpa @ns1.p16.dynect.net

; &lt;&lt;&gt;&gt; DiG 9.8.1-P1 &lt;&lt;&gt;&gt; PTR 129.252.30.192.in-addr.arpa @ns1.p16.dynect.net
;; global options: +cmd
;; Got answer:
;; -&gt;&gt;HEADER&lt;&lt;- opcode: QUERY, status: NOERROR, id: 51495
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;129.252.30.192.in-addr.arpa.   IN      PTR

;; ANSWER SECTION:
129.252.30.192.in-addr.arpa. 3600 IN    PTR     ip1b-lb3-prd.iad.github.com.

;; AUTHORITY SECTION:
252.30.192.in-addr.arpa. 86400  IN      NS      ns1.p16.dynect.net.
252.30.192.in-addr.arpa. 86400  IN      NS      ns3.p16.dynect.net.
252.30.192.in-addr.arpa. 86400  IN      NS      ns2.p16.dynect.net.
252.30.192.in-addr.arpa. 86400  IN      NS      ns4.p16.dynect.net.

;; Query time: 476 msec
;; SERVER: 2001:500:90:1::16#53(2001:500:90:1::16)
;; WHEN: Fri Oct 18 03:31:39 2013
;; MSG SIZE  rcvd: 172
</code></pre>

<h2>Just simple resolution</h2>

<p>Now, for completeness sake, if all you want is the reverse dns, remember that <code>host</code> works on both ip and name.</p>

<pre><code>[carlos@multi ~]$ host github.com
github.com has address 192.30.252.130
github.com mail is handled by 30 ASPMX3.GOOGLEMAIL.com.
github.com mail is handled by 30 ASPMX2.GOOGLEMAIL.com.
github.com mail is handled by 20 ALT1.ASPMX.L.GOOGLE.com.
github.com mail is handled by 10 ASPMX.L.GOOGLE.com.
github.com mail is handled by 20 ALT2.ASPMX.L.GOOGLE.com.
[carlos@multi ~]$ host 192.30.252.130
130.252.30.192.in-addr.arpa domain name pointer ip1c-lb3-prd.iad.github.com.
[carlos@multi ~]$ 
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[git submodules: how (not) to use it.]]></title>
    <link href="http://blog.carloslima.name/blog/2013/10/16/git-submodules-how-not-to-use-it/"/>
    <updated>2013-10-16T01:35:00+08:00</updated>
    <id>http://blog.carloslima.name/blog/2013/10/16/git-submodules-how-not-to-use-it</id>
    <content type="html"><![CDATA[<h1>Intro (or What&rsquo;s a git submodule?)</h1>

<p>On our system, /dev/SuperFoo/sub-bar is a submodule of SuperFoo.git repository.</p>

<pre><code>carlos@carlosdev /d/SuperFoo (master)&gt; git log -1
commit c2abbad057a02a2bd0d7c1e1c74048da6ef88234
Author: Chuck Norris &lt;chuck@example.com&gt;
Date:   Thu Oct 10 02:35:16 2013 +0000

    Updated to latest translation
</code></pre>

<p>&nbsp;</p>

<pre><code>carlos@carlosdev /d/SuperFoo (master)&gt; cd sub-bar
carlos@carlosdev /d/S/sub-bar ((2279a91))&gt; git log -1
commit 2279a9187b023f79cf274f52a76fe5059f119914
Merge: fc57e1a a3110e8
Author: Chuck Norris &lt;chuck@example.com&gt;
Date:   Thu Oct 10 02:24:15 2013 +0000

    Merge branch 'master' into currenttranslations
</code></pre>

<h1>so what?</h1>

<p>They are disconnected, despite being shown/accessible as a regular subdirectory of your main project.</p>

<h2>again?</h2>

<pre><code>carlos@carlosdev /d/SuperFoo (master)&gt; vi sub-bar/templates/home/login.html.haml cgi/fooish.cgi
..(change change change)..
carlos@carlosdev /d/SuperFoo (master)&gt; git status

# On branch master
# Changes not staged for commit:
#   (use "git add &lt;file&gt;..." to update what will be committed)
#   (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#       modified:   sub-bar (modified content)
#       modified:   cgi/fooish.cgi
#
no changes added to commit (use "git add" and/or "git commit -a")
</code></pre>

<p>sub-bar/ files <em>are not</em> part of your repository!</p>

<p>Look again:</p>

<pre><code>carlos@carlosdev /d/SuperFoo (master)&gt; git diff
diff --git a/sub-bar b/sub-bar
--- a/sub-bar
+++ b/sub-bar
@@ -1 +1 @@
-Subproject commit 2279a9187b023f79cf274f52a76fe5059f119914
+Subproject commit 2279a9187b023f79cf274f52a76fe5059f119914-dirty
diff --git a/cgi/fooish.cgi b/cgi/fooish.cgi
index c607f79..2b1ce17 100755
--- a/cgi/fooish.cgi
+++ b/cgi/fooish.cgi
@@ -1,4 +1,3 @@
-#!/usr/bin/perl

 use strict;
 use warnings;
carlos@carlosdev /d/SuperFoo (master)&gt; 
</code></pre>

<h1>Ok, got it. But what&rsquo;s the deal? (or, What could possibly go wrong?)</h1>

<p>This <em>happened</em> before, more than once. Not hypothetical.</p>

<pre><code>carlos@carlosdev /d/SuperFoo (bugfixes)&gt; git status
# On branch bugfixes
# Your branch is behind 'origin/bugfixes' by 1813 commits, and can be fast-forwarded.
#
nothing to commit (working directory clean)

carlos@carlosdev /d/SuperFoo (bugfixes)&gt; git rebase -p
Successfully rebased and updated refs/heads/bugfixes.
</code></pre>

<p>All good. Let&rsquo;s go fix our ticket!</p>

<pre><code>carlos@carlosdev /d/SuperFoo (bugfixes)&gt; vi lib/README.txt 
carlos@carlosdev /d/SuperFoo (bugfixes)&gt; git diff
diff --git a/sub-bar b/sub-bar
index 8b6fa45..eac1423 160000
--- a/sub-bar
+++ b/sub-bar
@@ -1 +1 @@
-Subproject commit 8b6fa45a258e37293d472c81844a3c37e921b6f9
+Subproject commit eac1423fcb1812e0ff958712231dddc06687733c
diff --git a/lib/README.txt b/lib/README.txt
index 293a71f..e9a6e01 100644
--- a/lib/README.txt
+++ b/lib/README.txt
@@ -1,4 +1,4 @@
 This directory holds shared code between all sub-projects. Please keep it clean.

-See https://internal.example.com/wiki/code-rules
+See https://example.thirdparty-inthecloud.net/wiki/code-rules
</code></pre>

<p>Looks good, simple enough.</p>

<pre><code>carlos@carlosdev /d/SuperFoo (bugfixes)&gt; git commit -am 'Fix wrong url'
[bugfixes 9ecfc7d] Fix wrong url
 2 files changed, 2 insertions(+), 2 deletions(-)
</code></pre>

<p>Cheers! We just rolled back sub-bar by 1 month.</p>

<pre><code>carlos@carlosdev /d/S/sub-bar ((eac1423))&gt; git log -1 8b6fa45a258e37293d472c81844a3c37e921b6f9
commit 8b6fa45a258e37293d472c81844a3c37e921b6f9
Author: Michelle Yeoh &lt;mi@example.com&gt;
Date:   Thu Oct 3 11:52:38 2013 +0000

    Translated using Weblate (Portuguese)

    Currently translated at 100.0% (448 of 448 strings)
</code></pre>

<p>&nbsp;</p>

<pre><code>carlos@carlosdev /d/S/sub-bar ((eac1423))&gt; git log -1 eac1423fcb1812e0ff958712231dddc06687733c
commit eac1423fcb1812e0ff958712231dddc06687733c
Author: Angelina Jolie &lt;angie@example.com&gt;
Date:   Mon Sep 2 02:10:57 2013 +0000

    Tidy
</code></pre>

<p>Next time bugfixes gets released, the version of sub-bar in production will be from 1 month ago.</p>

<p>Not just minor changes..</p>

<pre><code>carlos@carlosdev /d/S/sub-bar ((eac1423))&gt; git diff --stat eac1423..8b6fa45
.. snip ..
78 files changed, 5871 insertions(+), 1435 deletions(-)
</code></pre>

<h1>Why did that happen?</h1>

<p>Because it is a separate repository, git only tracks three things about the submodule:</p>

<ul>
<li>url of the external repository</li>
<li>path where the files will be put/cloned</li>
<li>the commit id from that repository that you want to use.</li>
</ul>


<p>They are:</p>

<pre><code>carlos@carlosdev /d/SuperFoo (bugfixes)&gt; cat .gitmodules
[submodule "sub-bar"]
    path = sub-bar
    url = git@bitbucket.org:exampledotcom/sub-bar.git

carlos@carlosdev /d/SuperFoo (bugfixes)&gt; git ls-tree bugfixes
..snip..
100644 blob 2d918f0b794c059d6900e7211cd34e22aa395a77    Makefile   ← file
040000 tree 486d5dafd1d4fd7ff4f8cf3b273d5912e84666ae    api        ← directory
160000 commit eac1423fcb1812e0ff958712231dddc06687733c  sub-bar    ← submodule (commit id to use)
..snip..
</code></pre>

<p>When we did the rebase, the changes included updates to the version of sub-bar that the SuperFoo repository should be using.<br/>
But git <em>DOES NOT</em> checkout that new version inside the sub-bar directory.</p>

<p>Git knows we should be using commit 8b6fa45<br/>
But on sub-bar directory we have eac1423 (from before the rebase)</p>

<p>It doesn&rsquo;t know (or care) if the commits are newer, older, etc.<br/>
So, when we did <code>git commit -am'...'</code> without paying attention to that sub-bar mention that appeared on <code>git diff</code> or <code>git status</code>, we told git that we want it to use commit eac1423, which is what we have checked out at the moment.</p>

<h1>This is really confusing. I don&rsquo;t care about sub-bar and I&rsquo;m not touching it, how do I avoid breaking things?</h1>

<p>First and foremost, when <code>git status</code> or <code>git diff</code> shows sub-bar, <em>do not ignore it</em>.</p>

<p>The root cause is that when you move your repository to a different state, git won&rsquo;t automatically move the submodule to the new expected commit.<br/>
So we fix it with <code>git submodule update</code>.</p>

<p>The name might be counter-intuitive, but <code>git submodule update</code> doesn&rsquo;t change/write/commit/push the submodule, it just runs a checkout of the expected commit.</p>

<p>Second, don&rsquo;t <code>git add sub-bar</code>;<br/>
(Unless updating the submodule to a new version is what you&rsquo;re trying to do.)</p>

<h2>Caveats</h2>

<h3>Bitbucket</h3>

<p>Bitbucket (as of 2013-10-10) won&rsquo;t show changes to submodules on their diff.<br/>
That means reviewers won&rsquo;t be able to see that you made a mistake!</p>

<h3>git commit -a / git commit .</h3>

<p>Please, don&rsquo;t do it. Ever.<br/>
This will happily commit every change you have on disk.<br/>
It is an horrible practice, much more dangerous when submodules are involved.<br/>
Always review your changes with <code>git status</code> and <code>git diff</code>.<br/>
Don&rsquo;t commit anything you didn&rsquo;t mean to.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[method_missing and respond_to?: doing it properly]]></title>
    <link href="http://blog.carloslima.name/2010/03/methodmissing-and-respondto-doing-it.html"/>
    <updated>2010-03-09T00:00:00+08:00</updated>
    <id>http://blog.carloslima.name/2010/03/method-missing-and-respond-to-doing-it-properly</id>
    <content type="html"><![CDATA[<p>Sometime ago while using <code>method_missing</code> to implement some functionality I got the weird behavior that it would work only
<em>most</em> of the time but not always.<br/>
In retrospect it&rsquo;s now pretty obvious but in the heat of the moment it took me about half a day of investigation and talking
before I figured it out.</p>

<p>What happened is that I did only half of the work.<br/>
I defined <code>method_missing</code> but I forgot to define <code>respond_to?</code> accordingly.<br/>
The result is that it worked when I called it directly on the instance, but failed if an association was involved.</p>

<p>To give an example, say you have a class like this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">A</span> <span class="o">&lt;</span> <span class="ss">ActiveRecord</span><span class="p">:</span><span class="ss">:Base</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">example</span>
</span><span class='line'>    <span class="kp">true</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">def</span> <span class="nf">method_missing</span><span class="p">(</span><span class="nb">method</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
</span><span class='line'>    <span class="k">if</span> <span class="nb">method</span><span class="o">.</span><span class="n">to_s</span> <span class="o">=~</span> <span class="sr">/example/</span>
</span><span class='line'>      <span class="n">example</span>
</span><span class='line'>    <span class="k">else</span>
</span><span class='line'>      <span class="k">super</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>Calling <em>example</em> directly on your instance works just fine.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='irb'><span class='line'><span class="gp">&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">my_example</span>
</span><span class='line'><span class="go">=&gt; true</span>
</span><span class='line'>
</span><span class='line'><span class="gp">&gt;&gt; </span><span class="n">A</span><span class="o">.</span><span class="n">create!</span><span class="o">.</span><span class="n">example_me?</span>
</span><span class='line'><span class="go">=&gt; true</span>
</span></code></pre></td></tr></table></div></figure>


<p>All fine, but as soon as you get an association in the middle of things:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">B</span> <span class="o">&lt;</span> <span class="ss">ActiveRecord</span><span class="p">:</span><span class="ss">:Base</span>
</span><span class='line'>  <span class="n">belongs_to</span> <span class="ss">:a</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>It just doesn&rsquo;t go well anymore:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class='irb'><span class='line'><span class="gp">&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">B</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">:a</span><span class="o">=&gt;</span><span class="n">A</span><span class="o">.</span><span class="n">new</span><span class="p">)</span>
</span><span class='line'><span class="go">=&gt; #&lt;B id: nil, a_id: nil, created_at: nil, updated_at: nil&gt;</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="gp">&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">example?</span>
</span><span class='line'><span class="go">NoMethodError: undefined method example?&#39; for #&lt;A id: nil, created_at: nil, updated_at: nil&gt;</span>
</span><span class='line'><span class="go"> from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:220:inmethod_missing’</span>
</span><span class='line'><span class="go">from (irb):55</span>
</span><span class='line'>
</span><span class='line'><span class="gp">&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">B</span><span class="o">.</span><span class="n">create!</span><span class="p">(</span><span class="ss">:a</span><span class="o">=&gt;</span><span class="n">A</span><span class="o">.</span><span class="n">create!</span><span class="p">)</span>
</span><span class='line'><span class="go">=&gt; #&lt;B id: 4, a_id: 7, created_at: “2010-03-08 21:15:01”, updated_at: “2010-03-08 21:15:01”&gt;</span>
</span><span class='line'><span class="gp">&gt;&gt; </span><span class="n">b</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">failing_example</span>
</span><span class='line'><span class="go">NoMethodError: undefined method failing_example&#39; for #&lt;ActiveRecord::Associations::BelongsToAssociation:0xb70491d0&gt;</span>
</span><span class='line'><span class="go"> from /var/lib/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:220:inmethod_missing’</span>
</span><span class='line'><span class="go">from (irb):57</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now, this last error is a bit clearer but I don&rsquo;t remember running into it at the time.<br/>
If I had just followed the association_proxy:220 hint right away&hellip; ;)</p>

<p>What happens is that <code>b.a</code> doesn&rsquo;t return the instance but rather an <a href="http://apidock.com/rails/ActiveRecord/Associations/AssociationProxy">AssociationProxy</a> instance that provides ActiveRecord&rsquo;s
extended functionality and this proxy relies on <code>A#respond_to?</code> to correctly forward method calls to the actual instance.</p>

<p>What I should have done is:<br></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">A</span> <span class="o">&lt;</span> <span class="ss">ActiveRecord</span><span class="p">:</span><span class="ss">:Base</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">example</span>
</span><span class='line'>    <span class="kp">true</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">def</span> <span class="nf">method_missing</span><span class="p">(</span><span class="nb">method</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
</span><span class='line'>    <span class="k">if</span> <span class="nb">method</span><span class="o">.</span><span class="n">to_s</span> <span class="o">=~</span> <span class="sr">/example/</span>
</span><span class='line'>      <span class="n">example</span>
</span><span class='line'>    <span class="k">else</span>
</span><span class='line'>      <span class="k">super</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">def</span> <span class="nf">respond_to?</span><span class="p">(</span><span class="nb">method</span><span class="p">,</span> <span class="n">include_private</span> <span class="o">=</span> <span class="kp">false</span><span class="p">)</span>
</span><span class='line'>    <span class="k">if</span> <span class="nb">method</span><span class="o">.</span><span class="n">to_s</span> <span class="o">=~</span> <span class="sr">/example/</span>
</span><span class='line'>      <span class="kp">true</span>
</span><span class='line'>    <span class="k">else</span>
</span><span class='line'>      <span class="k">super</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='irb'><span class='line'><span class="gp">&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">create!</span><span class="p">(</span><span class="ss">:a</span><span class="o">=&gt;</span><span class="n">A</span><span class="o">.</span><span class="n">create!</span><span class="p">)</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">example?</span>
</span><span class='line'><span class="go">=&gt; true</span>
</span><span class='line'><span class="gp">&gt;&gt; </span><span class="n">B</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">:a</span><span class="o">=&gt;</span><span class="n">A</span><span class="o">.</span><span class="n">new</span><span class="p">)</span><span class="o">.</span><span class="n">a</span><span class="o">.</span><span class="n">failing_example</span>
</span><span class='line'><span class="go">=&gt; true</span>
</span></code></pre></td></tr></table></div></figure>


<p>There are some much better write-ups on this topic, if you want to read more:</p>

<ul>
<li><a href="http://technicalpickles.com/posts/using-method_missing-and-respond_to-to-create-dynamic-methods/">Using method_missing and respond_to? to create dynamic methods</a></li>
<li><a href="http://coderrr.wordpress.com/2008/07/11/solving-the-method_missing-respond_to-problem/">Solving the method_missing/respond_to? problem</a></li>
</ul>


<p>Now, I must be honest here: what I was doing was a <strong>big</strong> code smell :)<br/>
It taught me the lesson to use method_missing properly and was even quite fun to debug and all that but what I really needed and
end up doing in that case was a group of <a href="http://apidock.com/rails/Module/delegate">delegates</a> here and there and voilà, it was all cool and clean.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Solutionatic Pair Programming]]></title>
    <link href="http://blog.carloslima.name/2010/03/solutionatic-pair-programming.html"/>
    <updated>2010-03-02T00:00:00+08:00</updated>
    <id>http://blog.carloslima.name/2010/03/solutionatic-pair-programming</id>
    <content type="html"><![CDATA[<div class='post'>
<h1>Remote Pair Programming</h1>A few weeks ago, <a href="http://www.knowing.net">Larry O&#8217;Brien</a> and I set out to experiment with Remote Pair Programming.<br />He wrote about it on his SDTimes column: <a href="http://www.sdtimes.com/WINDOWS__NET_WATCH_PROBLEMATIC_PAIR_PROGRAMMING/By_Larry_O_Brien/About_EXTREMEPROGRAMMING/34158">Windows & .NET Watch: Problematic pair programming</a><br /><br />We both liked the experience and would be rather happy to be able to work on a long term project that way (anyone hiring a remote pair?), but since his column gives more emphasis to the down sides, I thought I could write my point of view which is more on the up side ;)<br /><br />In general, I agree on the down sides but I got so excited with the advantages I saw that I would barely remember mentioning the problems if asked.<br /><br /><h2>The focus</h2><br />Working in pair forces you to focus on the work.<br />There is just no way you can be there and not be paying attention to whatever it is that you&#8217;re supposed to do.<br />You get so focused in the work and the communication that the environmental noise that would otherwise annoy you just seem to disappear.<br />The speed in which you make progress can vary with a lot of factors but you are *guaranteed* to make some progress. All. The. Time.<br /><br /><h2>The challenge</h2><br />The fact that someone is watching your every step means that you keep challenging yourself to do things the best way you can.<br />You just can&#8217;t look sloppy to your pair.<br />That means you avoid cutting corners or knowingly doing the wrong thing out of laziness or &#8220;to fix it later&#8221;.<br />If you do something that feels wrong, you&#8217;ll be called on it and have to defend your point, so, unless it&#8217;s worth the trouble, you just work a bit harder and go for the right thing.<br /><br /><h2>The safety feeling</h2><br />You certainly feel more confident about every line of code you write.<br />Anything absurdly wrong will surely get catch by one or the other.<br />Even the small errors or typos get spotted really fast.<br />Sure, things can still be wrong, bugged or bad designed but the fact that the code was co-created and reviewed by at least one more person gives you a comforting feeling.<br /><br /><h2>The learning</h2><br />Working with someone else full time means you&#8217;re continuously learning or at least exercising a different approach than your own.<br />You learn new tricks.<br />You get to defend your points.<br />And you question everything.<br />At the end of the day, you feel actively improving in many things.<br />Even your English, if you&#8217;re not a native speaker ;)<br /><br /><h2>The loneliness</h2><br />Working remotely means you&#8217;re almost always alone.<br />When your clients are in different countries, thousands of miles away, that&#8217;s guaranteed.<br />It&#8217;s just too expensive, time consuming and a tiresome task to travel for a meeting.<br />If there is something I miss every now and then it&#8217;s having someone at close reach that I can share work stuff and work together.<br />Working in a pair was a comforting step in that direction.<br /><br /><h2>The results</h2><br />We shared the resulting project on Github.<br />If you&#8217;d like to poke around, it&#8217;s available at <a href="http://github.com/carloslima/pasteme">http://github.com/carloslima/pasteme</a><br /><br />Overall, I consider it was a big win over the solo experience.<br />There is only one thing that could be much better and that&#8217;s the IDE/Tools support.<br />While sharing a VM using VNC mostly worked, it didn&#8217;t come close to the experience you get when you use Saros, Bespin or even Google Wave.<br />Being able to use all your monitors, drag windows around and organize it the way you like better would definitely improve the experience.<br /><br />Have a different opinion or want to suggest a different tool?<br />Just drop me a comment!</div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[RSnapshot-style backups on Dreamhost]]></title>
    <link href="http://blog.carloslima.name/2010/03/rsnapshot-style-backups-on-dreamhost.html"/>
    <updated>2010-03-02T00:00:00+08:00</updated>
    <id>http://blog.carloslima.name/2010/03/rsnapshot-style-backups-on-dreamhost</id>
    <content type="html"><![CDATA[<div class='post'>
<h1>DHSnapshot</h1>A while ago I needed to find a good setup for backing up some machines.<br /><br />I wanted to use <a href="http://samba.anu.edu.au/rsync/">RSync</a> to do <a href="http://www.mikerubel.org/computers/rsync_snapshots/">snapshots-like backups</a>.<br /><br />This setup is:<br />* Off-site<br />* Storage efficient (the bulk of my backup was unlikely to ever change)<br />* Network efficient (only transfer changed files)<br />* Keeps versions going back a few months<br /><br />Now, <a href="http://www.dreamhost.com">DreamHost</a> offers 50GB of free space for personal backups and that seemed a good fit for this particular situation.<br /><br />Then I found <a href="http://rsnapshot.org/">RSnapshot</a> and it was exactly what I needed.<br />Unfortunately, RSnapshot doesn&#8217;t backup to an external server. <br />It&#8217;s meant to work in a setup where the server hosting the backups connects to your data sources and pull the files.<br />That totally makes sense and is probably the best setup but it wouldn&#8217;t work for me.<br /><br />DreamHost doesn&#8217;t have RSnapshot installed on their backup servers and the only access users have to that machine is SFTP and RSync. <br />I needed something that would work with just that.<br /><br />I came across a post about <a href="http://blog.wangling.me/2009/07/meta-backup-dreamhost-on-dreamhost-backups/">backing up DreamHost websites to DreamHost Backups</a> that showed a workaround to the lack of SSH access to the backups service.<br /><br />So I took the idea, mixed it up with the stuff I wanted from RSnapshot and wrote a small perl script to do it.<br /><br />It&#8217;s called <a href="http://github.com/carloslima/dhsnapshot">dhsnapshot</a> and is published at GitHub: <a href="http://github.com/carloslima/dhsnapshot">http://github.com/carloslima/dhsnapshot</a> <br /><br />At this moment, it&#8217;s not very flexible: it&#8217;s hardwired to keep 7 daily, 4 weekly and 6 monthly backups and it&#8217;s also limited to a single backup source (you can only point it to one source directory)<br />But it&#8217;s not hard to change, or even make it configurable.<br />I might do it if I ever get the need or motivation :)<br /><br />One way or the other, it should be reasonably simple to setup (<a href="http://github.com/carloslima/dhsnapshot#readme">instructions on GitHub</a>).<br /><br />I&#8217;d be glad to know if it helped anyone.<br />So, please, drop me a comment if you fnd it useful.</div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Hosting your GIT repository on DreamHost]]></title>
    <link href="http://blog.carloslima.name/2010/02/hosting-your-git-repository-on.html"/>
    <updated>2010-02-25T00:00:00+08:00</updated>
    <id>http://blog.carloslima.name/2010/02/hosting-your-git-repository-on-dreamhost</id>
    <content type="html"><![CDATA[<p>A few weeks ago I needed a private remote <a href="http://git-scm.com">Git</a> repository.<br/>
Since I already have a <a href="http://www.dreamhost.com">DreamHost</a> account, I didn&rsquo;t want to pay for <a href="http://github.com">GitHub</a> just to be able to set my repository as private.</p>

<p>DreamHost does not officially support Git on their Web Panel, so you must set things up manually.</p>

<p>There is a <a href="http://wiki.dreamhost.com/Git">Git entry on their Wiki</a> but it looked a bit messy, so I decided to write a cleaner tutorial.</p>

<p>Keep in mind that I&rsquo;m using <a href="http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt">WebDAV</a>.<br/>
It allows more than one user to push to the same repository, but it&rsquo;s also slower.</p>

<blockquote><p>You can use SSH but it&rsquo;s a lot more complex to setup.<br>
If that&rsquo;s what you want, read the <a href="http://wiki.dreamhost.com/Git#Setup_Three">DreamHost Wiki</a>.</p></blockquote>

<h2>Setup a WebDAV folder</h2>

<p>Login to <a href="https://panel.dreamhost.com/">DreamHost Web Panel</a><br/>
Go to <a href="https://panel.dreamhost.com/index.cgi?tree=goodies.webdav">Goodies &ndash;&gt; Htaccess/WebDAV</a><br/>
Select the domain name you want to use<br/>
Click &ldquo;Set Up A New Directory&rdquo;</p>

<p><img src="http://blog.carloslima.name/images/hosting-your-git-repository-on-dreamhost/dh-webpanel.png" alt="DH Panel/WebDAV" /></p>

<h2>Create the remote repository</h2>

<p>Git cannot create the remote repository, it only operates on existing ones, so we need to create an empty repository locally and
manually upload it to DreamHost.</p>

<p>So, there we go, open a console and..</p>

<pre><code>carlos@ubuntu:~/dev$ mkdir blank.git
carlos@ubuntu:~/dev$ cd blank.git/
carlos@ubuntu:~/dev/blank.git$ git --bare init
Initialized empty Git repository in /home/carlos/dev/blank.git/
carlos@ubuntu:~/dev/blank.git$ touch git-daemon-export-ok
carlos@ubuntu:~/dev/blank.git$ git --bare update-server-info
carlos@ubuntu:~/dev/blank.git$ mv hooks/post-update.sample hooks/post-update
carlos@ubuntu:~/dev/blank.git$
</code></pre>

<h3>Upload the blank repository and rename it</h3>

<p>Use Nautilus or any other file manager that supports WebDAV to upload blank.git to Dreamhost and rename it to something
meaningful. For the purpose of this example, let&rsquo;s call it project.git</p>

<p>On Ubuntu:</p>

<p><img src="http://blog.carloslima.name/images/hosting-your-git-repository-on-dreamhost/places-connect.png" alt="Places-&gt;Connect" /><br/>
<img src="http://blog.carloslima.name/images/hosting-your-git-repository-on-dreamhost/connect-to-server.png" alt="Places-&gt;Connect" /><br/>
<img src="http://blog.carloslima.name/images/hosting-your-git-repository-on-dreamhost/copy-files.png" alt="Places-&gt;Connect" /><br/>
<img src="http://blog.carloslima.name/images/hosting-your-git-repository-on-dreamhost/copy-files2.png" alt="Places-&gt;Connect" /></p>

<p>After it finishes uploading, rename the folder from blank.git to project.git</p>

<blockquote><p>When I renamed the file, I got an error message saying it failed, but refreshing showed it actually worked.</p></blockquote>

<h2>Ready!</h2>

<p>If you&rsquo;re starting fresh and all you need is a blank repository, then you&rsquo;re set.<br/>
Just clone your repository and start working!</p>

<pre><code>carlos@ubuntu:~/dev$ git clone http://bob@www.example.com/git/project.git
Initialized empty Git repository in /home/carlos/dev/project/.git/
Password:
warning: You appear to have cloned an empty repository.

carlos@ubuntu:~/dev$ cd project
carlos@ubuntu:~/dev/project$ (work, work, work)
carlos@ubuntu:~/dev/project$ git add README
carlos@ubuntu:~/dev/project$ git commit -m "your commit message"
[master (root-commit) 5bbe5f6] your commit message
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
carlos@ubuntu:~/dev/project$ git push origin master
Password:
Fetching remote heads...
refs/
refs/tags/
refs/heads/
updating 'refs/heads/master'
from 0000000000000000000000000000000000000000
to 5bbe5f6507fa39293bdc9674ca4ae2e0a1d2f15e
sending 3 objects
done
Updating remote server info

carlos@ubuntu:~/dev/project$ git pull
Password:
From http://bob@www.example.com/git/project
* [new branch] master -&amp;gt; origin/master
Already up-to-date.
carlos@ubuntu:~/dev/project (master)$
</code></pre>

<h2>Optional: Push your project repository to DreamHost</h2>

<p>Otherwise, if you already have a project repository that you&rsquo;ve been working locally, now is the time to push it to
DreamHost.</p>

<p>Instead of cloning the new repository, push your project there first:</p>

<pre><code>carlos@ubuntu:~/dev$ cd real_project/
carlos@ubuntu:~/dev/real_project$ git config remote.upload.url http://bob@www.example.com/git/project.git/

  # It is important to put the last '/'; Without it, the server will send a redirect which git-http-push
  # does not (yet) understand, and git-http-push will repeat the request infinitely.

carlos@ubuntu:~/dev/real_project$ git push upload master
Password:
Fetching remote heads...
refs/
refs/tags/
refs/heads/
updating 'refs/heads/master'
from 0000000000000000000000000000000000000000
to a10703d8e400ca9df1b19345975718935c083905
sending 107 objects
done
Updating remote server info
carlos@ubuntu:~/dev/real_project$
</code></pre>

<p>Then confirm it worked and start fresh by cloning it.</p>

<pre><code>carlos@ubuntu:~/dev/real_project$ cd ..
carlos@ubuntu:~/dev$ git clone http://bob@www.example.com/git/project.git/
Initialized empty Git repository in /home/carlos/dev/project/.git/
Password:
got a10703d8e400ca9df1b19345975718935c083905
walk a10703d8e400ca9df1b19345975718935c083905
got 574596c4cc435461515aa1a4c3cdd0e93af947f3
got 067f993be7432ac27e8a6e9636dea53dcc3d8632
got 475be0881778acd2de7404175fa323823e4d1ac0
walk 067f993be7432ac27e8a6e9636dea53dcc3d8632
(...)
got b7b5d32db9dd30c9ea28434b125781eb4a3e95b2

carlos@ubuntu:~/dev$ cd project/
carlos@ubuntu:~/dev/project$ git log --oneline
a10703d Adds a beautiful whitespace! :)
067f993 Adds project description.. or sort of
80c2e22 removes rerun.txt
07e3cd2 Initial commit

carlos@ubuntu:~/dev/project$ git pull
Password:
Already up-to-date.

carlos@ubuntu:~/dev/project$ git push origin master
Password:
Fetching remote heads...
refs/
refs/tags/
refs/heads/
'refs/heads/master': up-to-date
carlos@ubuntu:~/dev/project$
</code></pre>

<p>And you&rsquo;re good to resume working on your project :)</p>

<h2>Bonus: saving your WebDAV password</h2>

<p>Now, if you&rsquo;re thinking that typing the WebDAV password over and over again kind of suck, you can save it so that git won&rsquo;t ask
you anymore.</p>

<pre><code>carlos@ubuntu:~/dev$ echo "machine www.example.com login bob password secret" &gt;&gt; ~/.netrc
</code></pre>

<p>There is only one thing to keep in mind.
When you save your password like this, you need to drop the <code>bob@</code>
from the urls.<br/>
So, instead of referring to your repository as <code>http://bob@www.example.com/git/project.git/</code> you need to use just <code>http://www.example.com/git/project.git/</code><br/>
If you do this after you finished everything and cloned your repository, then git will have already saved the &ldquo;wrong&rdquo; url into
its config file and will keep asking you for the password.</p>

<p>To fix this you can either clone again using the correct url or fix git&rsquo;s config manually by doing:</p>

<pre><code>carlos@ubuntu:~/dev/project$ git config remote.origin.url http://www.example.com/git/project.git/
carlos@ubuntu:~/dev/project$
</code></pre>

<p>Now, just for reference :)</p>

<pre><code>carlos@ubuntu:~/dev$ more /etc/issue.net
Ubuntu 9.10
carlos@ubuntu:~/dev$ git --version
git version 1.6.3.3
carlos@ubuntu:~/dev$ date
Thu Feb 25 08:55:18 BRT 2010
carlos@ubuntu:~/dev$
</code></pre>
]]></content>
  </entry>
  
</feed>
