<?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>AndrewsBlog &#187; Ruby</title>
	<atom:link href="http://andrewsblog.org/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewsblog.org</link>
	<description>Stories of an ex-erasmus student</description>
	<lastBuildDate>Fri, 26 Mar 2010 15:02:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>F1Time Tool &#8211; Sinatra App</title>
		<link>http://andrewsblog.org/2008/12/21/f1time-tool-sinatra-app/</link>
		<comments>http://andrewsblog.org/2008/12/21/f1time-tool-sinatra-app/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 15:20:48 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[f1time]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://andrewsblog.org/2008/12/21/f1time-tool-sinatra-app/</guid>
		<description><![CDATA[I&#8217;ve been playing an online F1 manager game for a couple of weeks. F1Time is a manager simulation game with great depth and the right level of complexity. I like it.
I wrote a small tool to extract laptime data from the race reports so it can be easily analyzed in MS Excel. I wrote it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing an online F1 manager game for a couple of weeks. <a href="http://www.f1time.com">F1Time</a> is a manager simulation game with great depth and the right level of complexity. I like it.</p>
<p>I wrote <a href="http://f1tools.andrewsblog.org">a small tool</a> to extract laptime data from the race reports so it can be easily analyzed in MS Excel. I wrote it as a Sinatra webapp. <a href="http://sinatra.rubyforge.org/">Sinatra</a> is a Ruby DSL for writing small webapps with a minimum amount of code. This tool was written in <a href="http://github.com/andruby/f1time-tools/tree/master/sinatra_app.rb">35 lines of code</a>.</p>
<p>It&#8217;s open source, so you can view (or fork) the sourcecode on <a href="http://github.com/andruby/f1time-tools" title="andruby's f1time-tools on GitHub">github</a>.</p>
<p><strong>F1Time managers:</strong> You can simply copy &amp; paste the html code of your race report <a href="http://f1tools.andrewsblog.org">HERE</a>, and it will generate a table that you can copy/paste into Excel. (to get the html code from the race report: right click and click &#8220;View page source&#8221;)</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewsblog.org/2008/12/21/f1time-tool-sinatra-app/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ruby 1.8 vs 1.9 group_by performance</title>
		<link>http://andrewsblog.org/2008/08/16/ruby-18-vs-19-group_by-performance/</link>
		<comments>http://andrewsblog.org/2008/08/16/ruby-18-vs-19-group_by-performance/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 15:00:51 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://andrewsblog.org/2008/08/16/ruby-18-vs-19-sort_by-performance/</guid>
		<description><![CDATA[I am working on a ruby project which has cpu intensive tasks so I wanted to see what the impact would be of using the ruby 1.9 development version. It is supposed to provide a major performance increase.
The task used in this project crunches a large amount of data using mathematical functions, array sorting/grouping and [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a ruby project which has cpu intensive tasks so I wanted to see what the impact would be of using the ruby 1.9 development version. It is supposed to provide a major performance increase.</p>
<p>The task used in this project crunches a large amount of data using mathematical functions, array sorting/grouping and database writes.</p>
<p>Ruby versions used for this test:</p>
<pre>
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.1]
ruby 1.9.0 (2008-07-25 revision 18217) [i686-darwin9]
</pre>
<p>A typical run would take 240sec using ruby 1.8 and 205s with ruby 1.9 without any adaptations: A ~15% speed increase!</p>
<p>I dug a little deeper and found that the array.group_by method was performing a lot faster in ruby 1.9 so i wrote this benchmark to test the increase.</p>
<p><span id="more-41"></span></p>
<pre><span class="ident">require</span> <span class="punct">'</span><span class="string">rubygems</span><span class="punct">'</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">activesupport</span><span class="punct">'</span>
<span class="ident">require</span> <span class="punct">'</span><span class="string">benchmark</span><span class="punct">'</span>
<span class="ident">include</span> <span class="constant">Benchmark</span>

<span class="keyword">class </span><span class="class">T</span>
  <span class="ident">attr_accessor</span> <span class="symbol">:date</span><span class="punct">,</span> <span class="symbol">:count</span>
  <span class="keyword">def </span><span class="method">initialize</span><span class="punct">(</span><span class="ident">_date</span><span class="punct">,</span><span class="ident">_count</span><span class="punct">)</span>
    <span class="attribute">@count</span> <span class="punct">=</span> <span class="ident">_count</span>
    <span class="attribute">@date</span> <span class="punct">=</span> <span class="ident">_date</span>
  <span class="keyword">end</span>
<span class="keyword">end</span>

<span class="keyword">def </span><span class="method">fill_array</span><span class="punct">(</span><span class="ident">n</span><span class="punct">)</span>
  <span class="ident">a</span> <span class="punct">=</span> <span class="punct">[]</span>
  <span class="ident">random_dates</span> <span class="punct">=</span> <span class="ident">n</span> <span class="punct">/</span> <span class="number">5</span>
  <span class="ident">n</span><span class="punct">.</span><span class="ident">times</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">x</span><span class="punct">|</span> <span class="ident">a</span> <span class="punct">&lt;&lt;</span> <span class="constant">T</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">rand</span><span class="punct">(</span><span class="ident">random_dates</span><span class="punct">).</span><span class="ident">days</span><span class="punct">.</span><span class="ident">ago</span><span class="punct">,</span><span class="ident">x</span><span class="punct">)</span> <span class="punct">}</span>
  <span class="keyword">return</span> <span class="ident">a</span>
<span class="keyword">end</span>

<span class="punct">(</span><span class="number">2</span><span class="punct">..</span><span class="number">5</span><span class="punct">).</span><span class="ident">each</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">p</span><span class="punct">|</span>
  <span class="ident">n</span> <span class="punct">=</span> <span class="number">10</span><span class="punct">**</span><span class="ident">p</span>
  <span class="ident">puts</span> <span class="punct">"</span><span class="string">=== 10^<span class="expr">#{p}</span> ===</span><span class="punct">"</span>
  <span class="ident">array</span> <span class="punct">=</span> <span class="punct">[]</span>
  <span class="ident">benchmark</span> <span class="keyword">do</span> <span class="punct">|</span><span class="ident">x</span><span class="punct">|</span>
    <span class="ident">x</span><span class="punct">.</span><span class="ident">report</span><span class="punct">("</span><span class="string">filling array     : </span><span class="punct">")</span> <span class="punct">{</span> <span class="ident">array</span> <span class="punct">=</span> <span class="ident">fill_array</span><span class="punct">(</span><span class="ident">n</span><span class="punct">)</span> <span class="punct">}</span>
    <span class="ident">x</span><span class="punct">.</span><span class="ident">report</span><span class="punct">("</span><span class="string">group_by (Time)   : </span><span class="punct">")</span> <span class="punct">{</span> <span class="ident">array</span><span class="punct">.</span><span class="ident">group_by</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">r</span><span class="punct">|</span> <span class="ident">r</span><span class="punct">.</span><span class="ident">date</span> <span class="punct">}</span> <span class="punct">}</span>
    <span class="ident">x</span><span class="punct">.</span><span class="ident">report</span><span class="punct">("</span><span class="string">group_by (Date)   : </span><span class="punct">")</span> <span class="punct">{</span> <span class="ident">array</span><span class="punct">.</span><span class="ident">group_by</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">r</span><span class="punct">|</span> <span class="ident">r</span><span class="punct">.</span><span class="ident">date</span><span class="punct">.</span><span class="ident">to_date</span> <span class="punct">}</span> <span class="punct">}</span>
    <span class="ident">x</span><span class="punct">.</span><span class="ident">report</span><span class="punct">("</span><span class="string">group_by (String) : </span><span class="punct">")</span> <span class="punct">{</span> <span class="ident">array</span><span class="punct">.</span><span class="ident">group_by</span> <span class="punct">{</span> <span class="punct">|</span><span class="ident">r</span><span class="punct">|</span> <span class="ident">r</span><span class="punct">.</span><span class="ident">date</span><span class="punct">.</span><span class="ident">to_date</span><span class="punct">.</span><span class="ident">to_s</span> <span class="punct">}</span> <span class="punct">}</span>
  <span class="keyword">end</span>
<span class="keyword">end</span></pre>
<p>On ruby 1.8 this only runs upto 10^4, 10^5 took way too long for Time and Date grouping.</p>
<pre>
=== 10^2 ===
filling array     :   0.030000   0.000000   0.030000 (  0.023987)
group_by (Time)   :   0.030000   0.000000   0.030000 (  0.032630)
group_by (Date)   :   0.010000   0.000000   0.010000 (  0.012132)
group_by (String) :   0.020000   0.000000   0.020000 (  0.019727)
=== 10^3 ===
filling array     :   0.300000   0.000000   0.300000 (  0.305314)
group_by (Time)   :   4.270000   0.020000   4.290000 (  4.306768)
group_by (Date)   :   0.610000   0.000000   0.610000 (  0.622509)
group_by (String) :   0.260000   0.000000   0.260000 (  0.258966)
=== 10^4 ===
filling array     :   3.050000   0.030000   3.080000 (  3.094591)
group_by (Time)   : 425.980000   2.250000 428.230000 (433.534167)
group_by (Date)   :  53.930000   0.300000  54.230000 ( 54.870563)
group_by (String) :   5.440000   0.010000   5.450000 (  5.480042)
=== 10^5 ===
filling array     :  31.680000   0.240000  31.920000 ( 32.714948)
group_by (Time)   :  --- too long ---
group_by (Date)   :  --- too long ---
group_by (String) : 796.560000   5.540000 802.100000 (815.322759)
</pre>
<p>Another thing to note is that grouping by Time is a lot more expensive than grouping by Date. Grouping by String is even faster. This is the exact opposite of ruby 1.9 behavior:</p>
<pre>
=== 10^2 ===
filling array     :   0.030000   0.000000   0.030000 (  0.022190)
group_by (Time)   :   0.000000   0.000000   0.000000 (  0.000217)
group_by (Date)   :   0.000000   0.000000   0.000000 (  0.001032)
group_by (String) :   0.000000   0.000000   0.000000 (  0.004109)
=== 10^3 ===
filling array     :   0.110000   0.000000   0.110000 (  0.107807)
group_by (Time)   :   0.000000   0.000000   0.000000 (  0.001625)
group_by (Date)   :   0.010000   0.000000   0.010000 (  0.011684)
group_by (String) :   0.050000   0.000000   0.050000 (  0.061122)
=== 10^4 ===
filling array     :   0.940000   0.010000   0.950000 (  0.975104)
group_by (Time)   :   0.020000   0.000000   0.020000 (  0.018976)
group_by (Date)   :   0.140000   0.000000   0.140000 (  0.134740)
group_by (String) :   0.390000   0.010000   0.400000 (  0.400235)
=== 10^5 ===
filling array     :   9.290000   0.130000   9.420000 (  9.711327)
group_by (Time)   :   0.300000   0.000000   0.300000 (  0.312848)
group_by (Date)   :   1.360000   0.020000   1.380000 (  1.391566)
group_by (String) :   4.100000   0.040000   4.140000 (  4.194526)
</pre>
<p>With ruby 1.9, grouping by Time is faster than Date. Grouping by String is the slowest. Important to note is that the increase is almost linear.</p>
<p>If we look at the difference between 1.8 and 1.9 we see that filling an array with objects is 3 times faster. But the real surprise is the exponential speed increase when grouping large dataset!</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-8481207893602049";
google_ad_slot = "4791982862";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewsblog.org/2008/08/16/ruby-18-vs-19-group_by-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using net/pop in Ruby with ssl.</title>
		<link>http://andrewsblog.org/2008/05/15/using-netpop-in-ruby-with-ssl/</link>
		<comments>http://andrewsblog.org/2008/05/15/using-netpop-in-ruby-with-ssl/#comments</comments>
		<pubDate>Thu, 15 May 2008 19:55:47 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://andrewsblog.org/2008/05/15/using-netpop-in-ruby-with-ssl/</guid>
		<description><![CDATA[
	If you follow this blog post by Chris Roos for connecting to Gmail&#8217;s pop server with Ruby and encounter an error similar to this one: NoMethodError: undefined method `set_params&#8217; for #&#60;OpenSSL::SSL::SSLContext:0&#215;50fc58&#62;

Here&#8217;s the fix: You need an older version of Ruby 1.9&#8217;s net/pop library. I found that the latest one working was revision 13778. view it [...]]]></description>
			<content:encoded><![CDATA[<p>
	If you follow <a href="http://blog.seagul.co.uk/articles/2006/10/24/connecting-to-gmail-with-ruby-or-connecting-to-pop3-servers-over-ssl-with-ruby">this blog post</a> by Chris Roos for connecting to Gmail&#8217;s pop server with Ruby and encounter an error similar to this one: <em>NoMethodError: undefined method `set_params&#8217; for #&lt;OpenSSL::SSL::SSLContext:0&#215;50fc58&gt;</em>
</p>
<p>Here&#8217;s the fix: You need an older version of Ruby 1.9&#8217;s net/pop library. I found that the latest one working was revision 13778. <a href="http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v1_9_0_0/lib/net/pop.rb?revision=13778&#38;view=markup">view it here</a>.</p>
<p>Hope this saves some time for a few people.</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-8481207893602049";
google_ad_slot = "4791982862";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewsblog.org/2008/05/15/using-netpop-in-ruby-with-ssl/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Ruby 9th most popular programming language</title>
		<link>http://andrewsblog.org/2007/11/23/ruby-9th-most-popular-programming-language/</link>
		<comments>http://andrewsblog.org/2007/11/23/ruby-9th-most-popular-programming-language/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 01:18:16 +0000</pubDate>
		<dc:creator>andrew</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://andrewsblog.org/2007/11/23/ruby-9th-most-popular-programming-language/</guid>
		<description><![CDATA[The Ruby programming language creeps up as the 9th most popular programming language on the TIOBE Programming Community Index. Slightly overtaking Javascript. Being a Ruby programmer, this is nice news. 
To my surprise, the Lua language (portuguese word for moon) jumped up from the 48th place to the 16th. The language was developed in Brazil [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ruby-lang.org" title="Ruby Programming Language">The Ruby programming language</a> creeps up as the 9th most popular programming language on the <a href="http://www.tiobe.com/index.htm?tiobe_index" title="TIOBE Software - The Coding Standards Company">TIOBE Programming Community Index</a>. Slightly overtaking Javascript. Being a Ruby programmer, this is nice news. </p>
<p>To my surprise, <a href="http://www.lua.org/" title="The Programming Language Lua">the Lua language</a> (portuguese word for moon) jumped up from the 48th place to the 16th. The language was developed in Brazil and is being used more and more in games. I know that the talented developers from <a href="http://www.unknownworlds.com/" title="Unknown Worlds Entertainment">Unknown Worlds</a> are using it extensively in their upcoming <a href="http://www.unknownworlds.com/ns/" title="Natural Selection">NS2 game</a>. They even wrote <a href="http://www.unknownworlds.com/decoda" title="Decoda">a Lua debugger (decoda)</a> two months ago.<br />
<center><img src="http://www.rubyinside.com/wp-content/uploads/2007/11/tiobenov2007.jpg" border="0" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewsblog.org/2007/11/23/ruby-9th-most-popular-programming-language/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
