<?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" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
 
 <title>RFelix.com</title>
 
 <link href="http://rfelix.com/" />
 <updated>2010-11-22T22:15:57+00:00</updated>
 <id>http://rfelix.com/</id>
 <author>
   <name>Raoul Felix</name>
   <email>rf@rfelix.com</email>
 </author>
 
 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/rfelix" /><feedburner:info uri="rfelix" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Code Kata Resources</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/mjWLu1XeeUw/codekata-resources" />
   <updated>2010-06-19T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/06/19/codekata-resources</id>
   <content type="html">&lt;div style="text-align: right; float: right; border: 0px solid black; text-align: center; font-size: 12px; margin-left: 3px; margin-top: 15px"&gt;
&lt;img src="http://rfelix.com/img/posts/kung-fu-kata.jpg" width="200" alt="Kung Fu Kata" style="display:block; margin-bottom: -2px; border: 0px solid black;"/&gt;
    &lt;div style="text-align: right"&gt;&lt;em&gt;&lt;small&gt;Photo by &lt;a href="http://www.flickr.com/photos/paulpker121/3890517667/"&gt;paulpker121&lt;/a&gt;&lt;/small&gt;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="quote" style="margin-top: 10px"&gt;Striving for success without hard work is like trying to harvest where you haven&amp;#8217;t planted. &lt;div class="author"&gt;&lt;span class="dash"&gt;—&lt;/span&gt; David Bly&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;One aspect in becoming a better programmer is actually programming. A lot. Whether you&amp;#8217;re learning a new programming language or honing your programming skills, Code Katas are the way to go. They&amp;#8217;re ideal because they&amp;#8217;re small exercises which don&amp;#8217;t occupy too much time, and are fun to do.&lt;/p&gt;
&lt;p&gt;I compiled a list of links for myself and thought that it might be of use to other people. Most of them can be done in any language, only the last four are more Ruby specific.&lt;/p&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;h3&gt;Code Katas:&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.rubyrailways.com/implementing-15-exercises-for-learning-a-new-programming-language/"&gt;15 Exercises for Learning a New Programming Language&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://codekata.pragprog.com/"&gt;Code Kata’s from the Pragmatic Programmers&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://topcoder.com/"&gt;Top Coder Challenges&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://projecteuler.net/"&gt;Project Euler&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://stackoverflow.com/questions/tagged/code-golf"&gt;Stack Overflow’s Code Golf&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://katas.softwarecraftsmanship.org/"&gt;Software Craftmanship Katas with videos&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://sites.google.com/site/tddproblems/" title="for learning Test-Driven Development"&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; Problems&lt;/a&gt; (Found via &lt;a href="http://www.jphamilton.net/"&gt;J.P. Hamilton&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8"&gt;UVa Online Judge Challenges&lt;/a&gt;  (Found via &lt;a href="http://www.jphamilton.net/"&gt;J.P. Hamilton&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://www.spoj.pl/problems/classical/"&gt;Sphere Online Judge Challenges&lt;/a&gt; (Found via &lt;a href="http://www.jphamilton.net/"&gt;J.P. Hamilton&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata"&gt;Prime Factors Kata&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata"&gt;The Bowling Game Kata&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://codingdojo.org/cgi-bin/wiki.pl?KataCatalogue"&gt;Kata Catalogue&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://www.rubyquiz.com"&gt;Ruby Quiz Challenges&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://rubylearning.com/blog/tag/rpcfn/"&gt;Ruby Programming Challenge for Newbies&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://github.com/edgecase/ruby_koans/tree/master" title="for Beginner Ruby Programmers"&gt;Ruby Koans&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://rubyproblems.com"&gt;RubyProblems&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Bonus&lt;/h3&gt;
&lt;p&gt;If you’d like to take this concept further and do Code Katas in groups, then you should read &lt;a href="http://www.dtsato.com/blog/wp-content/uploads/2008/06/sato-codingdojo.pdf"&gt;Coding Dojo: an environment for learning and sharing Agile practices&lt;/a&gt; which explains how to start a Coding Dojo and discusses the experiences of actually creating one.&lt;/p&gt;
&lt;p&gt;If you know of any other resources, drop me a line in the comments section. I’ll be sure to update the list and add your name + link for the reference.&lt;/p&gt;
&lt;p&gt;Until then, happy practicing.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/mjWLu1XeeUw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/06/19/codekata-resources</feedburner:origLink></entry>
 
 <entry>
   <title>Git Repo Hosting via SSH</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/ah4bznujVXI/git-repo-hosting-via-ssh" />
   <updated>2010-04-06T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/04/06/git-repo-hosting-via-ssh</id>
   <content type="html">&lt;div style="text-align: right; float: right; border: 0px solid black; text-align: center; font-size: 12px; margin-left: 3px; margin-top: 6px"&gt;
&lt;img src="http://rfelix.com/img/posts/sharing.png" width="144" alt="Sharing" style="display:block; margin-bottom: -2px; border: 0px solid black;"/&gt;
    &lt;div style="text-align: right"&gt;&lt;em&gt;&lt;small&gt;Photo by &lt;a href="http://www.flickr.com/photos/75511860@N00/3876516145/"&gt;Medmoiselle T&lt;/a&gt;&lt;/small&gt;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Do you use Git? Great! Do you have a Shared Hosting environment? Or just want to give other people access to your git repositories under one shell account? Then let me introduce you to &lt;a href="http://github.com/rfelix/hostgitrb"&gt;HostGitRb&lt;/a&gt;: Git repository sharing Ruby style.&lt;/p&gt;
&lt;h3&gt;Features&lt;/h3&gt;
&lt;ul&gt;
	&lt;li&gt;Easy to install&lt;/li&gt;
	&lt;li&gt;Git Repository sharing via &lt;span class="caps"&gt;SSH&lt;/span&gt; under one user (ideal for shared hosting)&lt;/li&gt;
	&lt;li&gt;User permission is based on their public keys&lt;/li&gt;
	&lt;li&gt;Users can &lt;strong&gt;only&lt;/strong&gt; pull/push Git repos, they can&amp;#8217;t login via &lt;span class="caps"&gt;SSH&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;p&gt;I do know about Gitosis, but I had a few problems installing it on my host, so I did what a respectable hacker would do and created my own stuff. Plus playing with rubies are way more fun than playing with pythons. :)&lt;/p&gt;
&lt;p&gt;Because time is precious, here are some shortcuts to help you jump around to the sections you need:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="#usecase1"&gt;Use Case 1&lt;/a&gt; &amp;#8211; Example of how to share Git repos for a University project&lt;/li&gt;
	&lt;li&gt;&lt;a href="#usecase2"&gt;Use Case 2&lt;/a&gt; &amp;#8211; Example of how to let a one user access multiple repos (even that of a different user)&lt;/li&gt;
	&lt;li&gt;&lt;a href="#reference"&gt;Reference&lt;/a&gt; &amp;#8211; Overview of command line options&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;It&amp;#8217;s easy as pie, just login to your server and install the gem: &lt;code&gt;gem install hostgitrb&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Alternatively, clone the &lt;a href="http://github.com/rfelix/hostgitrb"&gt;HostGitRb repository&lt;/a&gt; from GitHub and add the &lt;code&gt;bin/&lt;/code&gt; directory to your &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;span id="usecase1"&gt;Use Case 1 &amp;#8211; Group Project&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;I originally made these scripts to share a Git repository with friends for a University project, so I&amp;#8217;ll use that as an example to illustrate HostGitRb&amp;#8217;s functionality.&lt;/p&gt;
&lt;p&gt;On my host, I have a directory that contains all my Git repositories: &lt;code&gt;~/gitrepos&lt;/code&gt;. Under that directory, I created another one called &lt;code&gt;tjs&lt;/code&gt; which is a subject I&amp;#8217;m taking this semester (translates to Game and Simulation Technology).&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;tjs&lt;/code&gt; folder contains all the Git repos I want my group to access. There&amp;#8217;s actually only one repository in the directory, but hey, who&amp;#8217;s counting? It&amp;#8217;s called &lt;code&gt;xinkysworld.git&lt;/code&gt; (the name of our game).&lt;/p&gt;
&lt;p&gt;To give my friends access, I did the following:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Got their public keys (generated via &lt;code&gt;ssh-keygen -t rsa&lt;/code&gt;)&lt;/li&gt;
	&lt;li&gt;Logged in to my server and for each key I executed the following command: &lt;code&gt;hostgitrb --dir ~/gitrepos/tjs --key "ssh-rsa AAAAB3Nza..."&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;After that they can access the repository like so: &lt;code&gt;git clone rfe@rfelix.com:xinkysworld.git&lt;/code&gt; or even &lt;code&gt;git clone ssh://rfe@rfelix.com/xinkysworld.git&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Even though they&amp;#8217;re using my username to access the repository, &lt;strong&gt;they can&amp;#8217;t do anything else&lt;/strong&gt; other than push or pull from the Git repositories under the &lt;code&gt;tjs/&lt;/code&gt; directory. Great! Now they can&amp;#8217;t deface my site (yep, they&amp;#8217;re evil like that).&lt;/p&gt;
&lt;h3&gt;&lt;span id="usecase2"&gt;Use Case 2 &amp;#8211; One User, Multiple Repositories&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;If you&amp;#8217;re a student, your group members might overlap between projects. To allow one person access to different Git repositories, you can set something up that is kinda like GitHub&amp;#8217;s structure: &lt;code&gt;git@github.com:rfelix/hostgitrb.git&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Say you want to give the user &lt;code&gt;foo&lt;/code&gt; access to not only his own repo, but also to another that&amp;#8217;s shared between him and the user &lt;code&gt;bar&lt;/code&gt;. You can do something like:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Create a directory for him: &lt;code&gt;mkdir -p ~/gitrepos/foo&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Create his own repo under &lt;code&gt;~/gitrepos/foo/project.git&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Create a symlink of &lt;code&gt;bar&lt;/code&gt; &amp;#8217;s repository in &lt;code&gt;foo&lt;/code&gt; &amp;#8217;s directory: &lt;code&gt;ln -s ~/gitrepos/bar/shared.git ~/gitrepos/foo/shared.git&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Give his public key permission (from a file this time): &lt;code&gt;hostgitrb --dir ~/gitrepos/tjs --file ~/tmp/foo.pub&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now &lt;code&gt;foo&lt;/code&gt; can access whichever repository under his &lt;code&gt;foo/&lt;/code&gt; folder. For example, he can access the &lt;code&gt;shared.git&lt;/code&gt; repo via the url (using GitHub&amp;#8217;s url for comparison) &lt;code&gt;git@github.com:shared.git&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s not exactly the &lt;code&gt;&amp;lt;user&amp;gt;/&amp;lt;repository&amp;gt;.git&lt;/code&gt; structure like GitHub, but it works.&lt;/p&gt;
&lt;h3&gt;&lt;span id="reference"&gt;Reference&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Running &lt;code&gt;hostgitrb --help&lt;/code&gt; will give you a list of possible options you can use (thanks to &lt;a href="http://trollop.rubyforge.org/"&gt;Trollop&lt;/a&gt;):&lt;/p&gt;
&lt;pre&gt;
&amp;gt; hostgitrb --help
Options:
          --file, -f &amp;lt;s&amp;gt;:  Set path to public ssh key file (default: )
           --key, -k &amp;lt;s&amp;gt;:  Provide public ssh key as a string (default: )
           --dir, -d &amp;lt;s&amp;gt;:  Set full path to directory with git repositories to 
                           allow access to (default: )
          --readonly, -r:  Set access to repositories in --dir to read only
          --nobackup, -n:  Don't make backup of authorized_keys file
--authorizedkeys, -a &amp;lt;s&amp;gt;:  Set authorized_keys file (default: ~/.ssh/authorized_keys)
              --help, -h:  Show this message
&lt;/pre&gt;
&lt;p&gt;They&amp;#8217;re pretty much self-explanatory, but here are a few notes:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Use &lt;code&gt;--key&lt;/code&gt; when you have the &lt;span class="caps"&gt;SSH&lt;/span&gt; public key is in the clipboard (don&amp;#8217;t forget the &amp;quot;&amp;quot; due to spaces)&lt;/li&gt;
	&lt;li&gt;Use &lt;code&gt;--file&lt;/code&gt; when you have the actual public key file on your server.&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;--readonly&lt;/code&gt; makes sure the user can only execute &lt;code&gt;git pull&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;HostGitRb makes backups of the &lt;em&gt;authorized_keys&lt;/em&gt; file it modifies; stop this with &lt;code&gt;--nobackup&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;--authorizedkeys&lt;/code&gt; allows you to change the file that the new permission is added to.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Final Remarks&lt;/h3&gt;
