<?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>Hungry Machine &#187; ruby</title>
	<atom:link href="http://blog.hungrymachine.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hungrymachine.com</link>
	<description>The guys behind LivingSocial</description>
	<lastBuildDate>Sun, 25 Oct 2009 15:08:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sorry Mephisto.. Moving to WordPress</title>
		<link>http://blog.hungrymachine.com/2008/12/09/sorry-mephisto-moving-to-wordpress/</link>
		<comments>http://blog.hungrymachine.com/2008/12/09/sorry-mephisto-moving-to-wordpress/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 18:56:21 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog2.hungrymachine.com/2008/12/09/sorry-mephisto-moving-to-wordpress/</guid>
		<description><![CDATA[Dear Mephisto, you&#8217;ve been great. We&#8217;ve been dating for a while, and I didnt have any complaints. but I&#8217;m sorta sick of writing blog posts in your web UI. I heard there are plugins for 0.8 for metaweblog api support, but after putzing around with rails 2.0 vs 2.2, etc&#8230; I decided to break up [...]]]></description>
			<content:encoded><![CDATA[<blockquote style="clear: both"><p>Dear Mephisto, you&#8217;ve been great. We&#8217;ve been dating for a while, and I didnt have any complaints. but I&#8217;m sorta sick of writing blog posts in your web UI. I heard there are plugins for 0.8 for metaweblog api support, but after putzing around with rails 2.0 vs 2.2, etc&#8230; I decided to break up with you. It&#8217;s really because I wanted to play with <a href="http://www.drinkbrainjuice.com/blogo" target="_blank">blogo</a>. No hard feelings. Lets be friends.</p></blockquote>
<blockquote style="clear: both"><p>Hi WordPress. How are you?</p></blockquote>
<p style="clear: both">We just ported our blog to WordPress. To import all our old content, I found <a href="http://schwuk.com/articles/2008/03/25/thy-will-be-done-m2wppy-is-released" target="_blank">m2wp.pl</a>, which after adding some mysql patches, does a great job of generating a wordpress export file that imports perfectly from the WP admin UI. It was missing a few features, like correct author attribution, so I make some tweaks and put it on <a href="http://github.com/hungrymachine/mephisto_to_wordpress/tree/master" target="_blank">github</a> if anyone is interested.</p>
<p style="clear: both">BTW, whats blogo?</p>
<p style="clear: both"><a class="image-link" href="http://twitter.com/lrz/status/1041024849"><img style=" text-align: center; display: block; margin: 0 auto 10px;" src="http://blog.hungrymachine.com/wp-content/uploads/2008/12/picture-32.png" alt="" width="400" height="168" /></a>Sor far I like.</p>
<p style="clear: both">One feature request for us techies, an easy TextMate &#8220;insert code here&#8221; feature.</p>
<p style="clear: both">UPDATE: don&#8217;t forget to cp your assets.</p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2008/12/09/sorry-mephisto-moving-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Pretty SVN commit emails</title>
		<link>http://blog.hungrymachine.com/2007/11/05/pretty-svn-commit-emails/</link>
		<comments>http://blog.hungrymachine.com/2007/11/05/pretty-svn-commit-emails/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 18:51:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2008/06/05/pretty-svn-commit-emails</guid>
		<description><![CDATA[
So i know it may be old school, but I like getting svn commit messages, especially when working on a small team.  I found ElliotH&#8217;s post about A better subversion post-commit hook than commit-email.pl, but it wasnt entirely working. 
Most of the credit goes to him, I just fixed the colorization.  
[UPDATED]: for [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float:left;padding-right:5px" src="http://blog.hungrymachine.com/assets/2007/11/5/Picture_10_1.png"></p>
<p>So i know it may be old school, but I like getting svn commit messages, especially when working on a small team.  I found <a href="http://elliotth.blogspot.com">ElliotH&#8217;s</a> post about <a href="http://elliotth.blogspot.com/2005/02/better-subversion-post-commit-hook.html">A better subversion post-commit hook than commit-email.pl</a>, but it wasnt entirely working. </p>
<p>Most of the credit goes to him, I just fixed the colorization.  </p>
<p>[UPDATED]: for some reason, new lines werent looking good in all emails</p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#888">#!/usr/bin/ruby -w</span>

<span style="color:#888"># A Subversion post-commit hook. Edit the configurable stuff below, and</span>
<span style="color:#888"># copy into your repository's hooks/ directory as &quot;post-commit&quot;. Don't</span>
<span style="color:#888"># forget to &quot;chmod a+x post-commit&quot;.</span>

<span style="color:#888"># ------------------------------------------------------------------------</span>

<span style="color:#888"># You *will* need to change these.</span>

address=<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">FOO@SOME_DOMAIN.com</span><span style="color:#710">&quot;</span></span>
sendmail=<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">/usr/sbin/sendmail</span><span style="color:#710">&quot;</span></span>
svnlook=<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">/usr/bin/svnlook</span><span style="color:#710">&quot;</span></span>

<span style="color:#888"># ------------------------------------------------------------------------</span>

require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">cgi</span><span style="color:#710">'</span></span>

<span style="color:#888"># Subversion's commit-email.pl suggests that svnlook might create files.</span>
<span style="color:#036; font-weight:bold">Dir</span>.chdir(<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">/tmp</span><span style="color:#710">&quot;</span></span>)

<span style="color:#888"># What revision in what repository?</span>
repo = <span style="color:#038; font-weight:bold">ARGV</span>.shift()
rev = <span style="color:#038; font-weight:bold">ARGV</span>.shift()

<span style="color:#888"># Get the overview information.</span>
info=<span style="background-color:#f0fff0"><span style="color:#161">`</span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>svnlook<span style="color:#161">}</span></span><span style="color:#2B2"> info </span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>repo<span style="color:#161">}</span></span><span style="color:#2B2"> -r </span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>rev<span style="color:#161">}</span></span><span style="color:#161">`</span></span>
info_lines=info.split(<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>)
author=info_lines.shift
date=info_lines.shift
info_lines.shift
comment=info_lines

<span style="color:#888"># Output the overview.</span>
body = <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;p&gt;&lt;b&gt;</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>author<span style="color:#710">}</span></span><span style="color:#D20">&lt;/b&gt; </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>date<span style="color:#710">}</span></span><span style="color:#D20">&lt;/p&gt;</span><span style="color:#710">&quot;</span></span>
body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;p&gt;</span><span style="color:#710">&quot;</span></span>
comment.each { |line|  body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span><span style="color:#036; font-weight:bold">CGI</span>.escapeHTML(line)<span style="color:#710">}</span></span><span style="color:#D20">&lt;br/&gt;</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span> }
body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;/p&gt;</span><span style="color:#710">&quot;</span></span>
body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;hr noshade&gt;</span><span style="color:#710">&quot;</span></span>

<span style="color:#888"># Get and output the patch.</span>
changes=<span style="background-color:#f0fff0"><span style="color:#161">`</span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>svnlook<span style="color:#161">}</span></span><span style="color:#2B2"> diff </span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>repo<span style="color:#161">}</span></span><span style="color:#2B2"> -r </span><span style="background-color:#f0fff0"><span style="color:#161">#{</span>rev<span style="color:#161">}</span></span><span style="color:#161">`</span></span>
body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;pre&gt;</span><span style="color:#710">&quot;</span></span>
changes.each <span style="color:#080; font-weight:bold">do</span> |top_line|
  top_line.split(<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>).each <span style="color:#080; font-weight:bold">do</span> |line|
    color = <span style="color:#080; font-weight:bold">case</span>
      <span style="color:#080; font-weight:bold">when</span> line =~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^Modified: </span><span style="color:#404">/</span></span> || line =~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^=+$</span><span style="color:#404">/</span></span> || line =~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^@@ </span><span style="color:#404">/</span></span>: <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">gray</span><span style="color:#710">&quot;</span></span>
      <span style="color:#080; font-weight:bold">when</span> line =~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^-</span><span style="color:#404">/</span></span>: <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">red</span><span style="color:#710">&quot;</span></span>
      <span style="color:#080; font-weight:bold">when</span> line =~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^</span><span style="color:#04D">\+</span><span style="color:#404">/</span></span>: <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">blue</span><span style="color:#710">&quot;</span></span>
      <span style="color:#080; font-weight:bold">else</span> <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">black</span><span style="color:#710">&quot;</span></span>
    <span style="color:#080; font-weight:bold">end</span>
    body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">%Q{</span><span style="color:#D20">&lt;font style=&quot;color:</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>color<span style="color:#710">}</span></span><span style="color:#D20">&quot;&gt;</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span><span style="color:#036; font-weight:bold">CGI</span>.escapeHTML(line)<span style="color:#710">}</span></span><span style="color:#D20">&lt;/font&gt;&lt;br/&gt;</span><span style="color:#04D">\n</span><span style="color:#710">}</span></span>
 <span style="color:#080; font-weight:bold">end</span>
<span style="color:#080; font-weight:bold">end</span>
body &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">&lt;/pre&gt;</span><span style="color:#710">&quot;</span></span>

<span style="color:#888"># Write the header.</span>
header = <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">To: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>address<span style="color:#710">}</span></span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">From: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>address<span style="color:#710">}</span></span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">Subject: [SVN] </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>repo<span style="color:#710">}</span></span><span style="color:#D20"> revision </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>rev<span style="color:#710">}</span></span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">Reply-to: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>address<span style="color:#710">}</span></span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">MIME-Version: 1.0</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">Content-Type: text/html; charset=UTF-8</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">Content-Transfer-Encoding: 8bit</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>
header &lt;&lt; <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>

<span style="color:#888"># Send the mail.</span>
<span style="color:#080; font-weight:bold">begin</span>
    fd = open(<span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">|</span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>sendmail<span style="color:#710">}</span></span><span style="color:#D20"> </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>address<span style="color:#710">}</span></span><span style="color:#710">&quot;</span></span>, <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">w</span><span style="color:#710">&quot;</span></span>)
    fd.print(header)
    fd.print(body)
<span style="color:#080; font-weight:bold">rescue</span>
    exit(<span style="color:#00D; font-weight:bold">1</span>)
<span style="color:#080; font-weight:bold">end</span>
fd.close

<span style="color:#888"># We're done.</span>
exit(<span style="color:#00D; font-weight:bold">0</span>)</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/11/05/pretty-svn-commit-emails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JRuby trunk == better/faster Rails performance</title>
		<link>http://blog.hungrymachine.com/2007/11/03/jruby-looking-better-every-day/</link>
		<comments>http://blog.hungrymachine.com/2007/11/03/jruby-looking-better-every-day/#comments</comments>
		<pubDate>Sat, 03 Nov 2007 21:56:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2008/11/13/jruby-looking-better-every-day</guid>
		<description><![CDATA[So I remember a couple months ago playing with JRuby, and while fibonacci was super fast, Rails was way off..  ActiveRecord performance 6x-10x slower than MRI&#8230; 
Looks like its getting better. Disclaimer: These are really really simple non-scientific tests.
Local mysql database, MYISAM, table people, with 2 columns, (id, name). 100k rows


&#62; jruby -J-server -O [...]]]></description>
			<content:encoded><![CDATA[<p>So I remember a couple months ago playing with JRuby, and while fibonacci was super fast, Rails was way off..  ActiveRecord performance 6x-10x slower than MRI&#8230; </p>
<p>Looks like its getting better. Disclaimer: These are really really simple non-scientific tests.</p>
<p>Local mysql database, MYISAM, table people, with 2 columns, (id, name). 100k rows</p>
<div class="CodeRay">
<div class="code">
<pre>&gt; jruby -<span style="color:#036; font-weight:bold">J</span>-server -<span style="color:#036; font-weight:bold">O</span> script/console production
&gt;&gt; <span style="color:#036; font-weight:bold">Benchmark</span>.measure {<span style="color:#00D; font-weight:bold">10000</span>.times {<span style="color:#036; font-weight:bold">Person</span>.find <span style="color:#A60">:first</span>}}.total
=&gt; <span style="color:#60E; font-weight:bold">2.286</span></pre>
</div>
</div>
<div class="CodeRay">
<div class="code">
<pre>&gt; ./script/console production
&gt;&gt;  <span style="color:#036; font-weight:bold">Benchmark</span>.measure {<span style="color:#00D; font-weight:bold">10000</span>.times {<span style="color:#036; font-weight:bold">Person</span>.find <span style="color:#A60">:first</span>}}.total
=&gt; <span style="color:#60E; font-weight:bold">1.7</span></pre>
</div>
</div>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#036; font-weight:bold">Mongrel</span>
&gt; ab -n <span style="color:#00D; font-weight:bold">1000</span> http<span style="color:#A60">:/</span>/localhost:<span style="color:#00D; font-weight:bold">3001</span>/people/<span style="color:#00D; font-weight:bold">1</span>
<span style="color:#036; font-weight:bold">Requests</span> per second:    <span style="color:#60E; font-weight:bold">95.02</span> [<span style="color:#888">#/sec] (mean)</span></pre>
</div>
</div>
<p>On Glassfish v3 with:  RAILS_ENV=production jruby -J-server -O -S glassfish_rails glass2, after a bit of warmup.</p>
<div class="CodeRay">
<div class="code">
<pre>&gt; ab -n <span style="color:#00D; font-weight:bold">1000</span> http<span style="color:#A60">:/</span>/localhost:<span style="color:#00D; font-weight:bold">8080</span>/glass2/people/<span style="color:#00D; font-weight:bold">1</span>
<span style="color:#036; font-weight:bold">Requests</span> per second:    <span style="color:#60E; font-weight:bold">48.25</span> [<span style="color:#888">#/sec] (mean)</span></pre>
</div>
</div>
<p>turning logging mostly off</p>
<div class="CodeRay">
<div class="code">
<pre>&gt; ab -n <span style="color:#00D; font-weight:bold">1000</span> http<span style="color:#A60">:/</span>/localhost:<span style="color:#00D; font-weight:bold">8080</span>/glass2/people/<span style="color:#00D; font-weight:bold">1</span>
<span style="color:#036; font-weight:bold">Requests</span> per second:    <span style="color:#60E; font-weight:bold">56.70</span> [<span style="color:#888">#/sec] (mean)</span></pre>
</div>
</div>
<p>All in all, thats impressive.  Congrats to Charles, Ola, and the whole JRuby crew.  I dont think i&#8217;ll be putting this in production yet, but I&#8217;m very interested to hear from others that have.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/11/03/jruby-looking-better-every-day/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Super fast IP to lat/lng in Rails &#8211; Part 2</title>
		<link>http://blog.hungrymachine.com/2007/10/31/super-fast-ip-to-lat-lng-in-rails-part-2/</link>
		<comments>http://blog.hungrymachine.com/2007/10/31/super-fast-ip-to-lat-lng-in-rails-part-2/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 03:04:00 +0000</pubDate>
		<dc:creator>aaron</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2008/11/13/super-fast-ip-to-lat-lng-in-rails-part-2</guid>
		<description><![CDATA[In  Super fast IP to lat/lng in Rails, I showed a solution for fast IP to lat/lng resolution in rails.  I called it &#8220;Super fast&#8221; because it performed orders of magnitude faster the the RESTful interface, but it was also &#8220;Super fast&#8221; to implement.  That being said, Kyle made a comment to [...]]]></description>
			<content:encoded><![CDATA[<p>In  <a href="http://blog.hungrymachine.com/2007/10/22/super-fast-ip-to-lat-lng-in-rails">Super fast IP to lat/lng in Rails</a>, I showed a solution for fast IP to lat/lng resolution in rails.  I called it &#8220;Super fast&#8221; because it performed orders of magnitude faster the the RESTful interface, but it was also &#8220;Super fast&#8221; to implement.  That being said, <a href="http://www.kisscafe.com/">Kyle</a> made a comment to check out the GeoIP gem.  I had heard of <a href="http://www.maxmind.com/">MaxMind</a> before, but I didnt want to spend hundreds of dollars to solve this problem.  What I didnt know was they also have a free download of their &#8220;lite&#8221; datasource.  They have a <a href="http://www.maxmind.com/app/geolitecountry">GeoLiteCountry</a> and <a href="http://www.maxmind.com/app/geolitecity">GeoLiteCity</a> version, although only the City version has lat/lng info.  They provide wrappers in most languages (including Ruby), and while Kyle&#8217;s suggested <a href="http://rubyforge.org/projects/geoip/">geoip</a>, I found <a href="http://rubyforge.org/projects/geoip-city/">geoip_city</a> on RubyForge which I like a bit better. <br/><br />
<br/><br />
[UPDATED]: I had forgotten to include the install instructions for getting the GeoIP C library.</p>
<p>Install the C bindings, the gem (which isnt packaged as a gem for easy download) and get the data.</p>
<div class="CodeRay">
<div class="code">
<pre>wget http<span style="color:#A60">:/</span>/www.maxmind.com/download/geoip/api/c/<span style="color:#036; font-weight:bold">GeoIP</span>.tar.gz
tar -zxvf <span style="color:#036; font-weight:bold">GeoIP</span>.tar.gz
cd <span style="color:#036; font-weight:bold">GeoIP</span>
./configure &amp;&amp; make &amp;&amp; sudo make install

wget http<span style="color:#A60">:/</span>/rubyforge.org/frs/download.php/<span style="color:#00D; font-weight:bold">27077</span>/geoip_city<span style="color:#60E; font-weight:bold">-0.1</span>.gem
sudo gem install geoip_city<span style="color:#60E; font-weight:bold">-0.1</span>.gem
wget http<span style="color:#A60">:/</span>/www.maxmind.com/download/geoip/database/<span style="color:#036; font-weight:bold">GeoLiteCity</span>.dat.gz
gunzip <span style="color:#036; font-weight:bold">GeoLiteCity</span>.dat.gz
sudo mkdir <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">usr</span><span style="color:#404">/</span></span>local/share/<span style="color:#036; font-weight:bold">GeoIP</span>
sudo mv <span style="color:#036; font-weight:bold">GeoLiteCity</span>.dat <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">usr</span><span style="color:#404">/</span></span>local/share/<span style="color:#036; font-weight:bold">GeoIP</span>/<span style="color:#036; font-weight:bold">GeoLiteCity</span>.dat</pre>
</div>
</div>
<p>Then the ruby part:</p>
<div class="CodeRay">
<div class="code">
<pre>&gt;&gt; require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">geoip_city</span><span style="color:#710">'</span></span>
&gt;&gt; g = <span style="color:#036; font-weight:bold">GeoIPCity</span>::<span style="color:#036; font-weight:bold">Database</span>.new(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">/usr/local/share/GeoIP/GeoLiteCity.dat</span><span style="color:#710">'</span></span>)
&gt;&gt; res = g.look_up(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">4.2.2.2</span><span style="color:#710">'</span></span>)
&gt;&gt; puts <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">lat: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>res[<span style="color:#A60">:latitude</span>]<span style="color:#710">}</span></span><span style="color:#D20"> lng: </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span>res[<span style="color:#A60">:longitude</span>]<span style="color:#710">}</span></span><span style="color:#710">&quot;</span></span>
lat: <span style="color:#60E; font-weight:bold">38.0</span> lng: <span style="color:#60E; font-weight:bold">-97.0</span></pre>
</div>
</div>
<p>So the question is (although its probably obvious), which is faster?</p>
<div class="CodeRay">
<div class="code">
<pre>&gt;&gt;  <span style="color:#036; font-weight:bold">Benchmark</span>.measure { <span style="color:#00D; font-weight:bold">1000</span>.times {<span style="color:#036; font-weight:bold">Hostip</span>.geocode(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">4.2.2.2</span><span style="color:#710">'</span></span>)}}.total
=&gt; <span style="color:#60E; font-weight:bold">1.02</span>
&gt;&gt;   <span style="color:#036; font-weight:bold">Benchmark</span>.measure { <span style="color:#00D; font-weight:bold">100000</span>.times {g.look_up(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">4.2.2.2</span><span style="color:#710">'</span></span>)}}.total
=&gt; <span style="color:#60E; font-weight:bold">0.5</span></pre>
</div>
</div>
<p>Conclusion?  The C library is MUCH faster than my database version.  200k req/s  vs.  1k req/s.  As a side note, I also tested the &#8220;geoip&#8221; gem, and it was about 3x faster than my database version. <br/><br/><br />
But all in all, for the 5 minutes it took me to write the original version, it was fast enough&#8230; but MaxMind GeoLiteCity + the geoip_city gem is Super fast-er.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/10/31/super-fast-ip-to-lat-lng-in-rails-part-2/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Killing sneaky mongrels</title>
		<link>http://blog.hungrymachine.com/2007/08/16/killing-sneaky-mongrels/</link>
		<comments>http://blog.hungrymachine.com/2007/08/16/killing-sneaky-mongrels/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 18:16:00 +0000</pubDate>
		<dc:creator>val</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Ops]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2007/08/29/killing-sneaky-mongrels</guid>
		<description><![CDATA[We found that sometimes monit fails to restart all mongrel instances after deployment and some of them end up running with the pid file gone. Since there is no pid, monit believes the instance is not running so it tries to start a new one on the same port and, of course, fails. Which leads [...]]]></description>
			<content:encoded><![CDATA[<p>We found that sometimes <a href="http://www.tildeslash.com/monit/">monit</a> fails to restart all mongrel instances after deployment and some of them end up running with the pid file gone. Since there is no pid, monit believes the instance is not running so it tries to start a new one on the same port and, of course, fails. Which leads to stale mongrel instances with old code. We&#8217;re investigating a long term solution but in the meantime have wrapped the mongrel_rails start script with a replacement which finds and kills the stale mongrel instances before starting a new one.</p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#888">#!/usr/bin/env ruby</span>

<span style="color:#080; font-weight:bold">class</span> <span style="color:#B06; font-weight:bold">MongrelController</span>

  <span style="color:#080; font-weight:bold">def</span> <span style="color:#038; font-weight:bold">self</span>.run_mongrel(args)
    pid = extract_pid(args)
    kill_stale_process(pid) <span style="color:#080; font-weight:bold">if</span> pid
    system <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#D20">/bin/mongrel_rails </span><span style="background-color:#fff0f0"><span style="color:#710">#{</span> args.join(<span style="background-color:#ffe0e0"><span style="color:#710">'</span><span style="color:#D20"> </span><span style="color:#710">'</span></span>) <span style="color:#710">}</span></span><span style="color:#710">&quot;</span></span>
  <span style="color:#080; font-weight:bold">end</span>

  <span style="color:#080; font-weight:bold">def</span> <span style="color:#038; font-weight:bold">self</span>.extract_pid(args)
     (args[<span style="color:#00D; font-weight:bold">0</span>] == <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">start</span><span style="color:#710">'</span></span>) &amp;&amp; (i = args.index(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">-P</span><span style="color:#710">'</span></span>)) &amp;&amp; args[i + <span style="color:#00D; font-weight:bold">1</span>]
  <span style="color:#080; font-weight:bold">end</span>

  <span style="color:#080; font-weight:bold">def</span> <span style="color:#038; font-weight:bold">self</span>.kill_stale_process(pid)
    mongrel_processes(pid).each { |p| process_running?(p) &amp;&amp; <span style="color:#036; font-weight:bold">Process</span>.kill(<span style="color:#00D; font-weight:bold">9</span>, p)  }
  <span style="color:#080; font-weight:bold">end</span>

  <span style="color:#080; font-weight:bold">def</span> <span style="color:#038; font-weight:bold">self</span>.mongrel_processes(pid)
    <span style="background-color:#f0fff0"><span style="color:#161">`</span><span style="color:#2B2">ps axww -o 'pid command'</span><span style="color:#161">`</span></span>.split(<span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\n</span><span style="color:#404">/</span></span>).inject([]) <span style="color:#080; font-weight:bold">do</span> |mongrels, process|
      mongrels &lt;&lt; process[<span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">^</span><span style="color:#04D">\s</span><span style="color:#808">*(</span><span style="color:#04D">\d</span><span style="color:#808">+)</span><span style="color:#404">/</span></span>][<span style="color:#d70; font-weight:bold">$1</span>].to_i <span style="color:#080; font-weight:bold">if</span> process.match(<span style="background-color:#fff0ff"><span style="color:#404">%r{</span><span style="color:#808">/bin/mongrel_rails</span><span style="color:#04D">\s</span><span style="color:#808">.*</span><span style="color:#04D">\s</span><span style="color:#808">-P</span><span style="color:#04D">\s</span><span style="background-color:#fff0ff"><span style="color:#404">#{</span> pid <span style="color:#404">}</span></span><span style="color:#04D">\b</span><span style="color:#404">}</span></span>)
      mongrels
    <span style="color:#080; font-weight:bold">end</span>
  <span style="color:#080; font-weight:bold">end</span>

  <span style="color:#080; font-weight:bold">def</span> <span style="color:#038; font-weight:bold">self</span>.process_running?(pid)
    pid &amp;&amp; (<span style="background-color:#f0fff0"><span style="color:#161">`</span><span style="color:#2B2">ps -p </span><span style="background-color:#f0fff0"><span style="color:#161">#{</span> pid <span style="color:#161">}</span></span><span style="color:#161">`</span></span>.split(<span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\n</span><span style="color:#404">/</span></span>).size == <span style="color:#00D; font-weight:bold">2</span>)
  <span style="color:#080; font-weight:bold">end</span>

<span style="color:#080; font-weight:bold">end</span>

<span style="color:#036; font-weight:bold">MongrelController</span>.run_mongrel(<span style="color:#038; font-weight:bold">ARGV</span>)</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/08/16/killing-sneaky-mongrels/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a ruby-based AIM notifier in nagios</title>
		<link>http://blog.hungrymachine.com/2007/08/14/using-a-ruby-based-aim-notifier-in-nagios/</link>
		<comments>http://blog.hungrymachine.com/2007/08/14/using-a-ruby-based-aim-notifier-in-nagios/#comments</comments>
		<pubDate>Tue, 14 Aug 2007 22:36:00 +0000</pubDate>
		<dc:creator>val</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Ops]]></category>
		<category><![CDATA[aim]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">blog.hungrymachine.com/2007/08/17/using-a-ruby-based-aim-notifier-in-nagios</guid>
		<description><![CDATA[If you use nagios for monitoring of your rails instances, you might want to get notification not only via email or SMS-messages but to your AIM when you are online. The script (libexec/aim_notifier.rb) utilizes the Net::TOC gem for sending out notifications:


#!/usr/bin/env ruby

 require 'rubygems'
 require 'net/toc'

 user = 'your_bot_name'
 password = 'bot_password'

 msg = ARGV[0].to_s.gsub('\n', [...]]]></description>
			<content:encoded><![CDATA[<p>If you use <a href="http://www.nagios.org/">nagios</a> for monitoring of your rails instances, you might want to get notification not only via email or <a href="http://www.sms411.net/2006/07/how-to-send-email-to-phone.html"><span class="caps">SMS</span>-messages</a> but to your <span class="caps">AIM</span> when you are online. The script (<em>libexec/aim_notifier.rb</em>) utilizes the <a href="http://rubyforge.org/projects/net-toc/">Net::TOC</a> gem for sending out notifications:</p>
<div class="CodeRay">
<div class="code">
<pre><span style="color:#888">#!/usr/bin/env ruby</span>

 require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">rubygems</span><span style="color:#710">'</span></span>
 require <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">net/toc</span><span style="color:#710">'</span></span>

 user = <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">your_bot_name</span><span style="color:#710">'</span></span>
 password = <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">bot_password</span><span style="color:#710">'</span></span>

 msg = <span style="color:#038; font-weight:bold">ARGV</span>[<span style="color:#00D; font-weight:bold">0</span>].to_s.gsub(<span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">\n</span><span style="color:#710">'</span></span>, <span style="background-color:#fff0f0"><span style="color:#710">&quot;</span><span style="color:#04D">\n</span><span style="color:#710">&quot;</span></span>)

 client = <span style="color:#036; font-weight:bold">Net</span>::<span style="color:#036; font-weight:bold">TOC</span>.new(user, password)

 client.connect

 sleep <span style="color:#00D; font-weight:bold">3</span>

 buddies = []

 client.buddy_list.each_group { |g, b| buddies = b <span style="color:#080; font-weight:bold">if</span> g == <span style="background-color:#fff0f0"><span style="color:#710">'</span><span style="color:#D20">Friends</span><span style="color:#710">'</span></span> }

 buddies.each <span style="color:#080; font-weight:bold">do</span> |b|
   b.send_im(msg) <span style="color:#080; font-weight:bold">if</span> b.available?
 <span style="color:#080; font-weight:bold">end</span>

 sleep <span style="color:#00D; font-weight:bold">3</span>

 client.disconnect</pre>
</div>
</div>
<p> You need to add any account you want to be notified to bot&#8217;s friends (either by logging to <span class="caps">AIM</span> using the bot account or using Net::TOC&#8217;s ability to add friends).</p>
<p> The last piece is to add a new notifier in <em>etc/objects/commands.cfg</em> as:</p>
<div class="CodeRay">
<div class="code">
<pre> define command{
         command_name    notify-service-by-aim
         command_line    $USER1$/aim_notifier.rb $ARG1$ $ARG2$ &quot;***** Nagios *****\n\nNotification Ty
 pe: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState:
 $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$&quot;
         }</pre>
</div>
</div>
<p> and to append it to the list of notifiers defined for a contact template in <em>etc/objects/commands.cfg</em>:</p>
<div class="CodeRay">
<div class="code">
<pre> service_notification_commands   notify-service-by-email,notify-service-by-aim</pre>
</div>
</div>
<p>Repeat the configuration if you want to use the <span class="caps">AIM</span> notification for hosts as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hungrymachine.com/2007/08/14/using-a-ruby-based-aim-notifier-in-nagios/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
