<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Renaud Bourassa &#187; Ruby</title>
	<atom:link href="http://renaudbourassa.com/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://renaudbourassa.com/blog</link>
	<description>Welcome to my World. Here, I am the Architect.</description>
	<lastBuildDate>Thu, 19 Jan 2012 05:45:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Basic Data Structure Addition to Batfish</title>
		<link>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/</link>
		<comments>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 02:18:36 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Batfish]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Linked List]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Stack]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=470</guid>
		<description><![CDATA[Batfish is collection of data structures and algorithms written in Ruby that I started about a month ago. While trying to implement graphs in the library, I quickly realised that a number of basic data structure were missing to implement certain graph algorithms. Stacks and queues were needed to respectively implement the depth-first search and [...]]]></description>
			<content:encoded><![CDATA[<p>Batfish is collection of data structures and algorithms written in Ruby that I started about a month ago. While trying to implement graphs in the library, I quickly realised that a number of basic data structure were missing to implement certain graph algorithms. Stacks and queues were needed to respectively implement the depth-first search and breadth-first search algorithm and a linked list is a good way to represent the adjency lists of vertices. </p>
<p>I thus decided to implement these simple, but oh so useful data structures. Sure, you could reply that ruby arrays already implement all the functionalities provided by theses data structures. True, but when you are dealing with linked lists of millions of elements, having to relocate the whole array in memory to add an element can prove to be a lenghty task. Also, finding a memory chunk big enough to hold the whole array may prove challenging. Ruby arrays grow pretty fast (~1.5x) as can be seen from the following code snippet from array.c (ruby 1.9.1p243) and can rapidly become hard to store in memory.</p>
<pre class="brush: ruby; title: ; notranslate">
if (idx &gt;= ARY_CAPA(ary)) {
    long new_capa = ARY_CAPA(ary) / 2;

    if (new_capa &lt; ARY_DEFAULT_SIZE) {
        new_capa = ARY_DEFAULT_SIZE;
    }
    if (new_capa &gt;= ARY_MAX_SIZE - idx) {
        new_capa = (ARY_MAX_SIZE - idx) / 2;
    }
    new_capa += idx;
    ary_resize_capa(ary, new_capa);
}
</pre>
<p>And finally, theses data structures implement functionalities that are badly supported by arrays such as deleting or adding an element in the middle of a list.</p>
<p>The stack and queue implementation are separated from the linked list implementation to keep them as simple as possible. The linked list implementation is more extensive and is also used to implement the sorted linked list data structure. The next data structure to be added to Batfish will probably be graphs and it should include a number of basic graph algorithms.</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/09/24/basic-data-structure-addition-to-batfish/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batfish, Just a Bunch of Functions</title>
		<link>http://renaudbourassa.com/blog/2009/08/23/batfish-just-a-bunch-of-functions/</link>
		<comments>http://renaudbourassa.com/blog/2009/08/23/batfish-just-a-bunch-of-functions/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 04:01:42 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Batfish]]></category>
		<category><![CDATA[BK-Tree]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Trie]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=431</guid>
		<description><![CDATA[I have been programming in Ruby for a bit less then a year but already, I accumulated a number of data structures and algorithms. Since they could probably be of some use to someone else and I don&#8217;t want to lose everything because of a failure of some sort, I decided to publish them on [...]]]></description>
			<content:encoded><![CDATA[<p>I have been programming in Ruby for a bit less then a year but already, I accumulated a number of data structures and algorithms. Since they could probably be of some use to someone else and I don&#8217;t want to lose everything because of a failure of some sort, I decided to publish them on my <a href="http://github.com/renaudb">github</a>. The name of the gem: <a href="http://github.com/renaudb/batfish/">batfish</a> (the name comes from a random haiku generator). So far, only my implementations of BK-tree and trie are included, but more should follow soon as I get more time to package them. For more informations, you can browse the batfish <a href="http://renaudbourassa.com/projects/batfish">documentation</a>.</p>
<p><strong>Trie</strong></p>
<p>A trie is a data structure that is used to store an associative array where the array&#8217;s keys are strings. It has the same structure as any other tree, except that keys are not stored in nodes. Instead, each edge has a character associated with it and you browse the trie by going down the edges, one character at a time, until you reach the end of the key. <a href="http://renaudbourassa.com/blog/wp-content/uploads/2009/08/Trie.png"><img style = "border:none" src="http://renaudbourassa.com/blog/wp-content/uploads/2009/08/Trie-300x222.png" alt="Trie" title="Trie" width="300" height="222" class="alignleft size-medium wp-image-442" /></a>The node you reach this way contains the value associated with the key.</p>
<p>Tries have several advantages over binary search trees. First, the complexity of trie lookup is O(L) where L is the length of the key while it is of O(n) where n is the number of elements in the tree for a BST. It also takes less space since different keys overlap. It also have advantages over hash tables. First, the keys, in a trie, are ordered, which makes it a useful data structure to use to store a dictionary. It can also lead to faster lookup depending on the hash function and considering that collisions are possible with string hashes.</p>
<p>More informations on tries can be found <a href="http://en.wikipedia.org/wiki/Trie">here</a>.</p>
<p><strong>BK-Tree</strong></p>
<p><a href="http://renaudbourassa.com/blog/wp-content/uploads/2009/08/BKTree1.png"><img style = "border:none" src="http://renaudbourassa.com/blog/wp-content/uploads/2009/08/BKTree1-300x286.png" alt="Levenshtein BKTree" title="Levenshtein BKTree" width="300" height="286" class="alignright size-medium wp-image-466" /></a>A BK-tree is a useful data structure for nearest neighbor lookup in discrete metric spaces. A metric space is any space that obeys the following rules, where d(a,b) is the distance between a and b.</p>
<ul>
<li><img src='http://s.wordpress.com/latex.php?latex=d%28x%2Cy%29%20%3D%200%20%5CLeftrightarrow%20x%20%3D%20y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(x,y) = 0 \Leftrightarrow x = y' title='d(x,y) = 0 \Leftrightarrow x = y' class='latex' /></li>
<li><img src='http://s.wordpress.com/latex.php?latex=d%28x%2Cy%29%20%3D%20d%28y%2Cx%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(x,y) = d(y,x)' title='d(x,y) = d(y,x)' class='latex' /></li>
<li><img src='http://s.wordpress.com/latex.php?latex=d%28x%2Cy%29%20%5Cleq%20d%28x%2Ca%29%20%2B%20d%28a%2Cy%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d(x,y) \leq d(x,a) + d(a,y)' title='d(x,y) \leq d(x,a) + d(a,y)' class='latex' /></li>
</ul>
<p>The later is also known as the triangle inequality. It basically states that there is no shorter way to go from a point to another than the direct way. Examples of discrete metric spaces, that is, where the distances are integers, are the real numbers or the levenshtein distance between strings.</p>
<p>The BK-Tree is constructed by measuring the distance between the value to insert and every node, going down the edges corresponding to the distance at each node. Once an unregistered distance at a node is calculated for that node, the value is attached to it. The lookup process works by going down each edges in the distance to the node ± the lookup treshold range until a node with a distance equal to the treshold value or less is found. It is thus possible to find all the nodes within a certain distance of a value without going through each nodes. However, the larger the threshold, the more nodes you have to visit.</p>
<p>For more information on BK-trees, you can read the following <a href="http://portal.acm.org/citation.cfm?id=362003.362025">article</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/08/23/batfish-just-a-bunch-of-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release of RSDownloader 0.2.0</title>
		<link>http://renaudbourassa.com/blog/2009/04/22/release-of-rsdownloader-020/</link>
		<comments>http://renaudbourassa.com/blog/2009/04/22/release-of-rsdownloader-020/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 03:52:32 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[FilesTube]]></category>
		<category><![CDATA[RapidShare]]></category>
		<category><![CDATA[RSDownloader]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=275</guid>
		<description><![CDATA[It is here! After some development during the exam session and a final revision now that I am done with university, I am proud to announce the release of RSDownloader 0.2.0. A lot of things changed since the first draft that was version 0.1.0. First, I changed the download code to be more modular. I [...]]]></description>
			<content:encoded><![CDATA[<p>It is here! After some development during the exam session and a final revision now that I am done with university, I am proud to announce the release of RSDownloader 0.2.0. A lot of things changed since the first draft that was version 0.1.0. First, I changed the download code to be more modular. I created a Download superclass that can be used as a model to create specific download classes for different filehosting websites easily. As of now I implemented <a href="http://rapidshare.com/">RapidShare</a> and <a href="http://www.filestube.com/">FilesTube</a> and I may add others in the future. I also implemented a search function that relies on the FilesTube API to search files by keyword. Last but not least, I changed the structure of the package to look and act more like a real package. I added setup.rb support to make the installation easier and I released the source code under <a href="http://www.gnu.org/licenses/gpl-3.0.html">GPLv3</a>.</p>
<p>If you are interested in implementing any other functionality or website, don&#8217;t hesitate to fork the project on <a href="http://github.com/renaudb/rsdownloader/">github</a>. Here is the code of the Download superclass.</p>
<pre class="brush: ruby; title: ; notranslate"># The Download superclass
class Download
 attr_accessor :url, :name

 # Initializes a download
 def initialize(url, opts)
 @url = url
 @opts = opts
 @file = nil
 end

 # Tests the url
 def test
 begin
 Net::HTTP.get_response(URI.parse(url)).value
 rescue
 return false
 end
 return true
 end

 # Executes the download
 def execute
 self.set_file
 self.download
 end

 # Sets the file for the download
 def set_file
 @file = @url
 end

 # Downloads the file
 def download
 cmd = &amp;quot;wget -c --user-agent=&amp;quot;#{@opts[:header]['User-Agent']}&amp;quot;&amp;quot;
 cmd += &amp;quot; -q&amp;quot; if !$verbose
 cmd += &amp;quot; --directory-prefix=&amp;quot;#{@opts[:dir]}&amp;quot;&amp;quot; if @opts[:dir]

 IO.popen(cmd + &amp;quot; #{@file}&amp;quot;){|f|}
 end
end</pre>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/04/22/release-of-rsdownloader-020/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Euler 26 to 30</title>
		<link>http://renaudbourassa.com/blog/2009/02/10/euler-26-to-30/</link>
		<comments>http://renaudbourassa.com/blog/2009/02/10/euler-26-to-30/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 04:37:20 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=242</guid>
		<description><![CDATA[I just finished uploading my solutions to the Project Euler problems 26 to 30. They are all in Ruby since it is the language I am currently learning during my free time. I decided this time not to write the answers at the end. This way you have to execute the code yourself if you [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished uploading my <a href="http://renaudbourassa.com/blog/project-euler-solutions/">solutions</a> to the <a href="http://projecteuler.net">Project Euler</a> problems 26 to 30. They are all in Ruby since it is the language I am currently learning during my free time. I decided this time not to write the answers at the end. This way you have to execute the code yourself if you just want the answer. I also included comments to explain the parts that are harder to understand. If you have any question regarding any of the solutions, just post it as a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/02/10/euler-26-to-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back in Black (and Yellow)</title>
		<link>http://renaudbourassa.com/blog/2009/01/10/back-in-black/</link>
		<comments>http://renaudbourassa.com/blog/2009/01/10/back-in-black/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 23:21:56 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Christmas]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://renaudbourassa.com/blog/?p=69</guid>
		<description><![CDATA[After what is my shortest Christmas Holiday for the last three years, I am back in Waterloo. During these two weeks, I took a break from everything I was working on and spent most of my time with my friends and family. The little spare time I got went into Project Euler problems. I managed [...]]]></description>
			<content:encoded><![CDATA[<p>After what is my shortest Christmas Holiday for the last three years, I am back in <a href="http://www.uwaterloo.ca">Waterloo</a>. During these two weeks, I took a break from everything I was working on and spent most of my time with my friends and family. The little spare time I got went into <a href="http://projecteuler.net">Project Euler</a> problems. I managed to solve the first 25 using C and will probably post my code in the days to come.</p>
<p>I also received my marks for my first term and I have to say that I am pretty happy with what I got. This term is more focused on computer science related subjects with courses such as <em>Functional Programming and Data Abstraction</em> (using Scheme and C++) and <em>Dig</em><em>ital Circuits and Systems</em>. I also have two economy classes which is something I enjoy a lot. It is also the beginning of the hiring process for this summer co-op term.</p>
<p>And, as of right now, I am reading books on ruby and ruby on rails to improve my skills. I did a lot of small scripts and projects using this language/framework, but the <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a> concept is still new to me. I am now looking at creating a complete, usable web application so I need to expand my knowledge a bit more. Stay tuned for more.</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2009/01/10/back-in-black/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Little Update</title>
		<link>http://renaudbourassa.com/blog/2008/11/18/little-update/</link>
		<comments>http://renaudbourassa.com/blog/2008/11/18/little-update/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 01:52:15 +0000</pubDate>
		<dc:creator>Rhino</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[Polar Mobile]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Robot]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.rhinosphere.com/?p=41</guid>
		<description><![CDATA[I haven&#8217;t posted for a while so here is a little update on what is going on with me. I&#8217;m still troubleshooting my portfolio, searching for bugs and correcting them. There was some problem with the CSS on certain browsers, especially IE. University is taking most of my time. The assignments get longer and harder [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t posted for a while so here is a little update on what is going on with me. I&#8217;m still troubleshooting my <a href="http://portfolio.rhinosphere.com/">portfolio</a>, searching for bugs and correcting them. There was some problem with the CSS on certain browsers, especially IE. University is taking most of my time. The assignments get longer and harder so I have less free time to do extra work. The Lego Robot Project of my Software Engineering 101 is due for next week so I&#8217;m spending more time in the lab.</p>
<p>Also, last thursday was the Engineering Student Awards Dinner. As an entrance scolarship recipient I was invited with some 400 other engineering students. At my table was sitting Gaurav Jain, who graduated from software engineering last year and is now the VP of <a href="http://www.polarmobile.com/">Polar Mobile</a>, a young and quite successful company developing a smartphone publishing tool. I had the occasion to talk a bit with him about how he started the company and how he is managing it. He is a pretty brilliant guy and his company looks really promising.</p>
<p>I&#8217;m not working on a particular project. I discovered <a href="http://projecteuler.net/">Project Euler</a> and spent some time doing the first 10 challenges in C. I&#8217;m currently learning Ruby and the <a href="http://www.rubyonrails.com/">Ruby on Rails</a> framework via tutorials. I have an idea in mind for a future project that would fit perfectly with Rails but I&#8217;m not proficient enough right now to do anything effective. But I&#8217;m a quick learner so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://renaudbourassa.com/blog/2008/11/18/little-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