&lt;p&gt;I&amp;#8217;ve put this out in the open source world in hope that this will also be helpful to someone else other than myself. If you have any problems let me know in the comments. Or if you find a bug, please add it to &lt;a href="http://github.com/rfelix/hostgitrb/issues"&gt;Issues&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Until next time, happy git repo sharing!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/ah4bznujVXI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/04/06/git-repo-hosting-via-ssh</feedburner:origLink></entry>
 
 <entry>
   <title>The Road to Awesomeness</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/8a8qC_2nHMI/the-road-to-awesomeness" />
   <updated>2010-03-15T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/03/15/the-road-to-awesomeness</id>
   <content type="html">&lt;div style="text-align: right; float: right; border: 0px solid black; text-align: center; font-size: 12px; margin-left: 3px;"&gt;
&lt;img src="http://rfelix.com/img/posts/road-to-awesomeness.jpg" width="260px" alt="Yellow Brick Road" style="display:block; margin-bottom: -2px; border: 0px solid black;"/&gt;
    &lt;div style="text-align: right"&gt;&lt;em&gt;&lt;small&gt;Photo by &lt;a href="http://www.flickr.com/photos/wychwood/2288440801/"&gt;Nick Owen&lt;/a&gt;&lt;/small&gt;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Wouldn’t you like to become an awesome programmer? &lt;br /&gt;
Be able to excel at your craft and write great code? &lt;br /&gt;
I’m sure you do, as do I. But, where do we start?&lt;/p&gt;
&lt;p&gt;Well, I found a series of blog posts the other day about being awesome, which is a good start on getting onto this mythical road. The series, written by Jamis Buck, is titled &lt;a href="http://weblog.jamisbuck.org/2009/9/17/there-is-no-magic-there-is-only-awesome-part-1"&gt;There is no magic, there is only awesome&lt;/a&gt; and is summarized in this post.&lt;/p&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;div class="quote" style="margin-top: 24px"&gt;Any sufficiently advanced technology is indistinguishable from magic. &lt;div class="author"&gt;&lt;span class="dash"&gt;—&lt;/span&gt; &lt;a href="http://weblog.jamisbuck.org/2009/9/17/there-is-no-magic-there-is-only-awesome-part-1"&gt;Clarke’s 3rd Law&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In order to achieve &lt;em&gt;awesomeness&lt;/em&gt;, we need to dispel the magic around that advanced technology. We need to understand the &lt;strong&gt;how’s&lt;/strong&gt;, &lt;strong&gt;what’s&lt;/strong&gt;, and &lt;strong&gt;why’s&lt;/strong&gt; of the things we use each day. With this in mind, Jamis suggests four cardinal rules to becoming awesome, each explained in different posts:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2009/9/25/there-is-no-magic-there-is-only-awesome-part-2"&gt;Know thy tools&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2009/10/9/there-is-no-magic-there-is-only-awesome-part-3"&gt;Know thy language&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2010/1/26/there-is-no-magic-there-is-only-awesome-part-4"&gt;Know thy libraries&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://weblog.jamisbuck.org/2010/1/26/there-is-no-magic-there-is-only-awesome-part-4"&gt;Know thy communities&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;What this series basically comes down to is that we should ask the four following questions with every tool, programming language, and library that we use:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;What does this do best?&lt;/li&gt;
	&lt;li&gt;What does this do worst?&lt;/li&gt;
	&lt;li&gt;Why should I use this in particular?&lt;/li&gt;
	&lt;li&gt;When was the last time I learnt something new about this?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If any of those questions can’t be answered, then it’s a &lt;strong&gt;sign to investigate further&lt;/strong&gt; and slay that magic dragon.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Actually knowing&lt;/em&gt; and being able to apply that knowledge is so much more important than just &lt;em&gt;knowing about&lt;/em&gt;. And that is essential to form an opinion about the things we use and answer the above questions. An opinion is crucial to becoming awesome because:&lt;/p&gt;
&lt;div class="quote"&gt;People without opinions are, frankly, boring. They’re pretty much the opposite of awesome. &lt;div class="author"&gt;&lt;span class="dash"&gt;—&lt;/span&gt;Jamis Buck in &lt;a href="http://weblog.jamisbuck.org/2009/9/25/there-is-no-magic-there-is-only-awesome-part-2"&gt;Know thy tools&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s a big NO NO.&lt;/p&gt;
&lt;p&gt;It’s also important to note that, even if we’re able to answer those questions, we should &lt;strong&gt;continue to learn&lt;/strong&gt; something new about the tools we use. Jamis suggests we try do that each day by reading something we didn’t know before. Then, &lt;strong&gt;integrate that knowledge&lt;/strong&gt; in what we’re doing, be it in a project we’re working on, playing around with simple code examples, or even blogging about it. Doing this will help cement the newly acquired knowledge. After that, we then need to &lt;strong&gt;use it repeatedly&lt;/strong&gt; so we don’t forget it.&lt;/p&gt;
&lt;p&gt;Now that we know the direction of &lt;em&gt;The Road to Awesomeness&lt;/em&gt;, the only thing standing in our way is ourselves. It’s now up to each one of us to pick up the torch and go down this road.&lt;/p&gt;
&lt;p&gt;Start with reading the posts in the series, then get to answering those questions and follow that yellow brick road to awesomeness. Leave any suggestions or experiences in the comments section.&lt;/p&gt;
&lt;p&gt;Until the next post, happy road trip!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/8a8qC_2nHMI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/03/15/the-road-to-awesomeness</feedburner:origLink></entry>
 
 <entry>
   <title>Book: Ruby Best Practices</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/S-nFOB-w1Hc/book-ruby-best-practices" />
   <updated>2010-03-07T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/03/07/book-ruby-best-practices</id>
   <content type="html">&lt;div style="border: 1px solid black; width: 100%; padding: 2px; margin-top: 4px"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt; The Ruby Best Practices book is now fully available as open source. You can now have access to the book&amp;#8217;s source and a &lt;span class="caps"&gt;PDF&lt;/span&gt; version, but seriously think about showing support and purchasing a hardcopy of your own. More info over at the &lt;a href="http://blog.rubybestpractices.com/posts/gregory/022-rbp-now-open.html"&gt;Ruby Best Practices blog&lt;/a&gt; &lt;span style="font-size: 8px;"&gt;(Updated on 17/03/2010)&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div style="text-align: right; float: right; border: 0px solid black; text-align: center; font-size: 12px; margin-left: 3px;"&gt;
&lt;img src="http://rfelix.com/img/posts/ruby-best-practices.png" width="140px" alt="Ruby Best Practices Book Cover" style="display:block; margin-bottom: -2px; border: 0px solid black;"/&gt;
&lt;/div&gt;
&lt;p&gt;After learning the basics of Ruby and feeling at ease with the language, it&amp;#8217;s time to take it to the next level. &lt;strong&gt;It&amp;#8217;s time to start writing code like the experts&lt;/strong&gt;: &lt;em&gt;the Ruby way&lt;/em&gt;. Ruby Best Practices is just the book to help you do that, with a friendly tone and lots of yummy code examples for you to chew on and learn.&lt;/p&gt;
&lt;p&gt;Read on to find out what to expect from the book and for some reading tips (that I wish I had done) on how to make the most out of it.&lt;/p&gt;
&lt;h3&gt;Overview&lt;/h3&gt;
&lt;p&gt;Ruby Best Practices was written by Gregory T. Brown and comes at 298 pages. The subtitle “Increase Your Productivity &amp;#8211; Write better Code” pretty much sums what the book is about: taking your Ruby skills to the next level by learning how to write code like the experts, thus increasing your productivity.&lt;/p&gt;
&lt;p&gt;The book covers a lot of topics such as (but not limited to): designing beautiful APIs, testing and debugging your code, taking advantage of Ruby’s dynamic features, and how to maintain your projects.&lt;/p&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;h3&gt;The Price&lt;/h3&gt;
&lt;p&gt;Ruby Best Practices costs $23.09 on &lt;a href="http://www.amazon.com/Ruby-Best-Practices-Gregory-Brown/dp/0596523009/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1267900286&amp;amp;sr=8-1"&gt;Amazon.com&lt;/a&gt; and £14.87 on &lt;a href="http://www.amazon.co.uk/Ruby-Best-Practices-Gregory-Brown/dp/0596523009/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1267900292&amp;amp;sr=8-1"&gt;Amazon.co.uk&lt;/a&gt; (around €16). You also get access to the online version of the book for 45 days from Safari Books Online.&lt;/p&gt;
&lt;p&gt;Gregory Brown is also open sourcing the book, so you can download the chapters yourself &lt;strong&gt;for free&lt;/strong&gt; to see if it&amp;#8217;s worth buying. I think it is. You can get the chapters from the &lt;a href="http://blog.rubybestpractices.com/"&gt;&lt;span class="caps"&gt;RBP&lt;/span&gt; Blog&lt;/a&gt; along with other high quality Ruby-related articles.&lt;/p&gt;
&lt;h3&gt;What You Get&lt;/h3&gt;
&lt;p&gt;At 298 pages, you get 8 chapters:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;em&gt;Driving Code Through Tests&lt;/em&gt; &amp;#8211; talks about code testing, mocks and stubs, and &lt;span class="caps"&gt;TDD&lt;/span&gt;.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Designing Beautiful APIs&lt;/em&gt; &amp;#8211; shows what Ruby features help you create elegant and easy to use APIs.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Mastering the Dynamic Toolkit&lt;/em&gt; &amp;#8211; explains Ruby’s many reflective capabilities and how to use them.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Text Processing and File Management&lt;/em&gt; &amp;#8211; tricks and tips to help you manage and process files.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Functional Programming Techniques&lt;/em&gt; &amp;#8211; goes through some functional techniques that can help you.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;When Things Go Wrong&lt;/em&gt; &amp;#8211; mentions ways to hunt for bugs when your program explodes.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Reducing Cultural Barriers&lt;/em&gt; &amp;#8211; explains various methods to make your apps internationally friendly.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Skillful Project Maintenance&lt;/em&gt; &amp;#8211; shows you and explains how Ruby projects are typically structured.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;And 3 appendices:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;em&gt;Writing Backward-Compatible Code&lt;/em&gt; &amp;#8211; useful for writing apps that need to work with any Ruby version.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Leveraging Ruby’s Standard Library&lt;/em&gt; &amp;#8211; some libraries you might not know about that can help.&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Ruby Worst Practices&lt;/em&gt; &amp;#8211; a collection of bad examples to learn from and avoid.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The Good&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Real Examples.&lt;/strong&gt; The code examples use throughout the book were extracted from actual open source projects. This is really great because you get to see how other people are actually solving problems, rather than just theoretical and abstract examples.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Practice Code Reading Skills.&lt;/strong&gt; Each chapter starts off with some sample code taken from an open source project, which you may not understand at first. This is a good exercise at reading other people&amp;#8217;s code, which is essential to becoming a better programmer. Once you get a grasp of the problem, Gregory Brown then goes into more detail and explains various techniques that can be used to solve that problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nice read.&lt;/strong&gt; I enjoyed the way the book was written. Gregory Brown writes in an easy-to-understand way, with a friendly &amp;#8220;voice&amp;#8221; which makes you feel like he is in the &lt;em&gt;trenches&lt;/em&gt; with you. Another thing I appreciated was that each chapter ended with a few bullet points summarizing the covered topics and offers some advice on when you might want to use some of them. (Check &lt;a href="#tip-2"&gt;Tip #2&lt;/a&gt; to make the most out of the examples).&lt;/p&gt;
&lt;h3&gt;The Bad&lt;/h3&gt;
&lt;p&gt;There&amp;#8217;s not much I didn&amp;#8217;t like about this book, only a few nitpicks really.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lost interest when I got to Chapter 7.&lt;/strong&gt; Although this is not the book&amp;#8217;s fault, rather it was me that wasn&amp;#8217;t really interested in that chapter (&amp;#8220;Reducing Cultural Barriers&amp;#8221;) to begin with. I just read it half way and then jumped to the next chapter which renewed my interest. (Check &lt;a href="#tip-1"&gt;Tip #1&lt;/a&gt; to avoid this).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Long examples with a lot of baggage.&lt;/strong&gt; The examples presented in the book, namely the ones at the beginning of each chapter, are sometimes long and need a bit of context. I actually think this is good, but some might not like it. What it comes down to is: this is not a cookbook for copy-and-pasting solutions straight into your project. The book tries to show you the many tools Ruby gives you to solve your problems, which you then have to transpose into your project and think about it.&lt;/p&gt;
&lt;h3&gt;Extra: Reading Tips&lt;/h3&gt;
&lt;p&gt;Here are a few reading tips that will help you make the most out of the &lt;span class="caps"&gt;RBP&lt;/span&gt; Book:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;span id="tip-1"&gt;&lt;strong&gt;Read the most interesting chapters first.&lt;/strong&gt;&lt;/span&gt; Each chapter is fairly self-contained so read the chapters in any order. This way you won’t rush through reading Chapter 1 just to get to Chapter 2, for example.&lt;/li&gt;
	&lt;li&gt;&lt;span id="tip-2"&gt;&lt;strong&gt;Reread the code examples.&lt;/strong&gt;&lt;/span&gt; Once you&amp;#8217;ve finished reading a chapter, before proceeding to the next, go back and reread the initial example that got you started. Make sure you now fully understand it.&lt;/li&gt;
	&lt;li&gt;&lt;span id="tip-3"&gt;&lt;strong&gt;Read your book next to the computer.&lt;/strong&gt;&lt;/span&gt; Take your time reading each chapter and pause often to actually try out the new concepts you&amp;#8217;ve learnt. And most importantly, play with the code, have fun!&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;And The Verdict&lt;/h3&gt;
