<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
    <title>Contentment</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/" />
    
    <id>tag:contentment.org,2008-03-23://3</id>
    <updated>2009-06-25T18:59:53Z</updated>
    <subtitle>The place where I get my geek on...</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>

<link rel="self" href="http://feeds.feedburner.com/Contentment" type="application/atom+xml" /><entry>
    <title>Weight Loss, My Way</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2009/06/weight-loss-my-way.html" />
    <id>tag:contentment.org,2009://3.662</id>

    <published>2009-06-25T17:24:04Z</published>
    <updated>2009-06-25T18:59:53Z</updated>

    <summary>Disclaimer: IANAD: I AM NOT A DOCTOR. Please consult one prior to engaging in any attempt at weight loss. I provide no recommendation you do things my way and take no responsibility for your health. Disclaimer 2: I am not...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p><strong>Disclaimer:</strong> <em>IANAD: I AM NOT A DOCTOR. Please consult one prior to engaging in any attempt at weight loss. I provide no recommendation you do things my way and take no responsibility for your health.</em></p>

<p><strong>Disclaimer 2:</strong> <em>I am not affiliated with, have never given money to, and have no relationship at all with the <strong>Unnamed Diet System</strong> I have based my diet plan upon. I do not recommend for or against their system, I am just sharing the fact that I my own variation of it and have had success.</em></p>

<p>Since my birthday this year, I&#8217;ve been working to lose a little extra weight. I now weigh around what I did when I was in high school and am still losing. I did this to show solidarity with my wife who wanted to lose a bit, but I needed to do this for myself as well.</p>

<p>Wanting to lose weight presented a few problems for me. First, I can not stand to do what somebody else tells me to do. My wife calls that being &#8220;obstinate-defiant.&#8221; Depending on my mood I usually either say I&#8217;m just selfish or I have a built-in distrust of the crowd. In any case, it was clear that unless I could tweak my plan a bit, I wasn&#8217;t going to be be happy with it. I&#8217;ve ended up tweaking less than I thought I would, but I still can, so there.</p>

<p>My next problem is that I refuse to do cruel or unusual dieting. I&#8217;m not going in for any fad or diet that drastically changes things. I&#8217;m not giving up cookies or eating grapefruit or doing Adkins. Regardless of what science there is or is not backing these things up, anything that changes what I eat is going to make me grumpy. I <em>love</em> food and there is no shame in that. The shame comes in consistently eating more than I need. I also find the idea of using a pill or surgery repulsive (no offense to those who do such, I won&#8217;t). For me, this process is about developing self-control, which means I need to learn to do it and my wife provides enough accountability to that end.</p>

<p>While metabolism and other factors adjust a person&#8217;s dietary needs, failure to consume enough calories to maintain a person&#8217;s current weight will cause a reduction. (Unless, which I suppose is possible, a person&#8217;s body is somehow capable of storing fat, but incapable of using it. I don&#8217;t know if any such disease exists, but I don&#8217;t have it if it does, so it&#8217;s not my problem.) Therefore, my diet plan would have to be something as mundane as journaling what I eat.</p>

<p>Which brings up my next problem, counting calories is too easy and not really addressing the full magnitude of the problem. Because not only should I eat less, but I should encourage myself to eat healthier. The system ought to take other factors into account.</p>

<p>My final problem is that whatever it is I do must be something I can do on a computer. I sit in front of one for around 8-12 hours per day. I can set my computer to remind of things, I can share things between myself and my wife to provide accountability on my computer, and while I like writing down notes, particularly when I&#8217;m brainstorming, I really don&#8217;t want to do all the math we&#8217;re talking about in my head all the time. It&#8217;s too tedious.</p>

<p>Fortunately, my wife <a href="http://terri.hanenkamp.com/ww/">previously</a> went on and successfully completed a plan using <strong>Unnamed Diet System</strong> for which you may have seen ads. This system met all my basic requirements. Yet, other than they way they count points, they don&#8217;t provide any value to me, at least none I would pay for. Fortunately, everything I needed was published at various places on the Internet and I built myself a Google Docs spreadsheet to do it.</p>

<p>I provide a link to a version of it here for anyone interested in weight loss on similar terms. <em>Go re-read the disclaimers again now.</em> I&#8217;ll wait&#8230; Done? Okay, I don&#8217;t recommend this plan to you, but if you find the spreadsheet useful, great. I&#8217;m providing it under a <a href="http://creativecommons.org/licenses/by/3.0/us/">Creative Commons 3.0</a> license. </p>

<ul>
<li><a href="http://spreadsheets.google.com/ccc?key=rEBiFNc8PjWLNtjKepbm00g">Food Points Sheet</a></li>
</ul>