&lt;p&gt;If you’re really interested in honing your Ruby coding skills, then this book is for you. It will show you how “real” Ruby code is written, what techniques you have at your disposal while tackling those hard-to-solve problems, and at the same time practice your code reading skills.&lt;/p&gt;
&lt;p&gt;Even though the book is being open sourced, I still think you should &lt;strong&gt;support the hard work of a fellow programmer&lt;/strong&gt; and buy a hardcopy. Personally, I prefer holding a book in my hand while reading, then again, I might be a bit “old-fashioned” that way. Plus, if you buy it then you&amp;#8217;re showing O&amp;#8217;Reilly that it&amp;#8217;s worth open sourcing their books.&lt;/p&gt;
&lt;p&gt;Hope you enjoy it. Happy reading!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/S-nFOB-w1Hc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/03/07/book-ruby-best-practices</feedburner:origLink></entry>
 
 <entry>
   <title>Bruce Lee, Water, and Programming</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/BjEcIE9L3YA/bruce-lee-water-programming" />
   <updated>2010-01-26T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/01/26/bruce-lee-water-programming</id>
   <content type="html">&lt;div style="text-align: center; margin-top: 5px"&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/MT_nuwm252I&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/MT_nuwm252I&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;div class="quote"&gt;Empty your mind, be formless, shapeless &amp;#8211; like water. Now you put water into a cup, it becomes the cup; you put water into a bottle, it becomes the bottle; you put it into a teapot, it becomes the teapot. Now water can flow or it can crash. Be water, my friend. &lt;div class="author"&gt;&lt;span class="dash"&gt;—&lt;/span&gt; Bruce Lee in an &lt;a href="http://www.youtube.com/watch?v=USlnfTGlhXc&amp;amp;feature=related"&gt;interview&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;When Bruce Lee said this, I&amp;#8217;m sure he wasn&amp;#8217;t thinking about programming. He was a great martial artist who knew his shit, but little did he know that us programmers can also apply his wisdom to our craft.&lt;/p&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;p&gt;Now that I&amp;#8217;ve finished my Programming Language Pragmatics class and discussed programming languages like Algol, &lt;span class="caps"&gt;ADA&lt;/span&gt;, Lisp, Scheme, Prolog, Smalltalk, C, C++, Java, C#, etc., I&amp;#8217;ve come to realize that there are a shit load of languages out there, each with their own set of pros and cons. Some thrive, others perish. Having this in mind, we can&amp;#8217;t put all our eggs in one basket and only learn one language. What if it flops?&lt;/p&gt;
&lt;p&gt;If there&amp;#8217;s any one constant thing about the IT industry, is that there is no such a thing as constant. We can rely on its unreliability. What&amp;#8217;s awesome and great today, can suck and disappear tomorrow.&lt;/p&gt;
&lt;h3&gt;So what is a programmer to do?&lt;/h3&gt;
&lt;p&gt;Bruce Lee has the answer: &lt;em&gt;be water, my friend&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Empty your mind&lt;/em&gt; &amp;#8211; we shouldn&amp;#8217;t treat any programming language like a religion. Just because it&amp;#8217;s &lt;a href="http://en.wikipedia.org/wiki/Turing_completeness"&gt;Turing Complete&lt;/a&gt;, it doesn&amp;#8217;t mean it should be used everywhere. You could build a web app in C++, but that would be like taking your teeth out with a hammer.&lt;/p&gt;
&lt;p&gt;We need to learn more than one language. More than two even. The more different, the better! It will help us to make informed decisions about the most suitable tool for the job, plus it will also help expand our minds and teach us to think differently. &lt;em&gt;Be formless, shapeless &amp;#8211; like water&lt;/em&gt;. Confining ourselves to one language will only make us stiff.&lt;/p&gt;
&lt;div class="quote"&gt;Notice that the stiffest tree is most easily cracked, while the bamboo and the willow survive by bending with the wind. &lt;div class="author"&gt;&lt;span class="dash"&gt;—&lt;/span&gt; Bruce Lee&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;We need to adapt, be dynamic, and have more than one language under our belt. We need to become a cup when we&amp;#8217;re in a cup; become a bottle when we&amp;#8217;re in a bottle; become Ruby when we&amp;#8217;re in Ruby. Be able to flow or crash when need be.&lt;/p&gt;
&lt;p&gt;This doesn&amp;#8217;t mean we should learn every language under the sun, jumping on the latest technology fad bandwagon like a dog after a frisbee.&lt;/p&gt;
&lt;p&gt;We need to learn at our own pace &amp;#8211; we&amp;#8217;re all different. It doesn&amp;#8217;t have to be one language a year; maybe one every two years is more suitable. &lt;br /&gt;
When we start to feel comfortable in a language, maybe that is a sign we should try another one.&lt;/p&gt;
&lt;p&gt;The most important is not the language you learn, it&amp;#8217;s what you learn from the language.&lt;/p&gt;
&lt;p&gt;Program a lot in &lt;a href="http://en.wikipedia.org/wiki/Java_(programming_language)"&gt;Java&lt;/a&gt;? Try &lt;a href="http://en.wikipedia.org/wiki/C_(programming_language)"&gt;C&lt;/a&gt;. &lt;br /&gt;
Sick of &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B"&gt;C++&lt;/a&gt;? Try &lt;a href="http://www.ruby-lang.org"&gt;Ruby&lt;/a&gt;!&lt;br /&gt;
Tired of juggling objects all day? Try something more functional like &lt;a href="http://www.plt-scheme.org/software/drscheme/"&gt;Scheme&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Lisp_(programming_language)"&gt;Lisp&lt;/a&gt;, or hardcore &lt;a href="http://www.haskell.org/"&gt;Haskell&lt;/a&gt;.&lt;br /&gt;
Hell, be strategic about this: go for &lt;a href="http://clojure.org/"&gt;Clojure&lt;/a&gt; for something lispy; &lt;a href="http://www.scala-lang.org/"&gt;Scala&lt;/a&gt; or &lt;a href="http://demo.erlang.org/"&gt;Erlang&lt;/a&gt; for something akin to Haskell.&lt;/p&gt;
&lt;p&gt;At the moment I&amp;#8217;m focusing on improving my Ruby-Fu, but afterwards I would love to look into Haskell or Scala.&lt;br /&gt;
&lt;strong&gt;What about you?&lt;/strong&gt; What languages do you plan on learning? Drop me a comment, lets have a chat.&lt;/p&gt;
&lt;p&gt;Whatever you do, remember to &lt;em&gt;bend with the wind&lt;/em&gt; and&lt;/p&gt;
&lt;h3&gt;&lt;em&gt;Be water, my friends&lt;/em&gt;.&lt;/h3&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/BjEcIE9L3YA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/01/26/bruce-lee-water-programming</feedburner:origLink></entry>
 
 <entry>
   <title>Jekyll Extensions -= Pain</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/lp2gqVBq4gA/jekyll-extensions-minus-equal-pain" />
   <updated>2010-01-19T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/01/19/jekyll-extensions-minus-equal-pain</id>
   <content type="html">&lt;div style="border: 1px solid black; width: 100%; padding: 2px; margin-top: 4px"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt; &lt;em&gt;jekyll_ext&lt;/em&gt; is now a gem and easy to install. See &lt;a href="#install"&gt;Installation&lt;/a&gt;. &lt;span style="font-size: 8px;"&gt;(Updated on 21/06/2010)&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div style="border: 1px solid black; width: 100%; padding: 2px; margin-top: 4px"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt; I&amp;#8217;ve created a wiki page over at GitHub to list all the extensions that use &lt;i&gt;jekyll_ext&lt;/i&gt;. At the moment it&amp;#8217;s a bit sparse, but hopefully that will change. Add your creations to the &lt;a href="http://wiki.github.com/rfelix/jekyll_ext/extensions"&gt;Extensions&lt;/a&gt; page. &lt;span style="font-size: 8px;"&gt;(Updated on 24/03/2010)&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;If you&amp;#8217;ve been using &lt;a href="jekyllrb.com/"&gt;Jekyll&lt;/a&gt; for your blog, you no doubt have needed to extend it in some way or another. Like me, you probably have your own forked version of Jekyll where you keep your customizations. This was fine in the beginning, but after a while it became kinda painful:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;b&gt;You can&amp;#8217;t use the Jekyll gem&lt;/b&gt; anymore because you&amp;#8217;re using your own version. Either make that a gem and use it, or just clone the repo and symlink it. You now have to worry about maintaining your fork when a new release comes out.&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;Forget about sharing your extensions&lt;/b&gt; with others. Actually, you can, using Git and its branching capabilities, but having to resolve conflicts takes the pleasure away.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Wouldn&amp;#8217;t it be great if you could extend Jekyll without creating your own fork? &lt;br /&gt;
Wouldn&amp;#8217;t it be even better if we could share and reutilize those extensions?&lt;/p&gt;
&lt;p&gt;Well, wait no more&amp;#8230;&lt;/p&gt;
&lt;h3&gt;Ladies and Gentlemen, may I present &lt;em&gt;jekyll_ext&lt;/em&gt;!&lt;/h3&gt;
&lt;p&gt;I&amp;#8217;ve come up with a solution that leverages Ruby&amp;#8217;s metaprogramming superpowers and its Open Class mechanism to give you:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Extensions that are local to the blog directory, stored under the &lt;em&gt;_extensions&lt;/em&gt; dir&lt;/li&gt;
	&lt;li&gt;Extensions that can be reutilized and shared&lt;/li&gt;
	&lt;li&gt;All this without modifying the Jekyll gem codebase&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;p&gt;As a bonus, this solution comes with 3 &lt;a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming"&gt;Aspect-Oriented Programming&lt;/a&gt; style helper methods (before, after, and around) to facilitate extension creation and also hide some of the metaprogramming &lt;strike&gt;&lt;a href="http://gilesbowkett.blogspot.com/2009/07/do-you-believe-in-magic.html"&gt;magic&lt;/a&gt;&lt;/strike&gt; code.&lt;/p&gt;
&lt;h3 id="install"&gt;Installing &lt;em&gt;jekyll_ext&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;gem install jekyll_ext&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Now you just need to create the directory &lt;em&gt;_extensions&lt;/em&gt; in your blog where all your extensions will live. Any &lt;em&gt;.rb&lt;/em&gt; file in that directory or subdirectory will automatically be loaded by &lt;em&gt;jekyll_ext&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;IMPORTANT&lt;/span&gt;&lt;/strong&gt;: Instead of using the &lt;code&gt;jekyll&lt;/code&gt; command, you should now use &lt;code&gt;ejekyll&lt;/code&gt; instead (which is just a jekyll wrapper that loads your extensions).&lt;/p&gt;
&lt;h3&gt;Extending Jekyll with &lt;em&gt;jekyll_ext&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;jekyll_ext&lt;/em&gt; attempts to load the file &lt;em&gt;jekyll_ext.rb&lt;/em&gt; located in the &lt;em&gt;_extensions&lt;/em&gt; directory of your blog. That file works as an entry point to load all the extensions that will be used when generating the site for your blog.&lt;/p&gt;
&lt;p&gt;The idea here is that you can use Ruby&amp;#8217;s Open Class mechanism to define new methods in Jekyll classes, or even replace them if need be. You can then use the &lt;span class="caps"&gt;AOP&lt;/span&gt; style helper functions I wrote to intercept method calls and add functionality to existing Jekyll class methods without actually changing the Jekyll code base:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;b&gt;before&lt;/b&gt; can be used when you want to execute some code before a method is invoked.&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;after&lt;/b&gt; can be used when you want to execute some code after a method is invoked.&lt;/li&gt;
	&lt;li&gt;&lt;b&gt;around&lt;/b&gt; can be used to control the execution of a method and to change the result returned by that method. With this you can execute code before and after the original method plus change the method&amp;#8217;s result.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a more general overview on how to use these methods you can have a look at the &lt;a href="http://github.com/rfelix/jekyll_ext/blob/master/specs/aop_spec.rb"&gt;specs&lt;/a&gt;. &lt;br /&gt;