<p>If you have a Google account, you can create a copy of the spreadsheet to use it or you can download it in another format to use with Excel or OpenOffice (I think, haven&#8217;t tried that).</p>

<p>To use it, I first scroll right until I fill in some information about myself. This sets up the basic tolerances for my diet plan based upon sex, age, current weight, height, daily activity, etc. Then scroll back left and log my consumption. Under each meal, the wide column is for a description of the item eaten and the narrow for recording the points. Once I have &#8220;0&#8221; points left for the day, I stop eating. The spreadsheet does have a weekly allowance of extra points that I can use as well to indulge in something or just allow me to consume all the points for a day without worrying about going over by a couple. I use all the points I have for a day unless I&#8217;m really not hungry. This is not a starvation diet, so I try to use up as many of my daily points as possible. I do not worry too much about using or not using the weekly points. I often consume most of them.</p>

<p>The formula for calculating this points is simple, but elegant in that it encourages me to get more fiber and avoid fatty foods, while consuming fewer calories than I need to maintain my weight:</p>

<pre><code>Points = Calories / 50 + Fat (g) / 12 + MIN(Fiber (g) / 5, 1)
</code></pre>

<p>I&#8217;ve been told that <strong>Unnamed Diet System</strong> actually divides Fiber by 4, but whatever. I have embedded a couple calculators in the spreadsheet for the times when I&#8217;m too lazy to do the math in my head.</p>

<p>I weigh myself once a week to track my progress (on a separate spreadsheet).Every 10 pounds, I adjust the chart to the right since the spreadsheet gives one less point per day for each 10 pounds I lose. I also copy the spreadsheet (actually, Terri manages this part) each week and blank it out to use the next week.</p>

<p>Eventually, I should reach my goal weight (I haven&#8217;t really decided what that is). When that happens, I&#8217;ll need to adjust the spreadsheet to deal with maintenance. When that happens, I will give myself more points until my weight stabilizes. I plan to continue recording points for the foreseeable future this way.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Wascally Perl Operators</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2009/06/wascally-perl-operators.html" />
    <id>tag:contentment.org,2009://3.660</id>

    <published>2009-06-03T03:34:13Z</published>
    <updated>2009-06-03T04:03:58Z</updated>

    <summary>I just finished writing a test that discovered I’d made a rather dumb and (upon looking back) rather obvious mistake in a return value in this Perl application I’m working on. The mistake involves a certain errant combination of return...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I just finished writing a test that discovered I&#8217;d made a rather dumb and (upon looking back) rather obvious mistake in a return value in <a href="http://qublog.net">this Perl application</a> I&#8217;m working on. The mistake involves a certain errant combination of <code>return</code> and <code>and</code> must be dealt with carefully.</p>

<p>The particular bit of code looks something like this:</p>

<pre><code>sub blah {
    return $foo and $bar;
}
</code></pre>

<p>For those who don&#8217;t know Perl intimately, Perl has two &#8220;and&#8221; operators. One named &#8220;and&#8221; and the other named &#8220;&amp;&amp;&#8221; like C. These are not strict synonyms. They are both shortcut operators, but the &#8220;&amp;&amp;&#8221; and the &#8220;and&#8221; sit at very different places in the operator precedent order. In Perl &#8220;&amp;&amp;&#8221; has a relatively high precedent and &#8220;and&#8221; is very, very low.</p>

<p>Back to the problem: this return was returning true when <code>$foo</code> was true and <code>$bar</code> was false. After rereading this line I smacked my forehead and said, &#8220;Duh!&#8221; The problem is that &#8220;return&#8221; actually has a higher operator precedent than &#8220;and&#8221; so this is how Perl would break it out if it showed the AST with parenthesis:</p>

<pre><code>sub blah {
    (return $foo) and ($bar);
}
</code></pre>

<p>This means the code immediately return <code>$foo</code> in all circumstances. I might as well have just written:</p>

<pre><code>sub blah {
    return $foo;
}
</code></pre>

<p>The solution, then, is to either use the &#8220;&amp;&amp;&#8221; operator:</p>

<pre><code>sub blah {
    return $foo &amp;&amp; $bar;
}
</code></pre>

<p>Or use explicit parenthesis:</p>

<pre><code>sub blah {
    return ($foo and $bar);
}
</code></pre>

<p>Or don&#8217;t use the &#8220;return&#8221; operator (since subroutines in Perl always return the value of the last expression executed):</p>

<pre><code>sub blah {
    $foo and $bar;
}
</code></pre>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Converting from iTunes to Banshee</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2009/05/converting-from-itunes-to-bans.html" />
    <id>tag:contentment.org,2009://3.659</id>

    <published>2009-05-22T23:12:40Z</published>
    <updated>2009-06-02T20:17:17Z</updated>

    <summary>This past week I purchased for myself a mini laptop. I wanted something nice and portable that I could use for personal use on trips and do hobby projects on. This thing is great. I got Ubuntu installed and started...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>This past week I purchased for myself a mini laptop. I wanted something nice and portable that I could use for personal use on trips and do hobby projects on. This thing is great. I got Ubuntu installed and started playing around since it&#8217;s been a couple years since I had a Linux desktop, and even then I usually had a Mac OS X laptop I used with it. As such, when it came to copy over my music and such, I needed to convert to a new music player. I&#8217;ve settled on <a href="http://banshee-project.org/">Banshee</a> for the moment.</p>

<p><strong>Problem:</strong> There&#8217;s no import tool out there to go from iTunes to the current version of Banshee. </p>

<p><strong>Solution:</strong> However, the process turned out to be not so hard for me. Here&#8217;s what I did:</p>

<ol>
<li>Copied the iTunes music folder from my Mac to the music folder on my new laptop.</li>
<li>Started up Banshee and used Media > Import Media&#8230; to tell Banshee where to find all the files and let it do it&#8217;s thing.</li>
<li>Went back into iTunes on my old machine and used File > Library > Export Library&#8230; to generate a <code>Library.xml</code> file, which I copied to the new laptop</li>
<li>Ran a Perl script I wrote to pull out the play lists, song play counts, last play date, and ratings and push them into the Banshee database</li>
</ol>

<p>Fortunately the <code>Library.xml</code> file output by iTunes is in a standard format that is pretty easy to understand. Also, Banshee keeps much of the information about your music and such in a SQLite database. So, I could very easily automatically copy over all the ratings and other information I&#8217;ve been assembling for the past several years.</p>

<p>Here&#8217;s the conversion script, <code>itunes-to-banshee.pl</code> that I wrote for download:</p>

<p><span class="mt-enclosure mt-enclosure-file" style="display: inline;"><a href="http://contentment.org/files/itunes-to-banshee.pl">Download itunes-to-banshee.pl</a></span></p>

<p><strong>Update (thanks to Rolo):</strong> You will need to install a few dependencies as well. On Debian or Ubuntu, this is done by installing:</p>

<ul>
<li>libdatetime-perl </li>
<li>libdatetime-format-iso8601-perl </li>
<li>libclass-dbi-sqlite-perl</li>
<li>libxml-twig-perl</li>
<li>libmime-base64-perl</li>
</ul>

<p>This can be done from Synaptics or by running this on the command-line:</p>

<pre><code>sudo apt-get install libdatetime-perl libdatetime-format-iso8601-perl \
    libclass-dbi-sqlite-perl libxml-twig-perl libmime-base64-perl
</code></pre>

<p>Once Banshee has finished adding your song files to its music library, close Banshee. Make a backup copy of <code>banshee.db</code> to somewhere in case something goes wrong (which can be found at <code>~/.config/banshee-1/banshee.db</code>). Then run:</p>

<pre><code>perl itunes-to-banshee.pl Library.xml ~/.config/banshee-1/banshee.db
</code></pre>

<p>This may take a few minutes, depending on how many songs you have. It might show you some warnings if your <code>Library.xml</code> is weird (remember I wrote this just for me). It may also tell you if it can&#8217;t find some songs in Banshee that it found in your <code>Library.xml</code>. (It did for me because I&#8217;d deleted some songs from the disk and iTunes never figured it out.)</p>

<p>Once it finishes, start Banshee back up and it should have the play lists, ratings, play counts, and last played date set for all the songs that had such information in iTunes.</p>

<p>There are a couple things you might want to know about how the program works. First, it does not touch smart play lists. I don&#8217;t know and don&#8217;t particularly care how to read the smart playlist configuration from iTunes. I was able to recreate the smart play lists I had in a few minutes.</p>

<p>Second, the import script uses the song title and song file size to match songs from the iTunes library in the Banshee library. This is probably safe since I&#8217;ve never seen two CDs with the same songs on them end up being the same size, but it&#8217;s theoretically possible it could be a problem.</p>

<p>Third, if you have duplicates in your library, this script will only change one of them. I&#8217;d recommend weeding those out first.</p>

<p>I&#8217;m not interested in maintaining the script, but I&#8217;ll answer questions about it. If you ask really nicely and I&#8217;m in a good mood and the change you want is very small, I might be willing to make it, but that&#8217;s a lot of &#8220;ifs&#8221; to line up.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>The Best Way to Add Icons</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2009/05/the-best-way-to-add-icons.html" />
    <id>tag:contentment.org,2009://3.657</id>

    <published>2009-05-13T23:00:00Z</published>
    <updated>2009-05-13T19:33:50Z</updated>

    <summary>With my work on qublog.net continuing to progress toward hosting this service on the qublog.net web site. I’ve been using the silk icon set for the icons, but recently decided to switch over to the fugue icons. In the process,...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>With my work on <a href="http://qublog.net">qublog.net</a> continuing to progress toward hosting this service on the qublog.net web site. I&#8217;ve been using the <a href="http://www.famfamfam.com/lab/icons/silk/">silk icon set</a> for the icons, but recently decided to switch over to the <a href="http://www.pinvoke.com/">fugue icons</a>. In the process, I rethought how I added icons to the system, which I subsequently chose to try on some work things as well. There&#8217;s no magic here, nothing to patent (at least I hope not), but it&#8217;s worked pretty well, so I&#8217;ll share. I suppose this might not be &#8220;The Best Way&#8221;, but it&#8217;s certainly now &#8220;My Best Way.&#8221;</p>

<p>First, these icons are all being added without IMG-tags. This keeps my content less cluttered and allows me to very quickly switch icons if I change my mind later just be changing my stylesheet. Typically, these are added to buttons, links, and spans like so:</p>

<pre><code>&lt;span class="icon o-time"&gt;12:44 PM&lt;/span&gt;
&lt;a class="icon v-add o-task"&gt;Create Task&lt;/a&gt;
&lt;input type="submit" class="icon v-save o-time" name="op" value="Save"/&gt;
</code></pre>

<p>The first class &#8220;icon&#8221; performs the work of making sure the icon itself is attached to the element properly. This looks like:</p>

<pre><code>.icon {
    padding-left: 18px;
    background-repeat: no-repeat;
    background-position: 1px 1px;
    min-height: 18px;
}
</code></pre>

<p>This basically makes sure that my 16 pixel icon has 1 pixel of space around it and makes sure the element is at least tall enough not to cut anything off.</p>

<p>Then, the icon itself is chosen by examining the other associated classes. I&#8217;ve divided the classes into nouns (with an &#8220;o-&#8221; prefix), adjectives (with an &#8220;a-&#8221; prefix), verbs (with a &#8220;v-&#8221; prefix), and adverbs (with a &#8220;r-&#8221; prefix). I define these classes within the style sheet in that order so that adjectives will override nouns, verbs override both nouns and adjectives, and adverbs will override everything. So, now my style sheet looks something like this:</p>

<pre><code>.o-task { background-image: url(ticket.png) }
.o-time { background-image: url(clock.png) }

.a-group { background-image: url(folder.png) }
.o-task.a-project { background-image: url(briefcase.png) }

.v-add { background-image: url(plus.png) }
.v-add.o-task { background-image: url(ticket__plus.png) }
.v-add.o-task.a-project { background-image: url(briefcase__plus.png) }
</code></pre>

<p>By setting up the style sheet this way, a regular task reference shows up with a ticket icon. However, a project (which is a kind of task in Qublog) shows up as a briefcase. In case I need a generic add link, I can use a lone plus sign, but if I want a specific add link for tasks I can have a ticket with a plus sign. Finally, I can add a new project with a briefcase with a plus sign.</p>

<p>Later, if I want to modify the icons used, I can do so by just adding another class or something. It&#8217;s pretty flexible and if I make sure and include enough information on every link, span, or button that might have icon, I can make my icons more or less particular later just be adding a line or two to my style sheet. (For example, if my icon set lacked a briefcase with a plus next to it and then added one or I created one, then I could add that last rule later and rely on the ticket with a plus sign in the meantime.)</p>

<p>Some final varations I also use are things like having the icon only and ignoring the text itself:</p>

<pre><code>.icon.only {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    width: 0;
}
</code></pre>

<p>Now I can add the &#8220;only&#8221; class to my spans and links and the text becomes hidden. I combine this with a jQuery code similar to this:</p>

<pre><code>jQuery(document).ready(function() { 
    jQuery('.icon.only').each(function(){
        jQuery(this).attr('title', jQuery(this).text());
    });
});
</code></pre>

<p>This causes the text of the element itself to show up as a tooltip when you hover your mouse over the icon. Generally speaking, though, I usually try to do this on the server side when I use the &#8220;icon only&#8221; classes.</p>

<p>I have a few other &#8220;icon&#8221; class variants for changing the position of the icon, dealing with small 9-pixel icons, and making sure buttons and specific other things look good with the icons, but I&#8217;ll leave these as exercises for the reader.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Mutator Defaults: The Wrong Way</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2009/03/mutator-defaults-the-wrong-way.html" />
    <id>tag:contentment.org,2009://3.653</id>

    <published>2009-03-03T03:35:20Z</published>
    <updated>2009-03-03T03:57:23Z</updated>

    <summary>I’m messing around with Drupal again for a church web site. The task I’m working with at the moment is trying to make it so that the breadcrumb is based upon a menu other than than that Navigation menu (which...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I&#8217;m messing around with Drupal again for a church web site. The task I&#8217;m working with at the moment is trying to make it so that the breadcrumb is based upon a menu other than than that Navigation menu (which is the normal way content breadcrumbs are set in Drupal). Long story short, we&#8217;ve chosen to make the Primary Links the site map rather than the more typical Navigation menu.</p>

<p>The technique that really ought to work is this:</p>

<pre>
menu_set_active_menu_name('primary-links');
$breadcrumb = menu_get_active_trail();
drupal_set_breadcrumb($breadcrumb);
</pre>

<p>That&#8217;s simple enough, but it doesn&#8217;t work. At least, it doesn&#8217;t work unless it gets called at some point very early in the request life cycle. After some digging through the <a href="http://api.drupal.org/">Drupal API</a>, I found that <code>menu_get_active_trail()</code> is actually defined like this:</p>

<pre>
function menu_get_active_trail() {
  return menu_set_active_trail();
}
</pre>

<p>I vaguely remembered this from a year ago when I was last mucking with Drupal. This is a pretty common Drupal idiom. It&#8217;s basically the Drupal developer&#8217;s way of using the mutator (i.e., <code>menu_set_active_trail()</code>) simultaneously as a accessor and default setting. That&#8217;s fine. However, when you look into <code>menu_set_active_trail()</code> I found something wrong. The code looks like this (minus some code that I don&#8217;t want to spew here):</p>

<pre>
function menu_set_active_trail($new_trail = NULL) {
  static $trail;

  if (isset($new_trail)) {
    $trail = $new_trail;
  }
  elseif (!isset($trail)) {
    // LOTS OF CODE HERE TO CONFIGURE THE DEFAULT
    // BASED UPON THE OUTPUT OF menu_get_active_menu_name()
  }
  return $trail;
}
</pre>

<p>Do you see the problem? If you happen to set the value returned by <code>menu_get_active_menu_name()</code> (via <code>menu_set_active_menu_name()</code>) in time, you can get it to setup your breadcrumb using some fairly smart code that does the right thing for you. </p>

<p>However, if you don&#8217;t set it before the first call to <code>menu_set_active_trail()</code>, you can <strong>never</strong> run that helpful default code ever again. There&#8217;s no way to unset <code>$trail</code> because <code>$new_trail</code> is ignored if it is unset. There&#8217;s no way to execute the default code without unsetting <code>$trail</code> since it&#8217;s all within this single function.</p>

<p>Bah! The correct solution is to move the default code into a separate method so that it can be called separately later and reused.</p>

<p>My work-around will probably be to install the <a href="http://drupal.org/project/menu_breadcrumb">Menu Breadcrumb</a> module. I&#8217;m trying to keep the number of modules installed on this particular site very low, so I was hoping to avoid it. Yet, installing a module is going to work out better than me reinventing the wheel with a module of my own, in this case. It&#8217;s these little frustrations that drove me away from Drupal in my personal site. I&#8217;m probably being too picky and hypocritical, but whatever.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Dabbling in Git</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/dabbling-in-git.html" />
    <id>tag:contentment.org,2008://3.631</id>

    <published>2008-10-23T11:00:00Z</published>
    <updated>2008-10-23T14:45:08Z</updated>

    <summary>Recently, I started trying out git to see what the relative advantages and disadvantages of it are over Subversion, SVK, and CVS. I am not quite ready to give up the use of Subversion as the mechanism for sharing my...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>Recently, I started trying out git to see what the relative advantages and disadvantages of it are over Subversion, SVK, and CVS. I am not quite ready to give up the use of Subversion as the mechanism for sharing my projects with others, if only for the fact that I know more programmers familiar with it than with git (and also for the fact that my web host provides built-in support for Subversion, not git, at this time). Therefore, I&#8217;m actually using git as the front-end to access my Subversion repositories, which is quite similar to how I use SVK (and the normal model for SVK use).</p>

<p>The first difference I had to deal with was simply that the command-line is just a bit different. So, I had to map various ideas in Subversion/SVK/CVS into git before I could use it very successfully. Now that I&#8217;m using it comfortably, I&#8217;m certain I like it better than anything I&#8217;ve yet tried and will likely continue to use it over SVK, which was my preference up until now. On the other hand, I don&#8217;t think I&#8217;ll ever completely give up using Subversion, SVK, or CVS entirely unless and until they become obsolete tools that no one is using.</p>

<h3>Adding Changes</h3>

<p>Why do I like git over the alternatives? First, it helps protect me from common mistakes. For example, one thing that annoyed me at first is that you have to add any files you change to the list to be committed before committing.</p>

<pre><code>% git add lib/Net/Google/PicasaWeb.pm
% git commit
</code></pre>

<p>That seemed a little annoying compared to how SVK lets you commit with a single &#8220;svk commit&#8221; command and select which files to commit by editting the commit message. Yet, once I got used to it, I realized that I rarely ever have to back out a mistakenly committed file. It only commits those you explicitly ask for. If you&#8217;re sure you want to commit everything, you can add whole directories or use the <code>-a</code> switch to commit, but the fact that you have to explicitly make these decisions rather than just committing whatever makes it difficult to make mistakes in what you commit (unless you are in hurry).</p>

<h3>Commit by Hunk</h3>

<p>Next, I can commit only parts of a file. This feature blew my mind. This should be a mandatory feature for any source code storage system. When I&#8217;m making a complex set of changes, but don&#8217;t make intermediate commits for whatever reason (laziness, forgot, not sure if what I&#8217;m doing in one part really serves the whole yet, etc.), I can perform an interactive patch.</p>

<pre><code>% git add -p
% git commit
</code></pre>

<p>When running add with the <code>-p</code> switch, you will iterate through all the listed files (or in this case, all files changes in the repository), and be shown the diff. You can then add individual hunks from the diff to the commit or not. On the latest release of git, you can even edit the diff to pick out individual lines from the hunk to stage and leave the rest out for the moment. This is a killer feature.</p>

<h3>Tracking Patches, Not Files</h3>

<p>Another nice feature has to do with how git manages to deal with tracking changes. In Subversion, SVK, and CVS the most important unit to work with is the code itself. However, with git, the most important unit to work with is the diff of how the code changed from one commit to the next. </p>

<p>What do I mean? As an example, if I take a project and branch it to work on some complicated feature while the trunk continues to move forward. Then, I merge them when I am done, Subversion, SVK, and CVS handle the merge by diffing the branch with the trunk and then putting all the changes together in a single revision. These will use the history of the trunk and branch in various ways to help resolve problems, but they essentially treat a merge as a single diff. (SVK is a partial exception if you use the &#8220;-I&#8221; option during merges.) </p>

<p>With git, all the changes of the merge are copied over to the top of the trunk and then you deal with conflicts one diff at a time. This way the entire history gets pulled over from the branch onto top of the trunk, as if the work had been done from the top of the trunk in the first place. You take a little extra time to &#8220;rewrite history&#8221; this way, but it makes your patches a little more logical.</p>

<p>This same handling of patches works all over the place. For example if you just want to take advantage of some new features placed on the trunk, you can do something called a &#8220;rebase&#8221; rather than a &#8220;merge.&#8221; This is the same process as the merge, except all the patches remain on the same branch.</p>

<pre><code>% git rebase master
</code></pre>

<p>You can even move the entire branch to a different base point if you want to try your branch out using features still in progress on a different branch:</p>

<pre><code>% git rebase --onto bar master foo
</code></pre>

<p>The above command would move all the changes on branch &#8220;foo&#8221; on to branch &#8220;bar&#8221; as if these changes had been written for &#8220;bar&#8221; originally.</p>

<p>Under SVK or Subversion, a merge would be done by pulling in the latest trunk changes over into the branch. This adds a the trunk changes into the middle of your branch as either an individual commit (or as a set of commits with &#8220;-I&#8221; in SVK).</p>

<h3>Work in Progress</h3>

<p>Have you ever tried out some code changes and then realized they weren&#8217;t going to get you where you want to go? At the same time, though, there are some good ideas here that you don&#8217;t want to just throw away. In Subversion you might create a special branch to hold them, but probably not. In SVK, you might create a local branch or something to hold work in progress, but again, probably not.</p>

<p>In git, you can just run:</p>

<pre><code>% git stash
</code></pre>

<p>This takes all of the changes you&#8217;ve just made and stores them quickly in a special stash. You can then see the stash and recover the latest stashed item using:</p>

<pre><code>% git stash list
% git stash apply
</code></pre>

<p>There are a few other commands with the stash as well that are handy, but these are the ones I use most.</p>

<p>Those are a few of the reasons why I really like git. On the other hand, there are some aspects of SVK that are nice, such as the fact that it is very easily extended using Perl (since SVK is written in Perl and written for extensibility). I&#8217;ve been thinking about looking into adding features like these into SVK as a fun exercise since I&#8217;ve been playing with git. I sure don&#8217;t have time to do any of the other of the fun projects I do on my own time, so why not?</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Android and Development Tools</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/android-and-development-tools.html" />
    <id>tag:contentment.org,2008://3.636</id>

    <published>2008-10-21T23:20:00Z</published>
    <updated>2008-10-21T20:18:04Z</updated>

    <summary>I think if I had my way, I would develop tools for developers most of the time. This would be a good implementation of Yegge’s “only build stuff for yourself” principle. The Android project catches my eye because it offers...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I think if I had my way, I would develop tools for developers most of the time. This would be a good implementation of Yegge&#8217;s &#8220;<a href="http://steve-yegge.blogspot.com/2008/08/business-requirements-are-bullshit.html">only build stuff for yourself</a>&#8221; principle. The <a href="http://source.android.com/">Android project</a> catches my eye because it offers the possibility of being able to get rid of the Microsoft OS on my phone without having to buy a new phone. However, after looking at the site, I&#8217;m now more interested in the tools they&#8217;ve put together to aid this development.</p>

<p>The first is a tool called &#8220;<a href="http://source.android.com/submit-patches">repo</a>&#8221;. It&#8217;s somewhat similar to a tool we use at work for managing our source repositories. It basically adds some higher level niceties to git and helping connect with code reviews. In addition, it interacts with a nice web-based UI for code reviews they&#8217;ve called &#8220;<a href="http://review.source.android.com/">garrit</a>&#8221;. </p>

<p>Garrit is kind of like a ticket tracker for submitting patches and works almost in reverse of the usual ticket tracker. Normally, you post a problem and then put together a solution. This tool lets you submit a solution and then lets the reviewers determine whether it&#8217;s a good idea or not. This is important for a project like Android where it will likely be common for someone to write a patch to get Android working for his particular phone or app and then submit it to the community for general inclusion. It supports the git model for development pretty well.</p>

<p>Anyway, I&#8217;m interested in Android and hope some smart folks with better C skills than me can make it work on my phone in the near future, but in the meantime, I think dev tools present some interesting ideas on their own.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>CPAN To Go</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/cpan-to-go.html" />
    <id>tag:contentment.org,2008://3.634</id>

    <published>2008-10-20T21:53:44Z</published>
    <updated>2008-10-20T22:10:57Z</updated>

    <summary>I don’t travel away from a network very often, particularly now that I have an EVDO card. However, it is inevitable that when am away from a network (on a plane, in snow storm, on the road) I want to...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I don&#8217;t travel away from a network very often, particularly now that I have an EVDO card. However, it is inevitable that when am away from a network (on a plane, in snow storm, on the road) I want to try out a CPAN module or need one that I haven&#8217;t yet installed. When this happens and I can&#8217;t do whatever it was that I wanted to do because I didn&#8217;t have it, I get grumpy. However, thanks to <a href="http://search.cpan.org/dist/CPAN-Mini/">CPAN::Mini</a>, I don&#8217;t have to worry about this problem anymore.</p>

<pre><code>% sudo cpan CPAN::Mini
% mkdir -p ~/projects/minicpan
</code></pre>

<p>That installs the module itself and sets up the directory for the local repository. Then, I added a nice alias to my shell config:</p>

<pre><code>alias cpansync="minicpan -l $HOME/projects/minicpan -r http://ftp.osuosl.org/pub/CPAN/"
</code></pre>

<p>I picked the OSL mirror here since I happen to know the man responsible for admin&#8217;ing that mirror. I can then run this to get a copy of the latest and greatest on CPAN:</p>

<pre><code>% cpansync
</code></pre>

<p>After that runs, I can run it again any time I want to refresh, which I usually do right before I travel and any other time I want a fresh copy.</p>

<p>Finally, I modified the list of CPAN mirrors to include:</p>

<pre><code>file:///home/sterling/projects/minicpan
</code></pre>

<p>Now, whenever I install modules, the modules are installed directly from my hard drive. This is also a bit faster than having to download the modules at install time (i.e., as long as I have already done the download previously).</p>

<p>This setup makes me happy, especially when on airplanes.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Pittsburgh, Perl, and Working in Shops</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/pittsburgh-perl-and-working-in.html" />
    <id>tag:contentment.org,2008://3.630</id>

    <published>2008-10-13T02:36:42Z</published>
    <updated>2008-10-13T04:53:14Z</updated>

    <summary>I found out about the fact that I would be giving two talks at the Pittsburgh Perl Workshop this week about 2 weeks ago and have been working frantically to get my stuff together since. Well… at least, I worked...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I found out about the fact that I would be giving two talks at the Pittsburgh Perl Workshop this week about 2 weeks ago and have been working frantically to get my stuff together since. Well&#8230; at least, I worked frantically for the last week. The first week, was not quite frantic. It was more like somewhat diligent, but I did spend a couple nights playing Zelda that should have been spent prepping. Anyway, I got my talks done and I don&#8217;t think they were particularly excellent, but I don&#8217;t think they went badly (at least, I hope they didn&#8217;t). But, this post isn&#8217;t really about my talks so much as it is about debriefing PPW 2008. On to the festivities&#8230;</p>

<h3>Travel To</h3>

<p>It all started on a completely average Friday morning of packing&#8230; okay, skipping ahead. I flew to Pittsburgh through Milwaukee. In Milwaukee, I was supposed to take a late flight from there, but that wasn&#8217;t supposed to me I took off from Milwaukee after midnight. However, the flight the airplane hadn&#8217;t even taken off yet from <em>Dallas</em> when we landed. So, I worked more on my slides which weren&#8217;t quite finished while I waited. And waited. Finally, the plane arrived and took me to Pittsburgh, where I landed around 2am. </p>

<p>Strange thing about the flight, though. There were only 5 actual passengers on an Embraer 170. For those of you that aren&#8217;t airplane fanatics (like me), that&#8217;s a plane that seets about 70. There were two flight attendants, the pilot and copilot, and another 4 or 5 airline personnel catching a ride to Pittsburgh. That&#8217;s all.</p>

<p>I was the only one that had a checked bag. Uh-oh. When I got off the plane, a baggage handler was asking each of the 5 real passengers if they checked a bag and I said, &#8220;Yes.&#8221; He said he&#8217;d meet me at baggage claim. He met me there, but with no bag. It was lost. Poop. I almost never check a bag and this time I did. Dumb. Oh well.</p>

<p>So, I catch a cab and go on to the hotel and finally get to sleep sometime after 3am.</p>

<h3>PPW Saturday</h3>

<p>My phone alarm woke me up around 7am. Yeesh. I felt like something scraped off the bottom the mattress, but I got up and showered and got some coffee. I am in a hotel about 1.5 miles from the conference, so I figured I walked. I think this was a good thing as it helped me wake up a bit and it has been a glorious weekend in Pennsylvania. I stopped off to get some antiperspirant and some Listerine breath strips to minimize in odious scents I might be emitting since I was lacking my toiletries.</p>

<p>I made it to Wean Hall on CMU campus and promptly picked up my conference T-shirt and took it to the bathroom to exchange it for the mildly damp shirt I had been wearing that had probably picked up odors from a shuttle bus, three airports, two airplanes, and a cab, not to mention a 35 minute walk on a warm morning with a 30 pound backpack. Okay, so with new shirt donned and odor opposing chemicals applied to my underarms and mouth, I went in to the keynote on Perl 6 in progress.</p>

<h4>Perl 6</h4>

<p>The keynote was by Patrick Michaud and the news for Perl 6 is good! Yay! For anyone who has followed the drama of Perl 6, you know that some of the history hasn&#8217;t necessarily been positive. However, it sounds like things might actually be moving on the right track now. The final release of Perl 6 still expected on Christmas, as it has been for at least a couple years now. But, given Patrick&#8217;s report, it sounds like it might actually be a Christmas before my son starts elementary school. (I wasn&#8217;t always sure of that.)</p>

<h4>Bug Labs</h4>

<p>After the first talk, a company called <a href="http://buglabs.net/">Bug Labs</a> gave a presentation. It was kind of an odd talk I thought since it really didn&#8217;t have much to do with Perl (existing APIs are Java), but it was more of a suggestion that Perl hackers <em>could</em> get involved. I&#8217;m a bad candidate for that. The product itself looked like an interesting diversion, but nothing I&#8217;d be willing to sink that much cash into. I&#8217;m not so much a hardware guy anyway.</p>

<p>My personal feelings aside, I have some doubts about the business plan of Bug Labs. It&#8217;s nice that they support Open Source, but the viability of the business model is a little questionable to me. The presenter kept saying they wanted to make it so easy that &#8220;your mom&#8221; could come up with a custom device. First, my mom is not likely to care about a device unless it comes prefab with as few buttons as possible. Second, my mom is not going to put down that kind of cash just so she can create some sort of customized web-cam/motion-sensor/GPS something-or-other. She has better things to do. I suspect she didn&#8217;t mean my mom literally, but that doesn&#8217;t mean my statements are any less valid for the hypothetically average mom either.</p>

<h4>SQLite Extensions</h4>

<p>After that was a talk on extending SQLite, which I admit I paid very little attention to because I was still trying to finish my slides for my first talk on Sunday. I thought this sounded interesting and it would be nifty to have more of that in some of the code we do at work, but since we don&#8217;t use SQLite for the work I&#8217;m thinking of, the talk doesn&#8217;t really apply to that. </p>

<h4>Data::Rx</h4>

<p>Ricardo Signes then gave a talk on something I&#8217;d never heard of before, Rx, but I think I&#8217;m going to check out. He&#8217;s basically put together a data validation system similar to XSD or RELAX-NG, but for general data structures in memory. It&#8217;s a really cool idea and I want to see what I might be able to gain from it, so it&#8217;s on my short list of things to try out in the near future. The fact that he&#8217;s got implementations for it in Ruby, Python, and PHP is also very interesting for interoperability.</p>

<h4>Lunch</h4>

<p>Next was lunch where I met <a href="http://www.klein.com/dvk/">Dan Klein</a>, a fellow consultant for Grant Street, in person for the first time and had a pretty mediocre chicken marsala, but an excellent salad with fetta cheese, roasted almonds, and strawberries with a raspberry vinaigrette.</p>

<h4>Advanced Pattern Matching</h4>

<p>Paul Grassie, another co-consultant, gave a talk on regexes, which I again confess I mostly missed to work on my own talk. What material I did catch was a good review and there were bits that were somewhat new, but I wasn&#8217;t paying close enough attention to really learn them.</p>

<p>By the way, Paul and Dan work for <a href="http://training.perl.com">Tom Christiansen Perl Consultancy</a>. Given what I know of them now (having seen Paul in action and spent part of a day with Dan), I&#8217;d recommend their services if you have some need of Perl training for your company.</p>

<h4>Network Introspection</h4>

<p>This talk I almost completely ignored. There were some things in it that were interesting, but it was mostly for the sysadmins. I was familiar with and impressed with some of what was presented, but I did the system administrator thing already and have turned a new leaf. I&#8217;m not going back to the land of putting out fires in the world of hardware.</p>

<h4><strike>R</strike>DBMS</h4>

<p>The next talk was on a database tool called Kioku::DB, which is an interesting idea and something I&#8217;m glad to be aware, but not something that will change the way I do my work or hobbies. Again, I&#8217;m still working on slides as I glance up now and then and this didn&#8217;t really capture my attention.</p>

<h4>Email Hates the Living!</h4>

<p>Finally, Ricardo gave his second talk of the day on Email. Having myself engaged in mortal combat against the spam monster at one of my first tech jobs and having been a systems administrator, this talk was flipping hilarious. His analysis on the insanity of email and the email specs is right on. For example, &#8220;asdf@!#$&amp;&#8221; is a valid email address within the To: or From: line of your email, even though such an email couldn&#8217;t possibly be delivered. Yet, &#8220;asdf@!#$&amp;.&#8221; is not. Stupid. It&#8217;s a great talk and helps to explain why his CPAN repository is filled with email code, when it doesn&#8217;t seem like it should really be quite that hard.</p>

<h4>Dinner and Sleep</h4>

<p>After that, the Grant Streeters still around headed out for dinner where there was some lively discussion of work and politics. Then, I went back to the hotel room and came up with a Lightning talk, did the final clean up on my slides, and then tried to get more sleep.</p>

<h3>The Saga of the Missing Bag</h3>

<p>I haven&#8217;t finished the story about my bag. Early Saturday, I called Midwest Airlines to find out about my bag. As I mentioned, mine was to be the only checked bag and the handler that I talked to couldn&#8217;t find it. He made me out a claim for the bag and said it would be delivered as soon as he could get it to me.</p>

<p>When I called Midwest, the conversation with the woman went something like this:</p>

<blockquote>
  <p><strong>Me:</strong> Hi, I&#8217;m calling to find out about my missing bag. <br />
  <strong>Woman:</strong> What&#8217;s your name? <br />
  <strong>Me:</strong> Andrew Hanenkamp. H-A-N-E-N-K-A-M-P. <br />
  <strong>Woman:</strong> Mr. Hanenkamp? Yes, your bag came in on your flight. Why didn&#8217;t you pick it up? <br />
  <strong>Me:</strong> Um, because the guy who said he was going to pull it out of the plane said he didn&#8217;t find it and gave me a baggage claim ticket. <br />
  <strong>Woman:</strong> Okay, I&#8217;m very busy right now, I will try to get them delivered to you hotel. Can I get your number?  </p>
</blockquote>

<p>I gave her the number and then finally was able to get back with her during lunch. This conversation went something like this:</p>

<blockquote>
  <p><strong>Me:</strong> Hi, I&#8217;m returning a call made to my cell phone? <br />
  <strong>Woman:</strong> Who is this? Is this Mr. Hanenkamp? <br />
  <strong>Me:</strong> Yes, I believe you have my bags, have they been sent to my hotel yet? <br />
  <strong>Woman:</strong> Well, your bag was here last night. My supervisor wants to know why didn&#8217;t you pick it up last night. It was here already. <br />
  <strong>Me:</strong> I know. As I told you before, the guy who pulled it out of the plane told me it didn&#8217;t come. <br />
  <strong>Woman:</strong> Hmm. Okay. Umm. Did he give you a baggage claim ticket? <br />
  <strong>Me:</strong> Yes. I have it in my wallet. <em>(Thinking, do you want me to shove it through the phone?)</em> <br />
  <strong>Woman:</strong> Okay, well, I guess I can have the delivery service take your bag over. Which hotel are you at? Do you know the zip code? <br />
  <strong>Me:</strong> <em>[chuckle]</em> Um, no, I don&#8217;t generally memorize the zip codes of the hotels I&#8217;m staying at.  </p>
</blockquote>

<p>Anyway, so when I got back, I had my bag and was finally able to change into completely fresh clothing and brush my teeth and such. Ah.</p>

<h3>Sunday</h3>

<p>I walked over to Wean Hall again after picking up my coffee and started out in the Rakudo Perl talk.</p>

<h4>Rakudo Perl</h4>

<p>This talk was also given by Patrick Michaud and I went to it rather than the Moose talk because I&#8217;m already somewhat familiar with Moose and because Perl 6 and Parrot are something I&#8217;d like to volunteer my time on. Perhaps I will at some point, but I have too many other things I&#8217;m doing that I&#8217;m more immediately interested in. I don&#8217;t have any excuse for not joining for reasons due to not knowing how now, though. Patrick went over all the sorts of things someone wanting to contribute might want to do to get started.</p>

<h4>Managing Open Source Projects</h4>

<p>Next I went to this talk by Tom Lane rather than attending Schwern&#8217;s talk on the y2038 bug. The talk was moderately interesting since Tom Lane is a Red Hat employee who spends most of his time contributing to PostgreSQL. It was interesting to here the differences between how Perl is managed and PostgreSQL, but I confess, I was again distracted, but this time by a bug report on one of my CPAN modules.</p>

<h4>Data Structures</h4>

<p>This was another talk by Paul Grassie and at a very introductory level. I don&#8217;t think he covered anything I don&#8217;t use on a nearly daily basis, but I was still working on bugs on my CPAN module. I did note that Paul has a very soothing voice and since I&#8217;ve only had about 8 hours of sleep total in the past 48 hours, it was making me a bit sleepy.</p>

<h4>MooseX::Tour</h4>

<p>Next was Jonathon Rockway&#8217;s talk on MooseX extensions. There are some pretty cool extensions to Moose available for dealing with various customizations to your meta-programming code. I&#8217;d recommend looking over his slides when they are posted on his <a href="http://blog.jrock.us/">blog</a>. There&#8217;s some interesting things in there.</p>

<h4>Lunch</h4>

<p>We had more lunch. I got to meet Tom Welsch&#8217;s kids, since Tom brought them with him as he did a little light recruiting for Grant Street. I had more yummy salad and a decent sandwich (at least for having been catered).</p>

<h4>Jifty Talk</h4>

<p>I gave and got through my whole talk on Jifty. I&#8217;ve <a href="http://qublog.net/2008/10/talk-introduction-to-jifty.html">posted</a> the slides, which is enough summary.</p>

<h4>Prophet</h4>

<p>I watched part of Kevin Falcone&#8217;s talk on <a href="http://syncwith.us">Prophet</a> and this is another one of those things that I have got to get my hands on in the near future. <a href="http://qublog.net/">Qublog</a>, in particular, could benefit from what it does very nicely.</p>

<h4>Perl REST</h4>

<p>Again, I gave this talk and the slides are <a href="http://contentment.org/2008/10/talk-making-your-perl-rest.html">posted</a>.</p>

<h4>Method Signatures</h4>

<p>Lastly, I attended the talk Schwern gave on his new method signatures class. It&#8217;s pretty nice overall, but I&#8217;m a little hesitant to actually use it. His point about there being 240,000 extra lines of code that can be taken off of CPAN because of it is well-taken, but I&#8217;m not quite convinced to actually use it yet. On the other hand, the parser module that Matt Trout wrote, Devel::Declare, which has some interesting possible implications for the DSL work I want to do with Jifty.</p>

<h4>Lightning Talks</h4>

<p>Most of the lightning talks were great, mine excluded. I fail. </p>

<p>Ricardo gave a talk on Dist::Zilla, which I am also adding to my short list. It&#8217;s kind of a replacement for Makefile.PL and Module::Starter and Module::Release and such, but does some very smart things. If I find out that it&#8217;s extensible and mostly makes sense when I take a first hand look, I&#8217;ll likely be using this to manage my modules in the future.</p>

<p>Kelli Ireland gave a talk on the orange shirt that&#8217;s been traveling with various members of the Perl community to exotic destinations and offered it to anyone going somewhere interesting if they will take pictures.</p>

<p>There was a talk on going <em>Sixty to Zero</em> in Perl (a play on the <em>Zero to Sixty</em> tutorial given). This talk was great in that it showed how very readable Perl can be turned very unreadable if someone wishes to do so deliberately in order to maintain job security. It was a very good example of why serious Perl developers don&#8217;t understand why Perl gets kicked in the face so much when it is not difficult to write good Perl code if you actually try to do so.</p>

<p>Probably the most memorable lightning talk, though, was the LOLCAT history of Perl. Unfortunately, there&#8217;s no way such a talk can be translated into this summary in any useful fashion, so I will just say, that it was <em>awesome</em>.</p>

<p>After that, I skipped out because I&#8217;m sleepy and should have been asleep already, but decided to write this instead&#8230; Okay, so I think that does it for PPW 2008. This is Sterling Hanenkamp signing off. Good night and God bless.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Talk: Making Your Perl REST</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/talk-making-your-perl-rest.html" />
    <id>tag:contentment.org,2008://3.629</id>

    <published>2008-10-12T23:58:04Z</published>
    <updated>2008-10-13T00:06:31Z</updated>

    <summary>I gave my talk on REST at the Pittsburgh Perl Workshop today. I think it went alright, but I’m sure it was dreadfully boring. If I ever give the talk again, I’m going to have to liven it up a...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I gave my talk on REST at the Pittsburgh Perl Workshop today. I think it went alright, but I&#8217;m sure it was dreadfully boring. If I ever give the talk again, I&#8217;m going to have to liven it up a bit and speed up the pace. For anyone that attended the talk, I would be interested to have your feedback, so please feel free to post it here.</p>

<p>Here are the slides, as promised:</p>

<div style="width:425px;text-align:left" id="__ss_653258"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/zostay/making-your-perl-rest-presentation?type=powerpoint" title="Making Your Perl REST">Making Your Perl REST</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=making-your-perl-rest-1223855066817171-8&stripped_title=making-your-perl-rest-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=making-your-perl-rest-1223855066817171-8&stripped_title=making-your-perl-rest-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/zostay/making-your-perl-rest-presentation?type=powerpoint" title="View Making Your Perl REST on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/perl">perl</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/rest">rest</a>)</div></div>

<p>Again here are links to the sample implementation files:</p>

<ul>
<li><a href="http://contentment.org/files/onlamp/book">book</a></li>
<li><a href="http://contentment.org/files/onlamp/library.cgi">library.cgi</a></li>
</ul>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Speaking at PPW 2008</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/speaking-at-ppw-2008.html" />
    <id>tag:contentment.org,2008://3.625</id>

    <published>2008-10-08T01:58:29Z</published>
    <updated>2008-10-08T02:09:14Z</updated>

    <summary>I just wanted to make a quick post to note that I will be in Pittsburgh this weekend speaking at the Pittsburgh Perl Workshop 2008. I will be giving two talks on Sunday afternoon: Introduction to Jifty Making Your Perl...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I just wanted to make a quick post to note that I will be in Pittsburgh this weekend speaking at the <a href="http://pghpw.org/ppw2008/">Pittsburgh Perl Workshop 2008</a>. I will be giving two talks on Sunday afternoon:</p>

<ul>
<li><a href="http://pghpw.org/ppw2008/talk/1497">Introduction to Jifty</a></li>
<li><a href="http://pghpw.org/ppw2008/talk/1496">Making Your Perl REST</a></li>
</ul>

<p>Also featured at the conference will be talks by a couple of my coworkers:</p>

<ul>
<li><a href="http://pghpw.org/ppw2008/zerotoperl.html">From Zero to Perl</a> (a tutorial) by Daniel Klein</li>
<li><a href="http://pghpw.org/ppw2008/talk/1506">Symbol Tables and Typeglobs</a> by Paul Grassie</li>
<li><a href="http://pghpw.org/ppw2008/talk/1507">Mastering Data Structures and References</a> by Paul Grassie</li>
<li><a href="http://pghpw.org/ppw2008/talk/1505">Advanced Pattern Matching</a> by Paul Grassie</li>
</ul>

<p>I&#8217;m mostly done with one set (REST) and started and somewhere around 25% done with the preparation I need to get done for the other set, which will include a shameless plug for my <a href="http://qublog.net">other project</a>. </p>

<p>This isn&#8217;t the first time I&#8217;ve given a 50 minute talk, since I taught a class, but this is a much different format than that. Since I&#8217;m attempting to re-use the excellent work of others (particularly <a href="http://tokyo2007.yapcasia.org/sessions/2007/02/jifty_now.html">Jesse Vincent and Audrey Tang</a> on the Jifty talk), I hope I will do alright.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Calendar Sync on Mac That (Sort of) Works</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/10/calendar-sync-on-mac-that-sort.html" />
    <id>tag:contentment.org,2008://3.624</id>

    <published>2008-10-03T11:02:22Z</published>
    <updated>2008-10-03T16:15:25Z</updated>

    <summary>At my current job, I have quite a few more important appointments on a regular basis that I’ve had since I was teaching courses at K-State. As such, I’ve resurrected my dedication to the calendar. I have finally gotten a...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>At my current job, I have quite a few more important appointments on a regular basis that I&#8217;ve had since I was teaching courses at K-State. As such, I&#8217;ve resurrected my dedication to the calendar. I have finally gotten a setup working that seems to do the job of allowing me to keep a good calendar, keep my wife informed, and keep my phone informed.</p>

<p>To do this, I&#8217;m using the following:</p>

<ul>
<li><a href="http://www.apple.com/macosx/features/300.html#ical">Apple iCal</a> to manage the day to day work with the calendar</li>
<li><a href="http://www.google.com/calendar">Google Calendar</a> to manage sharing the calendar with others</li>
<li><a href="http://www.busymac.com/">BusySync</a> ($25) to keep iCal and Google Calendar synchronized</li>
<li><a href="http://www.markspace.com/products/windowsmobile/mac/windows-mobile-sync-software.html">The Missing Sync</a> ($40) to keep iCal and my phone synchronized</li>
</ul>

<p>This is working pretty well. The weakest link in this setup is The Missing Sync which works, but is an absolute steaming pile when it comes to stability. It crashes at least 50% of the time I sync. Fortunately, it usually recovers if I force quit and unplug/plug my phone. If there&#8217;s anything else out there the next time I&#8217;m looking to buy something like this, I&#8217;ll try it instead unless they can get this fixed.</p>

<p>One thing I&#8217;ve discovered is that the integration with Apple Mail and iCal is wonderful. I can very easily create appointments by hovering over dates mentioned in an email, click on the popup that appears, and select &#8220;Create New iCal Event&#8230;&#8221; This makes keeping track of coworker&#8217;s vacation time and the downtime schedule very easy.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Making iTunes Submit</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/09/making-itunes-submit.html" />
    <id>tag:contentment.org,2008://3.620</id>

    <published>2008-09-19T01:23:18Z</published>
    <updated>2008-09-19T01:43:00Z</updated>

    <summary>I have a Mac and I listen to music in iTunes most of time. After quite a bit of experimentation I have, I think, finally come across a way of creating a play list that allows me to tolerate iTunes....</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I have a Mac and I listen to music in iTunes most of time. After quite a bit of experimentation I have, I think, finally come across a way of creating a play list that allows me to tolerate iTunes. I don&#8217;t like listening to my music in order. I&#8217;d like it to play randomly. On the other hand, random typically means I get one or two songs I don&#8217;t particularly like that come up often and some songs I do like getting played almost never. This is never what I want, but this is exactly what the useless &#8220;Party Shuffle&#8221; feature of iTunes. I hate it. Even with the &#8220;don&#8217;t play a song by the same whatever&#8221; settings set, it still manages to do so too often for my to tolerate.</p>

<p>My solution is to put together a play list that contains a set of music I like to listen to and then I create a smart play list  based on it. When configured correctly, my play list will play all the music I want to hear regularly, but not too regularly. Here&#8217;s how I do it. I create a smart play list and set it to match <strong>all</strong> of these rules:</p>

<ul>
<li>First, I add the rules that pick out genre or off of another play list as the source, plus any other modifications like minimum rating.</li>
<li>Second, set a rule that requires the <strong>Last Played</strong> date is not in the last X days, where X depends on the size of the source play list. For example, my &#8220;Top Music&#8221; list contains around 715 songs with around 1.9 day play time. I set the limit to at least 7 days, for this list.</li>
</ul>

<p>After that, I tell it to limit the play list to Y items selected at random. For the &#8220;Top Music&#8221; play list, I use 75 items.  I then make sure it&#8217;s <strong>Live Updating</strong> in case I add more music.</p>

<p>Finally, I play the list on shuffle. Since I&#8217;ve started playing my music this way, I find that I listen to all of the music in the list every month or so and I never hear a single song too often and it&#8217;s completely random.</p>

<p>What I really wish was that Party Shuffle would work the way I think it should. If I want to see the next 25 songs ahead, I want it to guarantee it won&#8217;t duplicate anything within that window. If I could then have it try to fit in songs I haven&#8217;t heard in a while, but prefer the higher rated songs, that would be great. It wouldn&#8217;t have to be perfect, but iTune&#8217;s play list options are abysmal.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Is He Talking About Me?</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/08/is-he-talking-about-me.html" />
    <id>tag:contentment.org,2008://3.609</id>

    <published>2008-08-28T17:56:44Z</published>
    <updated>2008-08-28T18:02:40Z</updated>

    <summary>I just finished reading this blog post and was convinced for a few minutes that this guy was stalking me even though I have no idea who it is. Fortunately, the references about class and school allowed me to relax...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p>I just finished reading <a href="http://lispy.wordpress.com/2008/08/25/do-you-know-any-programmers-that-exhibit-these-personality-traits/">this blog post</a> and was convinced for a few minutes that this guy was stalking me even though I have no idea who it is. Fortunately, the references about class and school allowed me to relax that he&#8217;s actually just stalking my long lost twin.</p>

<p>Thanks to Randall for passing that link on to me. It&#8217;s a little scary how accurate it describes me and, like Randall, I have to confess a little embarrassment at some of the harsher bits of the analysis because it&#8217;s very close to the mark, even down to the mention of specific details.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Developing RESTful Web Services in Perl, Part 2</title>
    <link rel="alternate" type="text/html" href="http://contentment.org/2008/08/developing-restful-web-service.html" />
    <id>tag:contentment.org,2008://3.607</id>

    <published>2008-08-18T02:28:05Z</published>
    <updated>2008-10-02T03:27:40Z</updated>

    <summary>Part 1 of this article was posted on onlamp.com. Due to changes in the format of O’Reilly’s online publications, they are no longer interested in Part 2, so I have published it here. Sorry for the delay but it took...</summary>
    <author>
        <name>Andrew Sterling Hanenkamp</name>
        <uri>http://andrew.sterling.hanenkamp.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://contentment.org/">
        <![CDATA[<p><em><a href="http://www.onlamp.com/pub/a/onlamp/2008/02/19/developing-restful-web-services-in-perl.html">Part 1</a> of this article was posted on <a href="http://onlamp.com/">onlamp.com</a>. Due to changes in the format of O&#8217;Reilly&#8217;s online publications, they are no longer interested in Part 2, so I have published it here. Sorry for the delay but it took some time to contact the editor to learn all this.</em></p>

<p>In my <a href="http://www.onlamp.com/pub/a/onlamp/2008/02/19/developing-restful-web-services-in-perl.html">previous article</a>, I described the process of building a RESTful web API from the server-side. This article will describe how we write the client to the web services server provided in the first article.</p>

<p>The source code for the client and server described in this article is available by saving the following links:</p>

<ul>
<li>Client: <a href="http://contentment.org/files/onlamp/book">book</a></li>
<li>Server: <a href="http://contentment.org/files/onlamp/library.cgi">library.cgi</a></li>
</ul>

<p>There are some instructions on how to install them in comments in each file, but you&#8217;re mostly on your own. I can say that they should work (do work for me) if installed correctly and if the required libraries are in your library path. Sorry that I haven&#8217;t made these easier to use.</p>

<h3>RESTful Client</h3>

<p>The RESTful server written in the previous article helps me track the books in my library. This time, we&#8217;ll look at a command-line client that takes advantage of the API. The principles applied to build this client could be used to in your web application to access web services APIs provided by third parties or to build a GUI application or anything else. A command-line just provides a good simple interface with which to demonstrate.</p>

<p>The command-line script is named <code>book</code> and operates through the use of subcommands. For example, to list all the books in the system, you can run:</p>

<pre><code>./book list
</code></pre>

<p>In cases where a new book is added or updated, you specify the update using a file name.</p>

<pre><code>./book update 1-56563-833-6 treasury.yml
</code></pre>

<p>Without further ado, let&#8217;s jump into the code.</p>

<h3>Setting up the Client</h3>

<p>Before getting into the commands themselves, there is some setup performed by the script. First, we have a constant named <code>HOST</code>. This constant is just the URL of the REST API server.</p>

<p>I&#8217;ve also defined to additional helper functions that will show up throughout this article. The first, <code>barf()</code>, is called whenever an error occurs. Since our server returns errors as HTML, it just pulls title of the error from the HTML header and the rest of the error message from the first paragraph. The second helper function is <code>slurp()</code>, which is really nothing more complicated than the function by the same name in <code>File::Slurp</code> (but without an additional dependency, which I was attempting to avoid for the simple demo). All this does is suck in all the text of a named file and return it as a scalar.</p>

<p>The last bit of setup is that I&#8217;ve initialized one global variable named <code>$ua</code> for convenience. This variable contains a freshly initialized <code>LWP::UserAgent</code> object. The only library from CPAN this program depends upon is <code>libwww-perl</code>. I&#8217;ve also imported some helpers from <code>HTTP::Request::Common</code>, but we&#8217;ll get to that in a bit. Now, let&#8217;s talk about the interesting stuff.</p>

<h3>Listing Resources</h3>

<p>The first and simplest command we can run is to simply check to see what resources are available. You can see all the books stored by listing them using this command:</p>

<pre><code>./book list
</code></pre>

<p>Calling this command causes the script to run this bit of code:</p>

<pre><code># GET /=/model/book
my $response = $ua-&gt;request(GET HOST.'/=/model/book/id');

# On success, find the link and print them out
if ($response-&gt;is_success) {
    my @links = $response-&gt;content =~ /\bhref="([^"]+)"/gm;
    for my $url (@links) {
        my ($id) = $url =~ /([\d-]+)$/;
        print "$id: $url\n";
    }
}

# On failure, barf
else {
    barf $response;
}
</code></pre>

<p>Our first act is to grab a list of books from <code>/=/model/book/id</code>. As we saw in the previous article, this should return an HTML file containing a list of links as part of the API. If the request was successful, we pull all the links out using a regex and print them out to the end-user. If the request fails, we barf.</p>

<p>The key bit of code here is all within the call to the <code>GET</code> subroutine, which is exported by <code>HTTP::Request::Common</code>. This performs all the extra work we need to build a standard <code>GET</code> request. Another alternative is to use the <code>get()</code> method of <code>LWP::UserAgent</code>, which would look very similar:</p>

<pre><code>my $response = $ua-&gt;get(HOST.'/=/model/book/id');
</code></pre>

<p>Moving on, I hope I haven&#8217;t turned your stomach with how cheaply I&#8217;ve parsed the URLs and IDs out. This is not an ideal use of regex, but it does the job. If I were to do this the right way, I ought to use a decent HTML parser (I&#8217;m partial to <code>HTML::TreeBuilder</code>) to pull the links out more carefully. Another solution would be to alter the server so that it returned the links as a YAML file and then parse apart the YAML data to get the information I want. I&#8217;m lazy and wanted to avoid additional module dependencies at all cost on the demo, so I do it this way.</p>

<p>This will return a list of IDs, which may be ISBNs or just a number, which isn&#8217;t terribly useful. A simple enhancement to the system would be to change this to use the &#8220;title&#8221; field or something else, but we&#8217;d also have to enhance the server to support that.</p>

<h3>Reading a Resource</h3>

<p>Once we know what resources are available by the list, we may then want to check one out to get more information about it. We can do this using the read command. For example,</p>

<pre><code>./book read 1-56563-833-6
</code></pre>

<p>As you will recall from the server, we can read data using a GET request to <code>/=/model/book/id/&lt;ID&gt;</code>. This is what we do when the read subcommand is executed:</p>

<pre><code>my $id = shift @ARGV;

# GET /=/model/book/id/[id]
my $response = $ua-&gt;request(GET HOST.'/=/model/book/id/'.$id);

# On success, print the file
if ($response-&gt;is_success) {
    print $response-&gt;content;
}

# On failure, barf
else {
    barf $response;
}
</code></pre>

<p>We grab the ID given from the command line and use <code>LWP::UserAgent</code> to <code>GET</code> the book resource we&#8217;re interested in. On success, we then print the file out and on failure we barf.</p>

<p>If we wanted to do something more interesting with the resource file like present in a form or place it into a table or something, we&#8217;d use a YAML parser to decode the data and then manipulate it.</p>

<h3>Creating a Resource</h3>

<p>Now that we&#8217;ve looked at the resources in our (presumably empty) database, let&#8217;s look at how we added them. The first command to consider is, of course, for creating a new book record.</p>

<pre><code>./book create treasury.yml
</code></pre>

<p>The command slurps up the file you name and uses it to <code>POST</code> to <code>/=/model/book</code> to create a new book record. We then scan the response to make sure we know what ID was assigned (because, if you&#8217;ll remember, not all books have ISBNs, so the server provides an alternate identifier in such cases).</p>

<pre><code>my $file = shift @ARGV;

# Slurp up the contents of the given filename
my $book_data = slurp $file;

# POST /=/model/book
my $response = $ua-&gt;request(POST HOST.'/=/model/book',
    'Content-Type' =&gt; 'text/yaml',
    Content        =&gt; $book_data
);

# On success, return the new ID assigned to the resource
if ($response-&gt;is_success) {
    my $url = $response-&gt;header('Location');
    my ($id) = $url =~ /([\d-]+)$/;
    print "$id: $url\n";
}

# On failure, barf
else {
    barf $response;
}
</code></pre>

<p>As you can see, this is exactly what we&#8217;ve done. Since the server requires the data to be specified as <code>text/yaml</code>, we&#8217;ve made sure to note that here. If the file is improperly formatted, the server will take note and return an error status, so I&#8217;m not being too picky about making sure the data is clean. However, you might want to make sure your data is sane before sending it in such cases just to avoid potential problems.</p>

<p>The other important detail to notice here is how we get the ID assigned to the resource back. We do it by checking the <code>Location</code> header. This is because we&#8217;ve build the server to return a <code>201 Created</code> status with a <code>Location</code> header referring us to the new resource location. If we were to perform an immediate <code>GET</code> on that location, we&#8217;d get the resource record we just saved back from the server. In fact, that&#8217;s probably what I should do. Instead, I&#8217;ve just ripped the ID off of the URL since I know what it will look like. This is a minor breach of the opacity principle of URIs, so if you&#8217;re sensitive about such things, I recommend you take the extra step and pull the ID from the returned YAML data.</p>

<h3>Updating a Resource</h3>

<p>Once we&#8217;ve added a resource, we might want to update to correct a typo or submit additional information to the record. We can do this by running:</p>

<pre><code>./book update 1-56563-833-6 treasury-updated.yml
</code></pre>

<p>As with the create command, we slurp up the file argument, but instead of a <code>POST</code>, we <code>PUT</code>. We also use the URL included the given ID.</p>

<pre><code>my $id   = shift @ARGV;
my $file = shift @ARGV;

# Slurp up the given file name
my $book_data = slurp $file;

# PUT /=/model/book/id/[id]
my $response = $ua-&gt;request(PUT HOST.'/=/model/book/id/'.$id,
    'Content-Type' =&gt; 'text/yaml',
    Content        =&gt; $book_data,
);

# On success, just announce success
if ($response-&gt;is_success) {
    print "Updated $id\n";
}

# On failure, barf
else {
    barf $response;
}
</code></pre>

<p>We again make sure to let the server know we&#8217;re passing it a YAML data file. Here the returned result is pretty empty, so we ignore everything but the status code and just return a success message. If we had implemented resource renaming on the server using <code>PUT</code>, we would probably need to watch the response for the new resource URI to make sure we fetch the new ID. Since we didn&#8217;t, we don&#8217;t.</p>

<h3>Deleting a Resource</h3>

<p>Finally, when a book gets lost or sold or just thrown away, we can delete it from the library. From the command line, this looks like this:</p>

<pre><code>./book delete 1-56563-833-6
</code></pre>

<p>Internally, the command is again very simple. This time, we just need to post a <code>DELETE</code> to the appropriate URL, <code>/=/model/book/id/&lt;ID&gt;</code> and check to see if it succeeded or not.</p>

<pre><code>my $id = shift @ARGV;

# DELETE /=/model/book/id/[id]
my $response = $ua-&gt;request(
    HTTP::Request-&gt;new( DELETE =&gt; HOST.'/=/model/book/id/'.$id )
);

# On success, announce it
if ($response-&gt;is_success) {
    print "Deleted $id\n";
}

# On failure, barf
else {
    barf $response;
}
</code></pre>

<p>First thing to note is that here we build the <code>DELETE</code> request ourselves. This is because <code>HTTP::Request::Common</code> did not provide a shortcut for <code>DELETE</code> when I originally wrote this client. I am happy to say that such a method exists as of 5.814 of <code>libwww-perl</code>. In case you aren&#8217;t able to use the latest version for some reason, this is how you live without. Fortunately, it&#8217;s not difficult to do this on our own.</p>

<p>Other than that, this should look remarkably similar to the update command minus the slurpy file action.</p>

<h3>RESTful Resources</h3>

<p>Now that you know the basics of building a REST server and client, you&#8217;re ready to move on to bigger and better things. Here are some resources for learning more about REST, for creating and using REST interfaces without building one yourself, for enhancing your REST interfaces, and some existing REST interfaces you might want to model or take advantage of.</p>

<h4>RESTful Documentation</h4>

<p>If you&#8217;re going to build a REST interface or work with one, it is helpful to find some details on what such things are commonly involved with. The most commonly referred to reference on the subject is the <a href="http://rest.blueoxen.net/">REST Wiki</a>. If you want to know the general outline of how some guys that think a lot about REST APIs in the abstract, this is a good resource.</p>

<p>An even more vital resource is the actual HTTP standard. It describes what the various request types and response types are for and how user agents should expect to deal with them. Since REST is tightly bound to HTTP, sticking to the proper behavior in HTTP is very important. Therefore, I recommend becoming familiar with <a href="http://www.w3.org/Protocols/HTTP/1.1/rfc2616bis/draft-lafon-rfc2616bis-03.html">RFC 2616</a>, which helps define the HTTP 1.1 protocol itself.</p>

<h4>RESTful Tools</h4>

<p>If you don&#8217;t want to mess so much with the code and just build on the foundation already laid by someone else, the best tool for the job that I currently know of is <a href="http://search.cpan.org/dist/OpenResty/">OpenResty</a>. This is a stand-alone REST database system. It&#8217;s essentially a middleware platform for accessing a database over HTTP and is a pretty good system to emulate.</p>

<p>I&#8217;m also partial to the REST plugin provided by Jifty. Just by implementing a few models and actions with Jifty, you get a REST interface to them for free. See <a href="http://search.cpan.org/dist/Jifty/lib/Jifty/Plugin/REST.pm">Jifty::Plugin::REST</a> for the server side implementation and <a href="http://search.cpan.org/dist/Net-Jifty/">Net::Jifty</a> for the client.</p>

<p>Both of these tools have a very similar feel to the implementation I&#8217;ve built for these articles because I like the style of Jifty&#8217;s implementation.</p>

<h4>RESTful Extensions</h4>

<p>The most significant RESTful API add-on I know of is <a href="http://oauth.net/">OAuth</a>. This tool provides a standard mechanism for sharing protected data between disparate services via REST. For example, let&#8217;s say you&#8217;re building an application that automatically sets the profile photo for several different social networking sites. You don&#8217;t want to store these photos, you just want to grab them and update a bunch of social networking sites. You could use OAuth to allow your users to grant you permission to access their Flickr or Picasaweb accounts without asking them for their username and password, which is one of those things that serious privacy advocates go bonkers over. </p>

<p>There are some big players implementing this and I&#8217;d love to see more mashups using this rather than asking me for my username/password to get photos or load contacts.</p>

<h4>RESTful Services</h4>

<p>There are lots and lots of RESTful web services available. However, I will highlight just a few that I have worked with personally in the past.</p>

<p>The first two are by Amazon. Amazon&#8217;s Web Services are all REST based, but the one&#8217;s I&#8217;ve worked with include S3 and EC2. With Amazon S3 you can store files on their services and be charged in micro-payments for just the storage you use and the amount of data transfer (which is pennies per Gigabyte). With Amazon EC2 you can run Linux-based servers that are started and stopped and manipulated using a REST-based service. These are again paid for in micro-payments by the hour (starting around 10 cents / server hour last I knew). There are Perl libraries already available for manipulating both of these without having to know the API directly too (search CPAN for Amazon).</p>

<p>The other I have worked a little bit with is Intuit Quickbase. Quickbase allows you to build database applications with a point-and-click interface. You can then pull and push data in and out of the system using a RESTful interface.</p>

<p>The last one I want to mention is <a href="http://www.hiveminder.com">Hiveminder</a>. Hiveminder is a web site for managing your to-do list. Hiveminder provides a number of different interfaces including an IMAP server interface and a RESTful Web API. Hiveminder is built with Jifty and has a special sub-class of <code>Net::Jifty</code> available for accessing the web API, <a href="http://search.cpan.org/dist/Net-Hiveminder/">Net::Hiverminder</a>.</p>

<h3>Conclusion</h3>

<p>There&#8217;s more that could be said and more resources I&#8217;d like to refer, but I think this article is plenty long. Adding a RESTful interface to a web application is a relatively simple thing to do and is great for giving folks a clean way to access and manipulate your application&#8217;s data.</p>

<p>Please feel free to comment here and I will try to answer any other questions or comments.</p>

<p>Cheers.</p>
]]>
        

    </content>
</entry>

</feed>