The extensions I&amp;#8217;m using for my blog are also available on GitHub (&lt;a href="http://github.com/rfelix/my_jekyll_extensions"&gt;my_jekyll_extensions&lt;/a&gt;) which you can use in your own blog or just as example code to get you started.&lt;/p&gt;
&lt;h3&gt;Helper Methods in Detail&lt;/h3&gt;
&lt;p&gt;Here&amp;#8217;s a more detailed explanation of how you can actually use the helper methods:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;AOP.before(&amp;lt;Class to intercept&amp;gt;, &amp;lt;Name of Method to intercept&amp;gt;)&lt;/code&gt; &lt;br /&gt;
  Executes the block you pass to it before the method you supply is called. Your block receives the following as parameters:
	&lt;ol&gt;
		&lt;li&gt;The receiver of the intercepted method (the class&amp;#8217;s instance)&lt;/li&gt;
		&lt;li&gt;An array with the arguments that were passed to the method&lt;/li&gt;
	&lt;/ol&gt;&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;AOP.after(&amp;lt;Class to intercept&amp;gt;, &amp;lt;Name of Method to intercept&amp;gt;)&lt;/code&gt; &lt;br /&gt;
  Executes the block you pass to it after the method you supply is called. Your block receives the following as parameters:
	&lt;ol&gt;
		&lt;li&gt;The receiver of the intercepted method (the class&amp;#8217;s instance)&lt;/li&gt;
		&lt;li&gt;The method&amp;#8217;s result&lt;/li&gt;
		&lt;li&gt;An array with the arguments that were passed to the method&lt;/li&gt;
	&lt;/ol&gt;&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;AOP.around(&amp;lt;Class to intercept&amp;gt;, &amp;lt;Name of Method to intercept&amp;gt;)&lt;/code&gt;&lt;br /&gt;
Executes the block you pass to it around the method you supply, i.e. you control when the original method gets executed and can change its result. The value returned by the intercepted method will be whatever the last line in the block you supply evaluates to. Your block receives the following as parameters:
	&lt;ol&gt;
		&lt;li&gt;The receiver of the intercepted method (the class&amp;#8217;s instance)&lt;/li&gt;
		&lt;li&gt;The method&amp;#8217;s result&lt;/li&gt;
		&lt;li&gt;An array with the arguments that were passed to the method&lt;/li&gt;
		&lt;li&gt;Lambda/Proc that corresponds to the method that&amp;#8217;s been intercepted. You must &lt;strong&gt;explicitly&lt;/strong&gt; invoke the &lt;em&gt;call&lt;/em&gt; method on this proc to execute the intercepted method.&lt;/li&gt;
		&lt;li&gt;Lambda/Proc that can be used to explicitly abort the method. Whatever you pass when invoking the &lt;em&gt;call&lt;/em&gt; method as arguments will be returned by the intercepted method.&lt;/li&gt;
	&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once again, you can use &lt;a href="http://github.com/rfelix/my_jekyll_extensions"&gt;my jekyll extensions&lt;/a&gt; to see how all this comes together and allows you to extend Jekyll without touching its codebase.&lt;/p&gt;
&lt;p&gt;Hope this makes extending Jekyll less painfull for you as it did for me.&lt;br /&gt;
If you have any problems, drop me a comment and I&amp;#8217;ll try help you out as best I can.&lt;/p&gt;
&lt;p&gt;Happy Jekyll extending!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/lp2gqVBq4gA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/01/19/jekyll-extensions-minus-equal-pain</feedburner:origLink></entry>
 
 <entry>
   <title>Book: Don't Make Me Think!</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/6SORHWqjF28/book-dont-make-me-think" />
   <updated>2010-01-07T00:00:00+00:00</updated>
   <id>http://rfelix.com/2010/01/07/book-dont-make-me-think</id>
   <content type="html">&lt;div style="text-align: right; float: right; border: 0px solid black; text-align: center; font-size: 12px; margin-left: 3px;"&gt;
&lt;a href="http://www.amazon.co.uk/gp/product/0321344758?ie=UTF8&amp;tag=rfelicom-21&amp;linkCode=as2&amp;camp=1634&amp;creative=6738&amp;creativeASIN=0321344758"&gt;
&lt;img src="http://rfelix.com/img/posts/dont_make_me_think_2nd.png" width="140px" alt="don't make me think book cover" style="display:block; margin-bottom: -2px; border: 1px solid black;"/&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;I can&amp;#8217;t remember why I bought this book, but I&amp;#8217;m glad I did. The author, &lt;a href="http://stevekrug.com/"&gt;Steve Krug&lt;/a&gt;, is a web usability expert and basically wrote about almost everything he knows about web usability (so he says on his website).&lt;/p&gt;
&lt;p&gt;Even though this second version of the book was written way back in 2005, I found its content to still be applicable today. The only chapter that might be a bit outdated is Chapter 11: &amp;#8220;Accessibility, Cascade Style Sheets, and You&amp;#8221;. Nowadays I think everyone uses &lt;span class="caps"&gt;CSS&lt;/span&gt; and don&amp;#8217;t bother with html table based layouts anymore. Other than that little nitpick, the rest of the chapter, and book, is relevant and a good read.&lt;/p&gt;
&lt;h3&gt;It&amp;#8217;s Not Rocket Surgery!&amp;trade;&lt;/h3&gt;
&lt;p&gt;The subtitle is &amp;#8220;A Common Sense Approach to Web Usability&amp;#8221; which I think portrays the book quite well. The author explains many usability concepts in an easy to understand way, always showing things from a user&amp;#8217;s perspective.&lt;/p&gt;
&lt;p&gt;Don&amp;#8217;t think of it as a rule book, it does not tell you how to build sites &amp;#8220;the right way&amp;#8221;, nor does it bad mouth other websites. What is does do, is provide you with a set of guiding principles that you should take into consideration when designing your website. These principles are explained in a way that makes sense, and is accompanied by many examples and illustrations to show them in action. There are also many real world website designs that the author uses to show what works, what doesn&amp;#8217;t, and why. All of this comes at 184 pages, so it&amp;#8217;s a quick read, plus it&amp;#8217;s colorful and visually appealing which transmits a friendly feeling.&lt;/p&gt;
&lt;p&gt;&lt;!-- -**-END-**- --&gt;&lt;/p&gt;
&lt;h3&gt;Not web &lt;em&gt;apps&lt;/em&gt;, web&lt;strong&gt;&lt;em&gt;sites&lt;/em&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Even though the book is about web usability, it doesn&amp;#8217;t discuss web applications and focuses only on websites. Still, many of the guidelines presented in the book are also applicable to web applications. It essentially gives you a behind-the-scenes view of the world from a user&amp;#8217;s perspective, with a lot of tips on how to enhance the various elements of your site. This type of information is invaluable, whether your designing web applications or websites.&lt;/p&gt;
&lt;h3&gt;Lesson #1&lt;/h3&gt;
&lt;p&gt;The most important thing I take away from this book is exactly its title: Don&amp;#8217;t Make Me Think! It might seem silly, but only after reading the book did I realize the importance of designing your websites in the most clear and simple way possible. Forget about counting clicks, worry more about reducing the number of &amp;#8220;???&amp;#8221; (question marks) that popup in a user&amp;#8217;s head. It might only take 3 clicks to do something, but if it confuses the user, it won&amp;#8217;t matter. Once you realize there is no such thing as an &amp;#8220;average&amp;#8221; web user, things start falling into place.&lt;/p&gt;
&lt;h3&gt;Lesson #2&lt;/h3&gt;
&lt;p&gt;The second most important lesson for me is: do usability tests early, and do them often. Such things like the &amp;#8220;average web user&amp;#8221; and &amp;#8220;the right way to design websites&amp;#8221; are myths. They don&amp;#8217;t exist. It all depends on the context. Just because you like something, it doesn&amp;#8217;t mean that &lt;em&gt;everyone else will like it too&lt;/em&gt;. Want to see if your design works? Test it with actual people!&lt;/p&gt;
&lt;p&gt;Complicated tests aren&amp;#8217;t necessary, nor is it essential to find your &amp;#8220;target user&amp;#8221;, and you don&amp;#8217;t need to spend a lot of money or time. Steve shows you how to conduct simple, no hassle web usability tests which is accompanied by a sample test session so you actually get to &amp;#8220;see&amp;#8221; how it&amp;#8217;s done.&lt;/p&gt;
&lt;h3&gt;Verdict: Recommended&lt;/h3&gt;
&lt;p&gt;The only possible reason to not buy this book right now is because another 5 years have almost passed and a new version might be coming (1st Edition published October 2000; 2nd in August 2005). So it&amp;#8217;s up to you if you want to wait. But, if you think it can come in handy right now, then go ahead and order the book! One thing is for sure, your users will appreciate it!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/6SORHWqjF28" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2010/01/07/book-dont-make-me-think</feedburner:origLink></entry>
 
 <entry>
   <title>4 Queens Problem with Continuation-Passing Style</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/m5B_Hpu5iTQ/4-queens-problem-with-cps" />
   <updated>2009-12-28T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/12/28/4-queens-problem-with-cps</id>
   <content type="html">&lt;div style="text-align: center"&gt;
&lt;p&gt;(&lt;em&gt;This is post #2 of the &lt;a href="/2009/10/09/continuations-explained-with-ruby-series/"&gt;Continuations Explained with Ruby Series&lt;/a&gt;&lt;/em&gt;)&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In &lt;a href="/2009/10/09/introduction-to-continuation-passing-style/"&gt;post #1 of this series&lt;/a&gt;, I showed you how to save the computations of a factorial and how to manipulate the base condition. As I said, we can&amp;#8217;t do much with that, but it is the basis for what we&amp;#8217;re going to be looking at in this post.&lt;/p&gt;
&lt;h3&gt;4 Queens Problem&lt;/h3&gt;
&lt;p&gt;The problem we&amp;#8217;re going to solve in this post is the 4 Queens problem, which is just a simplified version of the &lt;a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle"&gt;8 Queens problem&lt;/a&gt;. The idea is that we have a 4&amp;#215;4 chess table, and 4 Queen chess pieces. We now have to position those 4 Queens in such a way that there is only one queen per line and none of them are able to capture any other using standard chess moves.&lt;/p&gt;
&lt;h3&gt;Detecting Collisions&lt;/h3&gt;
&lt;p&gt;To detect a collision between Queens, we need to check the columns and the diagonals. Collisions can be easily checked if we assign index positions to chess board matrix and keep 3 separate collision lists: one for columns and two for the diagonals. We update the collision lists whenever a Queen is placed. For the column list, we simply add the Queen&amp;#8217;s column position; for one diagonal, we add the sum of the Queen&amp;#8217;s line with the Queen&amp;#8217;s column to the list (called Diag+); and for the other diagonal, we add the subtraction of the line and column position to the list (called Diag-).&lt;/p&gt;
&lt;div style="width: 100%; text-align: center"&gt;
&lt;img src="http://rfelix.com/img/posts/continuations/4-queens-collision-table.png" alt="Example image showing collision calculations"/&gt;
&lt;/div&gt;
&lt;p&gt;For example, take a look at the above image. Lines and columns are labeled from 1 to 4. The Diag+ elements are in the lower triangle in dark grey, and the Diag- elements are in the upper triangle in white. In table (b), the Queen on line 1 can capture the Queen on line 2 because summing their line and column position both result in the same number (4). Queen on line 2 collides with Queen on line 3 because of Diag-: subtract their line and column positions and you get the same value (0). Queen in line 1 and line 3 also collide because they have the same column position.&lt;/p&gt;
&lt;h3&gt;Recursion&lt;/h3&gt;
&lt;p&gt;One way to solve this problem is to employ backtracking depth first search. Think of backtracking as being just like recursion, except that you&amp;#8217;re not sure if the path you took is the right one, so you need to be able to go backwards and take another path if need be.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a possible recursive solution to this problem:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
def queens_collide?(i, j, col, diag_plus, diag_minus)
  col.include?(j) || diag_plus.include?(i + j) || diag_minus.include?(i - j)
end

def place_queens(n, i, j, col, diag_plus, diag_minus)
  if i.zero?
    col
  elsif j.zero?
    false
  elsif queens_collide?(i, j, col, diag_plus, diag_minus)
    place_queens(n, i, j - 1, col, diag_plus, diag_minus)
  else
    queen_placed_ok = place_queens(
      n, i - 1, n, 
      col + [j], 
      diag_plus + [i + j], 
      diag_minus + [i - j]
    )
    if queen_placed_ok
      queen_placed_ok
    else
      place_queens(n, i, j - 1, col, diag_plus, diag_minus)   
    end
  end
end

def queens(n)
  place_queens(n, n, n, [], [], [])
end

puts queens(4).inspect
# &amp;gt;&amp;gt; [3, 1, 4, 2]
&lt;/pre&gt;
&lt;h3&gt;I Want More&lt;/h3&gt;
&lt;p&gt;The code I just presented to you works fine, but what if we didn&amp;#8217;t like that answer? What if we wanted to compute another solution? And another one after that?&lt;/p&gt;
&lt;p&gt;The key here is line 13, which represents the backtracking checkpoint. It&amp;#8217;s the point of the algorithm where, if the path taken by the recursion leads to a wrong answer (collision or if the end of the table is reached), then it has to backtrack up until that deciding point and choose another path. Also notice that the code in the line I mentioned is a non tail-recursive call, meaning that the line is a dependency which uses the stack to store intermediate results.&lt;/p&gt;
&lt;h3&gt;&lt;span class="caps"&gt;CPS&lt;/span&gt; &lt;span class="caps"&gt;FTW&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;The idea here is to make the dependencies explicit and thus avoid the usage of the stack, because once the method finishes it&amp;#8217;s computation, all the intermediate results disappear along with the call stack. And we want access to those saved computations, so we can use them to calculate other possible solutions. To do that, we&amp;#8217;ll transform the &lt;code&gt;place_queens&lt;/code&gt; recursive function into a tail-recursive one using the Continuation-Passing Style technique by making the implicit computations, which are stored in the stack, explicit using anonymous functions (lambdas):&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
$queens_continuation = nil

def queens_collide?(i, j, col, diag_plus, diag_minus)
  col.include?(j) || diag_plus.include?(i + j) || diag_minus.include?(i - j)
end

def place_queens(n, i, j, col, diag_plus, diag_minus, continuation)
  if i.zero?
    $queens_continuation = continuation
    continuation.call([])
  elsif j.zero?
    continuation.call(false)
  elsif queens_collide?(i, j, col, diag_plus, diag_minus)
    place_queens(n, i, j - 1, col, diag_plus, diag_minus, continuation)
  else
    queen_placed_ok = place_queens(
      n, i - 1, n, 
      col + [j], 
      diag_plus + [i + j], 
      diag_minus + [i - j],
      lambda do |r| 
        if r
          continuation.call(r + [j])
        else
          place_queens(n, i, j - 1, col, diag_plus, diag_minus, continuation)
        end
      end
    )
  end
end

def queens(n)
  place_queens(n, n, n, [], [], [], lambda { |r| r })
end

puts queens(4).inspect
# &amp;gt;&amp;gt; [2, 4, 1, 3]
&lt;/pre&gt;
&lt;p&gt;This code still produces a correct answer, even if it&amp;#8217;s not the same as the 1st recursive version.&lt;/p&gt;
&lt;p&gt;Now for the fun part. The global variable &lt;code&gt;$queens_continuation&lt;/code&gt; contains the final continuation of the method. In other words, after calling the function, not only do we get the results like normal, but we now have access to the computations that were performed to reach it.&lt;/p&gt;
&lt;p&gt;Therefore, if we call the continuation passing an empty array, we&amp;#8217;ll get the same answer:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
puts $queens_continuation.call([]).inspect
# &amp;gt;&amp;gt; [2, 4, 1, 3]
&lt;/pre&gt;
&lt;p&gt;If you take a look at the continuation we create at line 21, more specifically the &lt;code&gt;if&lt;/code&gt; statement, we check if the argument &lt;code&gt;r&lt;/code&gt; is true, in which case the lambda just calls the previous continuation with a list to be concatenated as the result. But if it&amp;#8217;s &lt;code&gt;false&lt;/code&gt;, then it&amp;#8217;s because it hasn&amp;#8217;t gotten to a valid result yet, so it continues to calculate Queen positions.&lt;/p&gt;
&lt;p&gt;So, with access to the final continuation when the function call finished, we can do some interesting stuff. Say that you don&amp;#8217;t like the first result and want another one. We just need to call the continuation with &lt;code&gt;false&lt;/code&gt; and it&amp;#8217;ll think that it the Queens have collided and will calculate another solution for us:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
puts $queens_continuation.call(false).inspect
# &amp;gt;&amp;gt; [3, 1, 4, 2]
&lt;/pre&gt;
&lt;p&gt;And once again, when it returns, we have our solution plus access to its computations in &lt;code&gt;$queens_continuation&lt;/code&gt;. So if we&amp;#8217;re still not happy with the result, we can call the continuation again with &lt;code&gt;false&lt;/code&gt;. Although, this time we ran out of solutions:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
puts $queens_continuation.call(false).inspect
# &amp;gt;&amp;gt; false
&lt;/pre&gt;
&lt;p&gt;But if we had initially called &lt;code&gt;queens(8)&lt;/code&gt;, we&amp;#8217;d have more solutions to go through. But I&amp;#8217;ll leave that &lt;b&gt;for you to try&lt;/b&gt;: fire up &lt;span class="caps"&gt;IRB&lt;/span&gt;, copy-and-paste the above code, invoke &lt;code&gt;queens(8)&lt;/code&gt;, and see how many possible solutions exist by passing &lt;code&gt;false&lt;/code&gt; to the continuation lambda in &lt;code&gt;$queens_continuation&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Moral of the Story&lt;/h3&gt;
&lt;p&gt;By making the dependencies of a normal recursive function explicit and removing the usage of the stack, we have the capacity to reutilize the previous computations and calculate more results, just like Prolog. If the compiler/interpreter is sufficiently smart to optimize tail-recursive functions, we also gain a performance boost! The only problem is Tail Call Optimization (&lt;span class="caps"&gt;TCO&lt;/span&gt;) is only done in some Ruby implementations: &lt;a href="http://ola-bini.blogspot.com/2007/01/yarv-tail-call-optimization-in-jruby.html"&gt;JRuby&lt;/a&gt; (limited) and &lt;a href="http://stackoverflow.com/questions/824562/does-ruby-perform-tail-call-optimization"&gt;&lt;span class="caps"&gt;YARV&lt;/span&gt;&lt;/a&gt; (not enabled by default).&lt;/p&gt;
&lt;p&gt;I hope you found this as interesting as I did when my teacher explained it to the class. I don&amp;#8217;t know if I&amp;#8217;ll ever need to do something like this again, but I found it really cool and wanted to share this with you all (even if I&amp;#8217;m the only reader of my blog =).&lt;/p&gt;
&lt;p&gt;If you have any questions, please, don&amp;#8217;t hesitate and drop me a comment.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/m5B_Hpu5iTQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/12/28/4-queens-problem-with-cps</feedburner:origLink></entry>
 
 <entry>
   <title>My Jekyll Extensions</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/vwgIu-C2Nyg/my-jekyll-extensions" />
   <updated>2009-12-21T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/12/21/my-jekyll-extensions</id>
   <content type="html">&lt;div style="border: 1px solid black; width: 100%; padding: 2px; margin-top: 4px"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;:&lt;/strong&gt; I have extracted my customizations into &lt;a href="http://github.com/rfelix/my_jekyll_extensions"&gt;portable extensions&lt;/a&gt; using that you can use in your own Jekyll-powered blog. Read &lt;a href="/2010/01/19/jekyll-extensions-minus-equal-pain/"&gt;Jekyll Extensions -= Pain&lt;/a&gt; for more information on how to use &lt;a href="http://github.com/rfelix/jekyll_ext"&gt;jekyll_ext&lt;/a&gt; to extend Jekyll without modifying the Jekyll gem codebase. &lt;span style="font-size: 8px;"&gt;(Updated on 19/01/2010)&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I&amp;#8217;ve been getting some of traffic from my listing in the Jekyll &lt;a href="http://wiki.github.com/mojombo/jekyll/sites"&gt;Sites&lt;/a&gt; page, so I take it that people are interested in the &lt;a href="http://github.com/rfelix/jekyll"&gt;extensions I made to get Jekyll&lt;/a&gt; to fit my needs. In this post I&amp;#8217;ll explain some of the modifications that I did and how to use. I will also point out the modifications I made to the Jekyll code base, in case you wan&amp;#8217;t to incorporate some specific changes in your own customization.&lt;/p&gt;
&lt;h3&gt;&lt;span id="category-listing"&gt;Category Listing&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Jekyll by default only allows you to get a list of posts that belong to a category if you specify that category name: &lt;code&gt;site.categories.CATEGORY&lt;/code&gt;. But what I also wanted to do was iterate through the all the categories I have in order to generate a category/topics page.&lt;/p&gt;
&lt;p&gt;After stumbling around the Jekyll code base and messing with things, figuring out what code does what, I managed to do exactly what I wanted. You can see the results for yourself in the &lt;a href="/topics"&gt;Topics&lt;/a&gt; section of this blog. The alteration was actually quite simple (after a bit of fiddling), you can find the code in &lt;a href="http://github.com/rfelix/jekyll/blob/master/lib/jekyll/site.rb"&gt;lib/jekyll/site.rb&lt;/a&gt; under the following methods: &lt;code&gt;site_payload&lt;/code&gt; and &lt;code&gt;make_iterable&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To use this feature, all you need to do is iterate over &lt;code&gt;site.iterable.categories&lt;/code&gt;. You then have access to the category&amp;#8217;s name and the posts that belong to it by accessing the properties &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;posts&lt;/code&gt;. Here&amp;#8217;s part of the code I used to generate my &lt;a href="/topics"&gt;Topics&lt;/a&gt; for a complete example: &lt;a href="https://gist.github.com/f7116fb5889d8520a635#file_category%20(topics)%20listing%20example"&gt;Category/Topics Listing Liquid Markup&lt;/a&gt; &lt;small&gt;(Sorry for linking to a Gist, but I wasn&amp;#8217;t able to properly display that code here due to my failed attempt at escaping the liquid markup I&amp;#8217;m trying to show you).&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;Shorten Filter&lt;/h3&gt;
&lt;p&gt;I wanted my home page to display just the most recent post, and then below it display the titles of the other posts in chronological order (this is a blog after all). But, because some titles might be a bit long, I wanted a way to limit the number of words that can appear in a title and only show some words from the beginning and end with &amp;#8220;&amp;#8230;&amp;#8221; for the middle. For example, my post title &lt;a href="/2009/01/23/syntax-highlighting-code-in-posts-with-textmate/"&gt;&amp;#8220;Syntax Highlighting Code in Posts with Textmate&amp;#8221;&lt;/a&gt; when passed to the shorten filter becomes &amp;#8220;Syntax Highlighting Code&amp;#8230;with Textmate&amp;#8221;.&lt;/p&gt;
&lt;p&gt;The code for this filter can be found under the method &lt;code&gt;shorten&lt;/code&gt; in &lt;a href="http://github.com/rfelix/jekyll/blob/master/lib/jekyll/filters.rb"&gt;lib/jekyll/filters.rb&lt;/a&gt;. Just call it like any other filter and pass the maximum number of characters as its argument, like so: &amp;#123;&amp;#123; post.title | shorten: 45 &amp;#125;&amp;#125;&lt;/p&gt;
&lt;h3&gt;Categories in _posts&lt;/h3&gt;
&lt;p&gt;I made this alteration because I wanted to use categories in my blog, but I didn&amp;#8217;t want them spread around in various directories. Now all my posts live happily under their own category in the _posts directory. This feature was implemented easily in 4 lines of code, which can be found in &lt;a href="http://github.com/rfelix/jekyll/blob/master/lib/jekyll/post.rb"&gt;lib/jekyll/post.rb&lt;/a&gt; under method &lt;code&gt;initialize&lt;/code&gt; (lines 41-45).&lt;/p&gt;
&lt;h3&gt;Pretty &lt;span class="caps"&gt;URL&lt;/span&gt; but without the Category&lt;/h3&gt;
&lt;p&gt;At the time I setup my blog, I was so busy hacking away that I completely missed that you could specify the exact &lt;a href="http://wiki.github.com/mojombo/jekyll/permalinks"&gt;permalink&lt;/a&gt; structure in your &amp;#8220;_config.yml&amp;#8221; file. So my customization has an additional permalink style, which can be found under the method &lt;code&gt;template&lt;/code&gt; in &lt;a href="http://github.com/rfelix/jekyll/blob/master/lib/jekyll/post.rb"&gt;lib/jekyll/post.rb&lt;/a&gt;, called &amp;#8220;pretty_no_category&amp;#8221;. At least now what appears under the permalink option in &amp;#8220;_config.yml&amp;#8221; is &lt;code&gt;permalink:pretty_no_category&lt;/code&gt; rather than &lt;code&gt;permalink: /:year/:month/:day/:title&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Future Extensions&lt;/h3&gt;
&lt;p&gt;In the future, I plan on adding the same support for Category iteration to Tags. This should be implemented quite easily seeing as I already have a helper function (&lt;code&gt;make_iterable&lt;/code&gt; mentioned in &lt;a href="#category-listing"&gt;Category Listing&lt;/a&gt;) that I used for the categories. Other than that, Jekyll serves its purpose just fine!&lt;/p&gt;
&lt;p&gt;I didn&amp;#8217;t put the code for my site on GitHub because I didn&amp;#8217;t think that people would be interested in it. But if you would like to check it out, drop a comment. If I see there&amp;#8217;s enough interest, I&amp;#8217;ll put it up.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/vwgIu-C2Nyg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/12/21/my-jekyll-extensions</feedburner:origLink></entry>
 
 <entry>
   <title>You Know You're a Geek When...</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/JyHSDrPPVO4/you-know-youre-a-geek-when" />
   <updated>2009-12-03T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/12/03/you-know-youre-a-geek-when</id>
   <content type="html">&lt;div style="text-align: right; float: right; border: 0px solid black"&gt;
&lt;img src="http://rfelix.com/img/posts/know-geek/gpl.png" alt="gpl" style="display:block; margin-bottom: -2px;"/&gt;
&lt;/div&gt;
&lt;p&gt;While driving back and forth from classes at University, every now and again I see a car with a &lt;span class="caps"&gt;GPL&lt;/span&gt; sticker on.&lt;/p&gt;
&lt;p&gt;Now, you know you&amp;#8217;re a (portuguese) geek when&amp;#8230;&lt;/p&gt;
&lt;p&gt;The first thing that pops into your head whenever you see that sign is &lt;a href="http://www.gnu.org/licenses/gpl.html"&gt;General Public License&lt;/a&gt; rather than &amp;#8220;&lt;a href="http://pt.wikipedia.org/wiki/Gás_de_petróleo_liquefeito"&gt;G&amp;aacute;s de petr&amp;oacute;leo liquefeito&lt;/a&gt;&amp;#8221; (&lt;a href="http://en.wikipedia.org/wiki/Liquefied_petroleum_gas"&gt;Liquefied petroleum gas&lt;/a&gt; in english).&lt;/p&gt;
&lt;p&gt;(And it happens every time&amp;#8230;)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/JyHSDrPPVO4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/12/03/you-know-youre-a-geek-when</feedburner:origLink></entry>
 
 <entry>
   <title>Introduction to Continuation-Passing Style</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/WKFB-aKYUYI/introduction-to-continuation-passing-style" />
   <updated>2009-10-09T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/10/09/introduction-to-continuation-passing-style</id>
   <content type="html">&lt;div style="text-align: center"&gt;
&lt;p&gt;&lt;em&gt;This post #1 of the &lt;a href="/2009/10/09/continuations-explained-with-ruby-series/"&gt;Continuations Explained with Ruby Series&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div style="text-align: right; float: right; border: 0px solid black"&gt;
&lt;img src="http://rfelix.com/img/posts/continuations/recursion-small.jpg" alt="recursion" style="display:block; margin-bottom: -2px;"/&gt;
&lt;em&gt;&lt;small&gt;Photo by &lt;a href="http://www.flickr.com/photos/gadl/279433682/"&gt;gadl&lt;/a&gt;&lt;/small&gt;&lt;/em&gt;
&lt;/div&gt;
&lt;h3&gt;Recursion &amp;amp; Tail-Recursion&lt;/h3&gt;
&lt;p&gt;For those of you that are reading my blog, you already probably know what recursion is. Still, I would like to share with you one of my favorite definitions of recursion: &lt;em&gt;&amp;#8220;Definition of Recursion: If you still don&amp;#8217;t get it, see the definition of recursion.&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now, it is generally agreed upon that using recursion tends to be a lot slower and occupies a lot more memory that the iterative version. This isn&amp;#8217;t always the case. It is more accurate to say that a &lt;em&gt;naive implementation&lt;/em&gt; of iteration is usually more efficient than a &lt;em&gt;naive implementation&lt;/em&gt; of recursion.&lt;/p&gt;
&lt;p&gt;The major advantage that iteration has over recursion is that it doesn&amp;#8217;t allocate as much space on the run-time stack to store local variable and bookkeeping information.&lt;/p&gt;
&lt;p&gt;This advantage can be minimized if an &amp;#8220;optimizing&amp;#8221; compiler is used, in particular, one for a Functional Programming Language which is able to generate excellent code for recursive functions, especially for tail-recursive functions.&lt;/p&gt;
&lt;p&gt;A tail-recursive function is one that doesn&amp;#8217;t have any additional computations along with the recursive call. In other words, the function&amp;#8217;s return statement is just another call to the function itself, without any pending operations. Let&amp;#8217;s take a look at some code to better illustrate the point:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
# Normal recursive version of Factorial
def fact_r(n)
  return 1 if n == 0
  # Here's the pending operation with a call to a recursive function:
  n * fact_r(n - 1) 
end

# Tail-Recursive version of Factorial
def fact_tr(n)
  def fact_aux(n, accumulator)
    return accumulator if n == 0
    # No pending operations here, only a call to the recursive function:
    fact_aux(n - 1, accumulator * n)
  end
  fact_aux(n, 1)
end
&lt;/pre&gt;
&lt;p&gt;The tail-recursive function is much faster because the compiler doesn&amp;#8217;t need to dynamically allocate space on the stack for the pending operations. It can just reuse the space belonging to the current iteration when the tail-recursive function is called.&lt;/p&gt;
&lt;h3&gt;Transforming Non-Tail-Recursive functions into Tail-Recursive ones&lt;/h3&gt;
&lt;p&gt;By using Continuation-Passing style, a compiler for a functional language can automatically optimize a non-tail-recursive function into a tail-recursive one, which, in turn, allows it to apply further optimizations.&lt;/p&gt;
&lt;p&gt;But before we continue, we need to know what a Continuation is. According to Wikipedia, a &lt;a href="http://en.wikipedia.org/wiki/Continuation"&gt;Continuation&lt;/a&gt; is an abstract representation of the control state. In other words, they allow you to represent computations with dependencies in an explicit manner.&lt;/p&gt;
&lt;p&gt;Now, let&amp;#8217;s take a look at the &lt;code&gt;fact_r&lt;/code&gt; function from the above example, more specifically, the last line of the function: &lt;code&gt;n * fact_r(n - 1) &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;What we see here is a clear example of a computation with dependencies: &lt;code&gt;fact(3)&lt;/code&gt; has to wait for &lt;code&gt;3 * fact(2)&lt;/code&gt; to be computed, which in turn needs to wait for &lt;code&gt;2 * fact(1)&lt;/code&gt; to be computed, which still needs to wait for &lt;code&gt;1 * fact(0)&lt;/code&gt; to be computed.&lt;/p&gt;
&lt;p&gt;Now, how can remove those dependencies? First, we have to add a new argument to the function that will contain the continuation. Then, instead of performing the operation that causes the recursive function to wait, we wrap it in a lambda to be calculated later on. Only when we get to the base condition of the recursive function do we actually execute the continuation, which will then calculate the result and present it to us. This is easier to see in an example:&lt;/p&gt;
&lt;pre class="brush:ruby"&gt;
def fact_cps(n, c)
  if n == 0
    c.call(1)
  else
    fact_cps(n - 1, lambda { |r| c.call(n * r) })
  end
end

&amp;gt; fact_cps(5, lambda { |r| r })
120
&lt;/pre&gt;
&lt;p&gt;What we&amp;#8217;re doing is transferring the control to another function, either &lt;code&gt;fact_cps&lt;/code&gt; or to the continuation &lt;code&gt;c&lt;/code&gt;, without leaving any dependent computations in the stack.&lt;/p&gt;
&lt;p&gt;As I said earlier, using &lt;span class="caps"&gt;CPS&lt;/span&gt; results in a tail-recursive function, so the stack doesn&amp;#8217;t grow like a normal recursive function. But, because we use lambdas and chain them, they get allocated in the heap instead. Once used, the Garbage Collector will then clean up after us.&lt;/p&gt;
&lt;h3&gt;First steps towards imitating Prolog&amp;#8217;s backtracking capability&lt;/h3&gt;
&lt;p&gt;Now let&amp;#8217;s have some fun messing around with &lt;span class="caps"&gt;CPS&lt;/span&gt;: when &lt;code&gt;n&lt;/code&gt; reaches &lt;code&gt;0&lt;/code&gt;, what would happen if we saved the continuation in a global variable?&lt;/p&gt;
&lt;pre class="brush:ruby"&gt;
def fact_cps(n, c)
  if n == 0
    $end_fact_cps = c
    c.call(1)
  else
    fact_cps(n - 1, lambda { |r| c.call(n * r) })
  end
end
&amp;gt; fact_cps(5, lambda { |r| r })
120
&lt;/pre&gt;
&lt;p&gt;After calling the new &lt;code&gt;fact_cps&lt;/code&gt; for the first time, the global variable &lt;code&gt;$end_fact_cps&lt;/code&gt; contains a reference to the continuation that was used, i.e. we now have access to the computations that were performed while calculating the factorial of 5. We can now play around with them:&lt;/p&gt;
&lt;pre class="brush:ruby"&gt;
&amp;gt; $end_fact_cps.call(1) # 5 * 4 * 3 * 2 * 1
120
&amp;gt; $end_fact_cps.call(2) # 5 * 4 * 3 * 2 * 2
240
&amp;gt; $end_fact_cps.call(3) # 5 * 4 * 3 * 2 * 3
360
&lt;/pre&gt;
&lt;p&gt;Calling the saved continuation with 1 makes it calculate the result as if we were calling &lt;code&gt;fact_cps&lt;/code&gt; with 5. When we call it with 2, or 3, what we&amp;#8217;re doing is changing the value that&amp;#8217;s used when the base condition of the recursive function is reached. So, instead of calculating the factorial of 5, we calculate the double and the triple of the factorial of 5.&lt;/p&gt;
&lt;p&gt;Now, I admit this is nothing special, but it&amp;#8217;s the basis for what we&amp;#8217;re going to explore in the next blog post in the series. We&amp;#8217;re going to be doing something similar to create a recursive backtracking function that will allow us to produce different solutions to the 4-Queens problem (simpler version of the &lt;a href="http://en.wikipedia.org/wiki/Eight_queens_puzzle"&gt;8-Queens problem&lt;/a&gt;) depending on user input &amp;#8211; something that Prolog does easily.&lt;/p&gt;
&lt;p&gt;I hope you were able to understand how to use Continuation-Passing style to explicitly represent computations with dependencies in a recursive function.&lt;/p&gt;
&lt;p&gt;If you have any questions, I&amp;#8217;ll gladly try and answer them. Just drop me a comment!&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s it for now, hope to see you here for the next post in the series where we&amp;#8217;ll do a lot more interesting things! Until then&amp;#8230;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/WKFB-aKYUYI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/10/09/introduction-to-continuation-passing-style</feedburner:origLink></entry>
 
 <entry>
   <title>Continuations Explained with Ruby (Series)</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/jXLeoMWd2hw/continuations-explained-with-ruby-series" />
   <updated>2009-10-09T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/10/09/continuations-explained-with-ruby-series</id>
   <content type="html">&lt;p&gt;In my &lt;span class="caps"&gt;PLP&lt;/span&gt; class (Pragm&amp;aacute;tica das Linguagens de Programa&amp;ccedil;&amp;atilde;o/Programming Language Pragmatics) we&amp;#8217;ve been talking about continuations in Scheme and how they allow us to do some pretty interesting stuff.&lt;/p&gt;
&lt;p&gt;As &lt;em&gt;they&lt;/em&gt; say, in order to understand something properly, you&amp;#8217;ve gotta be able to explain it to someone else. So I&amp;#8217;m going to give it a shot and try to explain what Continuations are and how they can be used using Ruby as my language of choice.&lt;/p&gt;
&lt;p&gt;Before we continue, let me just get a few things straightened out:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;I do not claim to be an expert on this subject, so if you happen to find an error, please let me know. I&amp;#8217;m just explaining what I learnt in class and by reading up on it (Programming Language Pragmatics book by Michael L. Scott and Wikipedia).&lt;/li&gt;
	&lt;li&gt;I don&amp;#8217;t plan to cover &lt;em&gt;everything&lt;/em&gt; about continuations. For the moment I&amp;#8217;m just going to focus on explaining &lt;a href="http://en.wikipedia.org/wiki/Continuation_passing_style"&gt;Continuation-Passing style&lt;/a&gt; (&lt;span class="caps"&gt;CPS&lt;/span&gt;) using Ruby. Other things like Ruby Fibers or &lt;a href="http://en.wikipedia.org/wiki/Call-with-current-continuation"&gt;Call-with-Current-Continuation&lt;/a&gt; (call/cc) won&amp;#8217;t be discussed for the time being (but may come at a later stage).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Table of Contents&lt;/h3&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;&lt;a href="/2009/10/09/introduction-to-continuation-passing-style/"&gt;Introduction to Continuation-Passing Style&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
  Recursion vs. Iteration; Tail Recursion; Transforming a non-tail recursive function into a tail recursive one using &lt;span class="caps"&gt;CPS&lt;/span&gt;; Saving computations and avoiding the stack (kinda like Prolog).&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;&lt;a href="/2009/12/28/4-queens-problem-with-cps"&gt;4 Queens Problem with &lt;span class="caps"&gt;CPS&lt;/span&gt;&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
  4 Queens Problem; Recursive Solution; Solution using &lt;span class="caps"&gt;CPS&lt;/span&gt; that uses backtracking like Prolog and is capable of returning more than one solution (without duplicating calculations).&lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/jXLeoMWd2hw" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/10/09/continuations-explained-with-ruby-series</feedburner:origLink></entry>
 
 <entry>
   <title>Game of My Life</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/0suS_mr9X-k/game-of-my-life" />
   <updated>2009-09-26T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/09/26/game-of-my-life</id>
   <content type="html">&lt;p&gt;Last week the teacher of my &lt;span class="caps"&gt;DDJ&lt;/span&gt; class (Desenho e Desenvolvimento de Jogos/Design and Development of Games) asked us a simple question: what is the game of your life and why? We were then sent home to think about it and prepare a quick, 4 minute presentation on it.&lt;/p&gt;
&lt;p&gt;At first, I wasn&amp;#8217;t sure what game I was going to choose, seeing as I don&amp;#8217;t play &lt;em&gt;that&lt;/em&gt; much. But of all the games I&amp;#8217;ve played, which one did I &lt;em&gt;really&lt;/em&gt; like? Which one was my favorite of all? Which one did I have the most fun playing?&lt;/p&gt;
&lt;p&gt;After a few minutes, a name just drifted into my head&amp;#8230; &lt;br /&gt;
Solid Snake.&lt;/p&gt;
&lt;p&gt;What follows is the text that I wrote to sort out my ideas and to help prepare the basis for my presentation. I had to present it in portuguese, so it&amp;#8217;s not exactly what I said, but very close. The images you see to the right are the slides I made to go along with the presentation.&lt;/p&gt;
&lt;h3&gt;So, without further ado&amp;#8230;&lt;/h3&gt;
&lt;div style="float: right; clear:both; text-align: right; margin-top: 10px; margin-bottom: 10px; margin-left: 5px; padding-top: 15px"&gt;&lt;img src="/img/posts/goml/mgs1.png" alt="MGS Slide 1"/&gt;&lt;/div&gt;
&lt;p&gt;I don&amp;#8217;t only have one game of my life, per say. I have four games of my life, and they&amp;#8217;re all part of the Metal Gear Solid series. I like &lt;span class="caps"&gt;MGS&lt;/span&gt; so much that I saved money for a year and a half just to buy a Playstation 3 because I knew MGS4 would come out exclusively for it.&lt;/p&gt;
&lt;p&gt;Why do I like this game so much? Three reasons:&lt;/p&gt;
&lt;h3&gt;1. Stealth&lt;/h3&gt;
&lt;div style="float: right; clear:both; text-align: right; margin-right: 0; margin-bottom: 0px; margin-left: 5px;"&gt;&lt;img src="/img/posts/goml/mgs2.png"
 alt="MGS Slide 2"/&gt;&lt;/div&gt;
&lt;p&gt;&lt;span class="caps"&gt;MGS&lt;/span&gt; popularized the Stealth Action video game genre. You sneak around, trying to evade all the enemies. You can take them out, or you can just try go around them and avoid confrontation. You do all this in a Ninja like fashion; the only thing missing is a sword. In the more recent games, you now have camouflage to help while moving around undetected.&lt;/p&gt;
&lt;p&gt;I just think that the game not forcing you to kill everyone is really awesome. I mean sure, killing the enemy is pretty fun, but not making it obligatory is just as fun and is actually harder to do.&lt;/p&gt;
&lt;h3&gt;2. Story line&lt;/h3&gt;
&lt;div style="float: right; clear:both; text-align: right; margin-right: 0; margin-bottom: 10px; margin-left: 5px; margin-top: -10px"&gt;&lt;img src="/img/posts/goml/mgs3.png"
 alt="MGS Slide 3"/&gt;&lt;/div&gt;
&lt;p&gt;The story behind Metal Gear Solid, in my opinion, is just great! It talks about so many different things: it has secret military conspiracy theories, nuclear weapons, war, cloning, artificial intelligence, censorship, and much more. I admit that it gets bit complex at times, but that&amp;#8217;s exactly what I like about it.&lt;/p&gt;
&lt;h3&gt;3. Cinematic&lt;/h3&gt;
&lt;div style="float: right; clear:both; text-align: right; margin-right: 0; margin-bottom: 20px; margin-left: 5px;"&gt;&lt;img src="/img/posts/goml/mgs4.png"
  alt="MGS Slide 4"/&gt;&lt;/div&gt;
&lt;p&gt;Playing &lt;span class="caps"&gt;MGS&lt;/span&gt; is just like watching a movie, except that you get to control the actions of the main character. It has huge and entertaining cut scenes which tell the story. You just get so involved in the game and in the cut scenes that time just flies by without you noticing it.&lt;/p&gt;
&lt;p&gt;For me, the worst part of the cut scenes is that it&amp;#8217;s always during that time when people interrupt me &amp;#8211; either the phone will ring, or someone will want to talk to me &amp;#8211; and I wouldn&amp;#8217;t be able to pause it. Thankfully, MGS4 has introduced Pause during the &amp;#8220;mini movies&amp;#8221; which is really helpful. Before that, I had to &lt;em&gt;not&lt;/em&gt; save the game and then replay the last bit just to watch the cut scene without being interrupted.&lt;/p&gt;
&lt;p&gt;What about you? What&amp;#8217;s the game of your life and why? Drop me a line in the comments or a link to your own blog post.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/0suS_mr9X-k" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/09/26/game-of-my-life</feedburner:origLink></entry>
 
 <entry>
   <title>RFelix.com: Reloaded</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/qPu0uRR2Jxo/rfelix-reloaded" />
   <updated>2009-09-25T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/09/25/rfelix-reloaded</id>
   <content type="html">&lt;p&gt;Hi there! It&amp;#8217;s been quite a while since my last post (15th of March). Things got a bit hectic with all the university class projects and my internship work. That&amp;#8217;s life I guess.&lt;/p&gt;
&lt;p&gt;I admit that I&amp;#8217;ve neglected this blog quite a bit. I started it at the beginning of the year, but kept the main page of the site pointing to my about page rather than the blog. I just never really took it seriously.&lt;/p&gt;
&lt;p&gt;Well, things have now changed&amp;#8230;&lt;/p&gt;
&lt;h3&gt;Welcome to the new and improved RFelix.com!&lt;/h3&gt;
&lt;p&gt;The blog has been promoted and is now a first class citizen!&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve completely changed the layout. Rather than use a predefined template, I created my own simple theme. This is what is used to look like:&lt;/p&gt;
&lt;div style="text-align: center; margin-top: 10px; margin-bottom: 10px"&gt;&lt;img src="http://rfelix.com/img/posts/old-blog.png"
 alt="Picture of older version of blog"/&gt;&lt;/div&gt;
&lt;p&gt;I just never really liked it, it just wasn&amp;#8217;t &lt;em&gt;me&lt;/em&gt;. That&amp;#8217;s why I needed to create my own thing, make this whole space more personal.&lt;/p&gt;
&lt;p&gt;Now that I think about it, it was horrible. Yuck.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve also stopped using Wordpress and started &lt;a href="http://tom.preston-werner.com/2008/11/17/blogging-like-a-hacker.html"&gt;blogging like a hacker&lt;/a&gt; using Git and my own &lt;a href="http://github.com/rfelix/jekyll"&gt;custom version of Jekyll.&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Posting Schedule&lt;/h3&gt;
&lt;p&gt;I don&amp;#8217;t have as many subjects this semester as I had the previous years, but I also have to work on my master&amp;#8217;s dissertation, so that will consume a lot of time.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m not going to commit myself to a schedule, but my goal is to at least post one decent entry per week. I&amp;#8217;ll probably write about:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;My classes&lt;/li&gt;
	&lt;li&gt;My dissertation&lt;/li&gt;
	&lt;li&gt;Other projects I&amp;#8217;m working on&lt;/li&gt;
	&lt;li&gt;Or any new things I&amp;#8217;m learning about&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Arrivederci&lt;/h3&gt;
&lt;p&gt;For now, that&amp;#8217;s it. I hope to see you around here more often.&lt;/p&gt;
&lt;p&gt;And please, if you have any thoughts about the new theme or blog, any bugs, feel free to write a comment. Especially seeing as I&amp;#8217;ve really only tried viewing this site in Safari 4 and Firefox 3.5, any help on that front is greatly appreciated.&lt;/p&gt;
&lt;p&gt;Until the next post&amp;#8230;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/qPu0uRR2Jxo" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/09/25/rfelix-reloaded</feedburner:origLink></entry>
 
 <entry>
   <title>Memoization with Reflection in Ruby</title>
   <link href="http://feedproxy.google.com/~r/rfelix/~3/qyScD63lolU/memoization-with-reflection-in-ruby" />
   <updated>2009-03-15T00:00:00+00:00</updated>
   <id>http://rfelix.com/2009/03/15/memoization-with-reflection-in-ruby</id>
   <content type="html">&lt;p&gt;Since my classes started, in Programação Avançada (Advanced Programming) we have been talking about Reflection, using Lisp and Java for the examples. Now, Ruby is well know for it&amp;#8217;s Metaprogramming magic, so, being the geek I am, I was anxious to apply some of the things we discussed in class with Ruby.&lt;/p&gt;
&lt;p&gt;Because this post is so long please feel free to jump around and view only the parts that interest you the most. Here&amp;#8217;s a mini table of contents to help you out:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="#reflection"&gt;Reflection&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#self-modification"&gt;Self-Modification&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#lisp"&gt;Self-Modification and Memoization with Lisp&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#java"&gt;Self-Modification and Memoization with Java&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#ruby"&gt;Self-Modification and Memoization with Ruby&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="#simple-benchmark"&gt;Simple Ruby Code Benchmark&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;&lt;span id="reflection"&gt;Reflection&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Reflection, as per Wikipedia, is a particular kind of Metaprogramming. It is the process of reasoning about yourself and acting upon oneself. So basically it gives you the power to observe your own computer program during it&amp;#8217;s execution and, in some cases, allow you to modify it.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Reflection&lt;/i&gt; can be divided into two categories:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;i&gt;Introspection&lt;/i&gt; &amp;#8211; the ability to examine the structures of the program in execution from within itself;&lt;/li&gt;
	&lt;li&gt;&lt;i&gt;Intercession&lt;/i&gt; &amp;#8211; the ability to actually modify the behavior of the program in run-time.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;i&gt;Intercession&lt;/i&gt; can still be divided into another two sub-categories:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;i&gt;Self-Modification&lt;/i&gt; &amp;#8211; the ability to modify one&amp;#8217;s own structure;&lt;/li&gt;
	&lt;li&gt;&lt;i&gt;Intercession&lt;/i&gt; &amp;#8211; the ability to to modify the semantics of the language within the language itself.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;&lt;span id="self-modification"&gt;Self-Modification&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;The teacher in class used the recursive Fibonacci function &amp;#8211; &lt;em&gt;fib(n)&lt;/em&gt; &amp;#8211; as an example. Because of it&amp;#8217;s recursive nature, it&amp;#8217;s extremely inefficient to calculate fibonacci for big values of &lt;em&gt;n&lt;/em&gt;. To speed up it&amp;#8217;s execution, the teacher defined a &lt;em&gt;memoization&lt;/em&gt; function and applied it to &lt;em&gt;fib(n)&lt;/em&gt;. So it turns the original fibonacci function from an exponential beast into a linear calculation. It&amp;#8217;s pretty awesome to see how much time is saved by keeping the intermediate values and how that influences the execution time.&lt;/p&gt;
&lt;p&gt;So now let me show you how it&amp;#8217;s done in Lisp first, then in Java, and finally in Ruby.&lt;/p&gt;
&lt;p&gt;I won&amp;#8217;t spend too much time explaining the Lisp and Java code samples, they&amp;#8217;re here more for illustrative purposes than anything else. But if you&amp;#8217;re really interested in these samples and would like a detailed explanation, please drop me a comment as I&amp;#8217;d be glad to explain them to you.&lt;/p&gt;
&lt;p&gt;Please note that the following 2 code examples I&amp;#8217;m going to show you weren&amp;#8217;t programed by me; they were taken from my classes powerpoint slides which were created by my teacher, Ant&amp;oacute;nio Leit&amp;atilde;o. Only the Ruby code is 100% mine =)&lt;/p&gt;
&lt;h3&gt;&lt;span id="lisp"&gt;Lisp&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Let&amp;#8217;s take a look at the Fibonacci function in Lisp:&lt;/p&gt;
&lt;pre class="brush: lisp"&gt;
(lambda (n) 
	(if (&amp;lt; n 2) 
		n 
		(+	(fib (- n 1))
			(fib (- n 2)))))
&lt;/pre&gt;
&lt;p&gt;The &lt;em&gt;memoize&lt;/em&gt; function looks like this:&lt;/p&gt;
&lt;pre class="brush: lisp"&gt;
(defun memoize (lambda-form)
	(setcar (cddr lambda-form)
			`(let ((result ,(caddr lambda-form)))
				(setcar (cddr ',lambda-form)
					`(if (eql	,',(caadr lambda-form)
								',,(caadr lambda-form))
						',result
						,(caddr ',lambda-form)))
				result)))
&lt;/pre&gt;
&lt;p&gt;Pretty scary right? I&amp;#8217;m not going to explain it, it&amp;#8217;s just here for me to scare you and show you how cool Ruby is.&lt;/p&gt;
&lt;p&gt;But what this function does is it changes the &lt;em&gt;fib(n)&lt;/em&gt; function so that every time it has to calculate the fibonacci of some &lt;em&gt;n&lt;/em&gt;, it modifies itself. It does this by adding a new &lt;em&gt;If&lt;/em&gt; condition to the beginning of the function body, checking if &lt;em&gt;n&lt;/em&gt; is equal to some &lt;em&gt;n&lt;/em&gt; that was previously calculated. If so, it returns the value straight away. If not, the function calculates the value recursively and modifies itself once again.&lt;/p&gt;
&lt;h3&gt;&lt;span id="java"&gt;Java&lt;/n&gt;&lt;/h3&gt;
&lt;p&gt;Java doesn&amp;#8217;t allow destructive modification of programs at run-time like Lisp does. But what it does allow you to do is modify the program before the class is loaded by the Java Virtual Machine &amp;#8211; aka Load-Time. This is done by using an external library, in this case, &lt;a href="http://www.csg.is.titech.ac.jp/~chiba/javassist/"&gt;Javassist&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Fibonacci in Java looks something like:&lt;/p&gt;
&lt;pre class="brush: java"&gt;
public class Fib { 
	public static Long fib (Long n) { 
		if (n &amp;lt; 2) { 
			return n; 
		} else { 
			return fib(n - 1) + fib(n - 2); 
		} 
	} 
} 
&lt;/pre&gt;
&lt;p&gt;A bit verbose, I know. Now for the &lt;em&gt;memoization&lt;/em&gt; function:&lt;/p&gt;
&lt;pre class="brush: java"&gt;
import javassist.*; 
import java.io.*; 

public class Memoize { 
	public static void main(String[] args) 
		throws NotFoundException, CannotCompileException, IOException { 
		if (args.length != 2) { 
			System.err.println("Usage: java Memoize &amp;lt;class&amp;gt; &amp;lt;method&amp;gt;"); 
			System.exit(1); 
		} else { 
			ClassPool pool = ClassPool.getDefault(); 
			CtClass ctClass = pool.get(args[0]); 
			memoize(ctClass, ctClass.getDeclaredMethod(args[1])); 
			ctClass.writeFile();
		} 
	} 
	static void memoize(CtClass ctClass, CtMethod ctMethod) 
		throws NotFoundException, CannotCompileException { 
		CtField ctField = 
			CtField.make("static java.util.Hashtable cachedResults = " + 
						 " new java.util.Hashtable();", 
						 ctClass);
		ctClass.addField(ctField); 
		String name = ctMethod.getName(); 
		ctMethod.setName(name + "$original"); 
		ctMethod = CtNewMethod.copy(ctMethod, name, ctClass, null); 
		ctMethod.setBody("{" + 
					     " Object result = cachedResults.get($1);" + 
					     " if (result == null) {" + 
					     " result = " + name + "$original($$);" + 
					     " cachedResults.put($1, result);" + 
					     " }" + 
					     " return ($r)result;" + 
					     "}"); 
		ctClass.addMethod(ctMethod);
	} 
}
&lt;/pre&gt;
&lt;p&gt;Instead of adding an &lt;em&gt;If&lt;/em&gt; statement to be beginning of the function every time it calculates &lt;em&gt;n&lt;/em&gt; recursively, we&amp;#8217;ll use a Hash Table to keep the intermediate values by using &lt;em&gt;n&lt;/em&gt; as a key and the fibonacci value as the key&amp;#8217;s value.&lt;/p&gt;
&lt;p&gt;So this code renames the &lt;em&gt;fib(n)&lt;/em&gt; function to &lt;em&gt;original$fib&lt;/em&gt; which isn&amp;#8217;t normally allowed, but because Javassist works at such a low-level, it&amp;#8217;s allowed to do that. Plus, this way, it avoids any namespace collisions. After the rename, it redefines the original &lt;em&gt;fib(n)&lt;/em&gt; method so that it:&lt;/p&gt;
1. Checks if &lt;em&gt;n&lt;/em&gt; is in the hash table. If so, return the corresponding value.
2. If not, call the original$fib function, store the value in the hash table, and return it.
&lt;p&gt;Pretty simple right? That&amp;#8217;s exactly what I did in Ruby.&lt;/p&gt;
&lt;h3&gt;&lt;span id="ruby"&gt;Ruby&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;I saved the best for last. To be consistent, I&amp;#8217;ll show you the Fibonacci method I defined in Ruby:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
class Fib
  def fib(n)
    return n if n &amp;lt; 2
    return fib(n-1) + fib(n-2)  
  end
end
&lt;/pre&gt;
&lt;p&gt;And here&amp;#8217;s my &lt;em&gt;memoization&lt;/em&gt; function:&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
def memoize(className, methodName)
  className.class_eval do 
    alias_method("original_memoize_#{methodName}", methodName)
    
    define_method(methodName) do |*args|
      hash = instance_variable_get("@memoize_#{methodName}_hash")
      
      if hash.nil?
        hash = Hash.new
        instance_variable_set("@memoize_#{methodName}_hash", hash) 
      end
      
      return hash[args] if hash.has_key?(args)
      res = self.send("original_memoize_#{methodName}", *args)
      hash[args] = res
      return res
    end
  end
end
&lt;/pre&gt;
&lt;p&gt;The function takes as arguments: the Class to be modified and the corresponding method name as a symbol. With that it modifies the method, giving it &lt;em&gt;memoization&lt;/em&gt; super powers.&lt;/p&gt;
&lt;p&gt;So, given &lt;em&gt;fib(Fib, :fib)&lt;/em&gt;, the function:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Opens up the &lt;em&gt;Fib&lt;/em&gt; class and changes the &lt;em&gt;fib&lt;/em&gt; method&amp;#8217;s name to &lt;em&gt;original_memoize_fib&lt;/em&gt;&lt;/li&gt;
	&lt;li&gt;Adds a new method to the &lt;em&gt;Fib&lt;/em&gt; class, called &lt;em&gt;fib&lt;/em&gt;, that:
	&lt;ul&gt;
		&lt;li&gt;Tries to get the hash table from an instance variable called &lt;em&gt;@memoize_fib_hash&lt;/em&gt;&lt;/li&gt;
		&lt;li&gt;If that instance variable doesn&amp;#8217;t exist, it defines and initializes it with an empty &lt;em&gt;Hash&lt;/em&gt;&lt;/li&gt;
		&lt;li&gt;Checks if the key &lt;em&gt;n&lt;/em&gt; exists in the hash table, if it does, then return it straight away.&lt;/li&gt;
		&lt;li&gt;If not
		&lt;ul&gt;
			&lt;li&gt;Call the original &lt;em&gt;fib&lt;/em&gt; function, &lt;em&gt;original_memoize_fib&lt;/em&gt; and calculate the value recursively&lt;/li&gt;
			&lt;li&gt;Add it to the hash table&lt;/li&gt;
			&lt;li&gt;Finally, return the value.&lt;/li&gt;
		&lt;/ul&gt;&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;&lt;span id="simple-benchmark"&gt;Simple Benchmark&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Here&amp;#8217;s an sample execution with &lt;em&gt;n&lt;/em&gt; = 30.&lt;/p&gt;
&lt;pre class="brush: ruby"&gt;
Running Fib with 30
Without Memoization:
  1.530000   0.000000   1.530000 (  1.565292)
With Memoization:
  0.000000   0.000000   0.000000 (  0.000440)	
&lt;/pre&gt;
&lt;p&gt;And that&amp;#8217;s pretty much it for the Ruby version. Out of all the examples, I prefer this one, and not because it was me that did it. I find the code is a bit more elegant than the Lisp version, and a &lt;i&gt;lot&lt;/i&gt; more elegant and less verbose than the Java one.&lt;/p&gt;
&lt;p&gt;If you want to play with the code, you can get the full version &lt;a href="http://gist.github.com/79500"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/rfelix/~4/qyScD63lolU" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://rfelix.com/2009/03/15/memoization-with-reflection-in-ruby</feedburner:origLink></entry>
 
 
</feed>
