<?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>Introspection &#187; Ruby</title>
	<atom:link href="http://blog.jeffhaynie.us/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.jeffhaynie.us</link>
	<description>Jeff Haynie on business and technology in Silicon Valley</description>
	<lastBuildDate>Fri, 14 Jan 2011 18:39:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple twitter ruby utility</title>
		<link>http://blog.jeffhaynie.us/simple-twitter-ruby-utility.html</link>
		<comments>http://blog.jeffhaynie.us/simple-twitter-ruby-utility.html#comments</comments>
		<pubDate>Fri, 27 Jun 2008 04:06:12 +0000</pubDate>
		<dc:creator>Jeff Haynie</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[web2.0]]></category>

		<guid isPermaLink="false">http://blog.jeffhaynie.us/?p=205</guid>
		<description><![CDATA[There might be something like this already out there but I just wanted a quick and dirty ruby class to get some relevant user information given a twitter username.
Feel free to use it as you see fit &#8211; just don&#8217;t blame me if you have an issue.  You can download from here.

# Copyright (c) [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>There might be something like this already out there but I just wanted a quick and dirty ruby class to get some relevant user information given a twitter username.</p>
<p>Feel free to use it as you see fit &#8211; just don&#8217;t blame me if you have an issue.  You can <a href="http://pastebin.com/pastebin.php?dl=f30cddda3">download</a> from here.</p>
<pre language="ruby" style="font-size:10px"><code>
# Copyright (c) 2008 by Jeff Haynie.  All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
#    * Redistributions of source code must retain the above copyright notice,
#      this list of conditions and the following disclaimer.
#
#    * Redistributions in binary form must reproduce the above copyright notice,
#      this list of conditions and the following disclaimer in the documentation
#      and/or other materials provided with the distribution.
#
#    * Neither the name of Jeff Haynie nor the names of its
#      contributors may be used to endorse or promote products derived from this
#      software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

require 'open-uri'
require 'rubygems'
require 'json/pure'

class Twitter

	def Twitter.status(un)
		u = URI.parse "http://twitter.com/statuses/user_timeline.json?id=#{un}&#038;count=1"
		j = nil
		begin
			j = JSON.parse(u.read).first
		rescue OpenURI::HTTPError=>e
			case e.to_s
				when /^404/
					raise 'Not Found'
				when /^304/
					raise 'No Info'
			end
		end
		o = {}
		user = j['user']
		fullname = user['name']
		if fullname == un
			o[:firstname]=nil
			o[:lastname]=nil
		else
			o[:firstname],o[:lastname] = Twitter.parse_name(fullname)
		end
		o[:url] = user['url']
		o[:location] = user['location']
		o[:image] = user['profile_image_url']
		o[:bio] = user['description']
		o[:status] = j['text']
		o[:date] = j['created_at']
		o
	end

	private

	def Twitter.parse_name(fullname)
		idx = fullname.index ' '
		if idx
			return fullname[0..idx].strip,fullname[idx..-1].strip
		end
		return '',fullname.strip
	end

end

if __FILE__ == $0
	o = Twitter.status ARGV.first || 'jhaynie'
	puts "Firstname: #{o[:firstname]}, Lastname: #{o[:lastname]}"
	puts "URL: #{o[:url]}"
	puts "Location: #{o[:location]}"
	puts "Status: #{o[:status]}"
	puts "Date: #{o[:date]}"
	puts "Bio: #{o[:bio]}"
end
</code>
</pre>
<p>You can run from command line to test it out:</p>
<pre language="shell"><code>
> ruby twitter.rb ev
</code></pre>
<p>Replace twitter.rb with the name of the file you saved the code as and the 2nd argument (ev) with the twitter username.</p>
<img src="http://blog.jeffhaynie.us/?ak_action=api_record_view&id=205&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.jeffhaynie.us/simple-twitter-ruby-utility.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which web framework is right for your business?</title>
		<link>http://blog.jeffhaynie.us/which-web-framework-is-right-for-your-business.html</link>
		<comments>http://blog.jeffhaynie.us/which-web-framework-is-right-for-your-business.html#comments</comments>
		<pubDate>Fri, 18 May 2007 15:12:05 +0000</pubDate>
		<dc:creator>Jeff Haynie</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Entrepreneur]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Seam(less)]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[web2.0]]></category>

		<guid isPermaLink="false">http://blog.jeffhaynie.us/?p=143</guid>
		<description><![CDATA[Last night was the Atlanta Web Entrepreneur&#8217;s group meeting &#8211; which was held down at the ATDC, thanks to Lance Weatherby.  The main discussion was &#8220;Selecting a Technology for your website&#8221;.
I served on the panel as the representative for Ruby on Rails.  The other panelists were:

Calvin Yu, Partner at MyNextDive and representing Java
Neil [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Last night was the <a href="http://www.atlanta-web.org/">Atlanta Web Entrepreneur&#8217;s</a> group meeting &#8211; which was held down at the ATDC, thanks to <a href="http://blog.weatherby.net/">Lance Weatherby</a>.  The main discussion was &#8220;Selecting a Technology for your website&#8221;.</p>
<p>I served on the panel as the representative for Ruby on Rails.  The other panelists were:</p>
<ul>
<li><a href="http://blog.codeeg.com/">Calvin Yu</a>, Partner at <a href="http://www.mynextdive.com/">MyNextDive</a> and representing Java</li>
<li>Neil Green, Partner at <a href="http://www.mynextdive.com/">MyNextDive</a> and representing PHP</li>
<li><a href="http://pythonisito.blogspot.com/">Rick Copeland</a>, Senior Software Engineer, <a href="http://www.exchangeframe.com/">ExchangeFrame</a> &#8211; representing Python</li>
<li><a href="http://devcow.com/blogs/adnrg/default.aspx">Brendon Schwartz</a>, <a href="http://devcow.com/default.aspx">Atlanta .NET Regular Guys</a>, representing of course, Microsoft .NET</li>
</ul>
<p>Rusty Zarse was suppose to moderate but had a family conflict &#8211; so  Alan Pinstein stepped in and did a fine job.  I had met Alan the previous night at the Capital Connections event and his <a href="http://www.showcasere.com">real estate web business</a> is very interesting.</p>
<p>We spent most of the night debating the merits and weaknesses of each of the different languages and frameworks. Much of the discussion blurred between comparing features of the language with the framework itself.  The audience seemed to have a varying degree of backgrounds &#8211; some technical, some non-technical, others in the middle.  It was challenging to talk about the pros and cons of specific frameworks and not get too geeked out. I think the main consensus we all seemed to get across was that (a) a technology platform and toolset is really about the people that are building the product/service and (b) it depends on the requirements of the business.  Several of us made the point at different points that what really mattered the most was getting quality technical folk. If you did that, they would figure out the right frameworks to use.</p>
<p>As in almost all technology discussions, I try and think about it from a total cost of ownership standpoint.  And, that often conjures up thoughts of how much my hardware costs are and what the amortization of the upfront buy will be. And then, certainly, the cost of labor or contract services assistance.  And training, etc.  But, recently, I had a long conversation with a customer that had made a couple of bad technology selections &#8211; not because of the technology itself &#8211; but because they neither had any internal expertise (or just plain experience) with the selection nor did they have any access regionally to people on a contract basis that could be hired to bridge the gap.  While both products they selected are open source, they&#8217;re both extremely complex and their codebases are impossible to learn on a whim &#8211; especially by an average programmer.  In their case, they did the simple buy-vs-build equation and technology evaluation &#8211; but completely eliminated probably the most important part: who&#8217;s going to be able to &#8220;do this&#8221;.  Several questions last night centered around a similar flaw in thinking: &#8220;Which framework should I as an entrepreneur make for my technical team?&#8221;  Hello&#8230;. <em>None</em>.  If you&#8217;re an entrepreneur with no deep technology background and you have a team &#8212; <em>you shouldn&#8217;t be making any framework decision &#8211; they should</em>.  You need to provide the requirements, the financial working parameters and the support they need &#8212; and you <em>should get out of the way and give them the ability to execute</em>.  If you&#8217;re an entrepreneur with a technology team, go fetch them pizza while they code their butts off.  I promise you, it will go a long way &#8212; especially much longer than trying to make the decision for them.</p>
<p>So, I thought I&#8217;d try and address in written form some of the questions that were asked last night:</p>
<p><strong>What kind of websites is your technology best suited for?  Which is it not so well suited for?</strong></p>
<p>Ruby on Rails is really making a lot of debuts in more recent Web2.0 websites.  This is partly because it&#8217;s the latest new thing.  But, also, because it has a large concentration of libraries that have been specifically created for the next generation of capabilities such as <a href="http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids">tagging</a> and <a href="http://graticule.rubyforge.org/plugin.html">geocoding</a>.  That&#8217;s not to say that you couldn&#8217;t build a traditional enterprise website in RoR, it can.  RoR lacks support for some of the more enterprise integration tasks that some enterprises need &#8211; but there are plenty of backed in options like <a href="http://code.google.com/p/activemessaging/wiki/ActiveMessaging">Active Messaging</a> that allows you to talk with a <a href="http://java.sun.com/products/jms/">JMS</a> service for messaging.  Support for web services and <a href="http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics">REST</a> is also backed into to RoR &#8211; so it&#8217;s easy to integrate into a enterprise service bus or other SOA architecture.</p>
<p><strong>What famous web2.0 sites are using your technology?</strong></p>
<p><a href="http://www.37signals.com">37Signals</a> has made RoR not only possible, but popular, based on its nice utility software-as-a-service applications such as <a href="http://www.basecamphq.com/">Basecamp</a>, <a href="http://www.campfirenow.com/">Campfire</a> and most recently, <a href="http://www.highrisehq.com/">Highrise</a>.  But also, the more <a href="http://glu.ttono.us/articles/2007/04/15/on-twitter-rails-and-community">recent challenges</a> at <a href="http://www.twitter.com">Twitter</a> has also proven that RoR based applications have a way to go to get to massive scale.</p>
<p><strong>What does it cost to use your technology (e.g. hardware, software and support)?</strong></p>
<p>RoR is open source and free.  Hardware is not.  Support is based on the community model &#8211; and I&#8217;m sure you can find a number of people who will support your rails effort if you really need it.  Like almost all technology decisions, the largest factor in cost is people cost.  Not just their salaries, but how efficient and productive they are.  Most frameworks are chosen to help solve this problem &#8211; and RoR really succeeds in making development not only pleasant and fun again, but also extremely productive and hassle-free.</p>
<p><strong>How steep is the learning curve for newcomers?</strong></p>
<p>I&#8217;ve found that RoR is a little harder to un-train developers that have a lot of Java experience &#8211; simply because RoR (and Ruby itself) is just plan straightforward.  It supports traditional syntaxes like the for-loop.</p>
<p>Let me illustrate:</p>
<p>In most traditional languages, you can iterate over a loop such as:</p>
<p><code><br />
for (x=0;x&lt;len;x++)<br />
{<br />
// do something here<br />
}<br />
</code></p>
<p>In ruby, you can do something much easier:</p>
<p><code><br />
len.times do |x|<br />
# do something here<br />
end<br />
</code></p>
<p>OK, certainly that was a very trivial example.  But let&#8217;s take another simple one.  Let&#8217;s say you need to pass in a number of milliseconds to represent how long you should sleep before you wake up.  Unless the unit of time is very simple, most people have built or used libraries to assist them in calculating the value.  Not in RoR:</p>
<p><code><br />
sleep (10.minutes)<br />
</code></p>
<p>Any integer value in RoR supports any number of time unit conversions automatically. Is that enough to choose RoR over .NET?  No, of course not.  But, it&#8217;s pretty easy to pickup and exteremely fast to get proficient in it.  It&#8217;s also one of those rare frameworks that you have moments of fun finding new ways of doing things &#8211; and when you do, you say &#8220;yes, of course, that&#8217;s so obvious!&#8221;.</p>
<p><strong>How easy have you found it to find skilled people?  How about in Atlanta?</strong></p>
<p>Finding skilled people in RoR has been a little challenging &#8211; but that&#8217;s simply a function of time.  There are certainly way more Java and .NET shops in Atlanta and the greater world than there are Ruby shops.</p>
<p><strong>How much support is there for your technology? Who have you found to be reliable?</strong></p>
<p>Support is amazing on the web for RoR.  If you think you have a need for something, it probably already exists as a <a href="http://rubygems.org/read/book/1">Ruby Gem</a> on <a href="http://http://rubyforge.org/">RubyForge</a>.</p>
<p><strong>What issues (if any) did you encounter being an evangelist for your technology in your organization?  How did you overcome them?</strong></p>
<p>For us, it was simply a matter of two variables: (a) total cost considerations of RoR &#8211; which was fractions of the Java alternatives and (b) pleasure of working with it.  For our customers, it&#8217;s not that easy.  We have to adapt to what our customer environments and constraints are &#8211; and in all cases to date, that&#8217;s still Java.  For our own projects, we&#8217;re now 100% RoR.</p>
<p><strong>What add-ons, plug-ins, tools, etc. would you recommend using?</strong></p>
<p>For RoR, I&#8217;d recommend the following:</p>
<ul>
<li><a href="http://www.capify.org/">Capistrano </a></li>
<li><a href="http://ferret.davebalmain.com/trac/">Ferret</a></li>
<li><a href="http://www.tildeslash.com/monit/">Monit</a> (not specific to rails, but a great tool)</li>
<li><a href="http://www.danga.com/memcached/">Memcached</a> (not specific to rails, but good for caching)</li>
<li><a href="http://www.hakano.org">Seam(less) </a>- I gotta plug my own stuff!</li>
</ul>
<p><strong>What are some sites you&#8217;d recommend?</strong></p>
<p>Some RoR sites I read often:</p>
<ul>
<li><a href="http://weblog.jamisbuck.org/">the { buckblogs : here }</a></li>
<li><a href="http://errtheblog.com/">err.the_blog</a></li>
<li><a href="http://www.therailsway.com/">The Rails Way</a></li>
<li><a href="http://www.rubyinside.com/">Ruby Inside</a></li>
</ul>
<p>All in all, I think the biggest problem with RoR is the fact that it&#8217;s new and hasn&#8217;t been hardened to the point of Java, .NET and PHP.  However, that will come in short time I believe.  In my previous business, we were one of the first Java based products in the telecommunications software industry.  We spent many years pleading with our customers and partners that Java would scale &#8211; and it did fine.  Now, there are a large number of Java based telecom products.</p>
<p><em>RoR has a long way to go and a short-time to get there.</em></p>
<p><img src="http://freehogg.files.wordpress.com/2006/04/technorati.gif" id="image329" alt="Technorati" /> technorati tags: <a href="http://www.technorati.com/tags/ror" rel="tag">ror</a>, <a href="http://www.technorati.com/tags/rails" rel="tag">rails</a>, <a href="http://www.technorati.com/tags/rubyonrails" rel="tag">rubyonrails</a>, <a href="http://www.technorati.com/tags/ruby" rel="tag">ruby</a>, <a href="http://www.technorati.com/tags/atlanta" rel="tag">atlanta</a>, <a href="http://www.technorati.com/tags/atlantaweb" rel="tag">atlantaweb</a>, <a href="http://www.technorati.com/tags/web2.0" rel="tag">web2.0</a>, <a href="http://www.technorati.com/tags/seamless" rel="tag">seamless</a></p>
<img src="http://blog.jeffhaynie.us/?ak_action=api_record_view&id=143&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.jeffhaynie.us/which-web-framework-is-right-for-your-business.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Envy</title>
		<link>http://blog.jeffhaynie.us/ruby-on-rails-envy.html</link>
		<comments>http://blog.jeffhaynie.us/ruby-on-rails-envy.html#comments</comments>
		<pubDate>Wed, 16 May 2007 13:27:42 +0000</pubDate>
		<dc:creator>Jeff Haynie</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.jeffhaynie.us/?p=142</guid>
		<description><![CDATA[Tomorrow in Portland, Oregon, the Ruby on Rails Conference organized by O&#8217;Reilly called RailsConf 2007 kicks off.  I wish I had signed up to go.  I heard the other day from Nate Clark at Wamily that he was going out this week &#8211; I&#8217;m so jealous.
I&#8217;ll be presenting the Ruby on Rails portion [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Tomorrow in Portland, Oregon, the Ruby on Rails Conference organized by O&#8217;Reilly called <a href="http://conferences.oreillynet.com/rails/">RailsConf 2007</a> kicks off.  I wish I had signed up to go.  I heard the other day from <a href="http://nateclark.com/">Nate Clark</a> at <a href="http://www.wamily.com">Wamily</a> that he was going out this week &#8211; I&#8217;m so jealous.</p>
<p>I&#8217;ll be presenting the Ruby on Rails portion of tomorrow&#8217;s <a href="http://www.atlanta-web.org/">Atlanta Web Entrepreneurs Group</a> meeting.  If you&#8217;d like to know why I like RoR, check these fun videos out:</p>
<p><strong>Rails vs. Java</strong></p>
<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/PQbuyKUaKFo"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/PQbuyKUaKFo" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></p>
<p><strong>Rails vs. PHP Database</strong></p>
<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/n1NVfDlU6yQ"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/n1NVfDlU6yQ" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></p>
<p><strong>Rails vs. PHP Organization</strong></p>
<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/p5EIrSM8dCA"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/p5EIrSM8dCA" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></p>
<p>Thanks to the guys at <a href="http://www.railsenvy.com/">RailsEnvy</a> for these awesome videos.  They&#8217;re suppose to have one more video coming out tomorrow. Maybe sure you check their site for the last video in the series.</p>
<img src="http://blog.jeffhaynie.us/?ak_action=api_record_view&id=142&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.jeffhaynie.us/ruby-on-rails-envy.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Dear Java</title>
		<link>http://blog.jeffhaynie.us/dear-java.html</link>
		<comments>http://blog.jeffhaynie.us/dear-java.html#comments</comments>
		<pubDate>Tue, 30 Jan 2007 02:42:08 +0000</pubDate>
		<dc:creator>Jeff Haynie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.jeffhaynie.us/?p=81</guid>
		<description><![CDATA[Dear Java,
I&#8217;m sorry to have to write you this letter, and I hope you can forgive me for doing so.
I think we both know that our relationship has been over for some time. I have loved every minute of the ten years we have spent together. I feel bad it has to be over.
You see, [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Dear Java,</p>
<p>I&#8217;m sorry to have to write you this letter, and I hope you can forgive me for doing so.</p>
<p>I think we both know that our relationship has been over for some time. I have loved every minute of the ten years we have spent together. I feel bad it has to be over.</p>
<p>You see, the thing is I&#8217;ve been seeing someone new lately. Her name is <a href="http://www.ruby-lang.org/en/">Ruby</a>.  Ever since I started seeing her, things just haven&#8217;t been the same.  She&#8217;s quite beautiful and you&#8217;ve aged a lot over the past few years.  She&#8217;s fun and exciting.  You&#8217;ve gotten really boring.  She&#8217;s got some sexy friends she hangs out with, like <a href="http://www.rubyonrails.org/">Rails</a> and <a href="http://rubygems.org/">Gems</a>.  All your friends are really defensive and bitchy. She&#8217;s really flexible and works out a lot these days.  Lately, you&#8217;re really showing your age and you haven&#8217;t been keeping yourself fit &#8211; you&#8217;ve become pretty bloated and disorganized.  I&#8217;m sorry to say it, but you&#8217;re really losing it.</p>
<p>And one more thing. Your <a href="http://www.sun.com">parents</a> are really part of the problem and they are very controlling.  You should figure out how to get on your own.  Things would be much easier if you weren&#8217;t under their thumb.  I know they&#8217;ve told you that <a href="http://www.infoworld.com/article/06/06/27/79685_HNsunopensourcejava_1.html">you can part ways soon and get own your own</a>, but I think we know that that&#8217;s just another ploy and they&#8217;ll still control your life.  You need your independence if you&#8217;re going to have a chance at a good relationship.</p>
<p>All I can say is that I really hope we can still be friends. You&#8217;ve got a great personality and we&#8217;ve got a lot of great memories. I wish you the best of luck, please keep in touch.</p>
<p>Love always,</p>
<p>Jeff</p>
<p><img id="image329" alt="Technorati" src="http://freehogg.wordpress.com/files/2006/04/technorati.gif" /> technorati tags: <a rel="tag" href="http://www.technorati.com/tags/java">java</a>, <a rel="tag" href="http://www.technorati.com/tags/ruby">ruby</a>, <a rel="tag" href="http://www.technorati.com/tags/rubyonrails">rubyonrails</a></p>
<img src="http://blog.jeffhaynie.us/?ak_action=api_record_view&id=81&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.jeffhaynie.us/dear-java.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Why I love Ruby #1</title>
		<link>http://blog.jeffhaynie.us/why-i-love-ruby.html</link>
		<comments>http://blog.jeffhaynie.us/why-i-love-ruby.html#comments</comments>
		<pubDate>Sat, 12 Aug 2006 13:56:16 +0000</pubDate>
		<dc:creator>Jeff Haynie</dc:creator>
				<category><![CDATA[Lucene]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.jeffhaynie.us/?p=29</guid>
		<description><![CDATA[I&#8217;m going to start a new set of posts titled &#8220;Why I love Ruby&#8221;&#8230; I&#8217;ve been using Ruby for some time now and have built a number of applications using it.  Everyday, it just amazes me.  Partially the language itself. Partially the community support.
Jared and I have been doing a lot of Lucene [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;m going to start a new set of posts titled &#8220;Why I love Ruby&#8221;&#8230; I&#8217;ve been using Ruby for some time now and have built a number of applications using it.  Everyday, it just amazes me.  Partially the language itself. Partially the community support.</p>
<p>Jared and I have been doing a lot of <a href="http://lucene.apache.org/java/docs/">Lucene</a> and <a href="http://lucene.apache.org/nutch/">Nutch</a> work lately as we build out our new search-based website.  Most of our current back end, with a few exceptions, is built out in Java.  However, we&#8217;ve been doing more and more Ruby lately.</p>
<p>One of our pieces interacts with remote content in Ruby and we wanted to be able to index that content into one of our Lucene indexes, which is currently only really done in Java.  A quick search for &#8220;Ruby Lucene&#8221; revealed <a href="http://ferret.davebalmain.com/trac">Ferret</a>. How I love Ruby #1.</p>
<p>OK, so I whipped open my trustly console and typed:</p>
<pre style='background-color:#ffffcc;border:1px solid brown;border-left:4px solid brown;border-right:4px solid brown;'>
&gt; gem install ferret
</pre>
<p>Of course, seconds later, ferret was installed.</p>
<p>Now, I created a quick index and search demo:</p>
<pre style='background-color:#ffffcc;border:1px solid brown;border-left:4px solid brown;border-right:4px solid brown;'>
require &apos;net/http&apos;
require &apos;rubygems&apos;
require &apos;ferret&apos;

include Ferret
include Ferret::Document

# create an index in memory, pass path to make a persistent index
#index = Index::Index.new(:path=&gt;&apos;lucene&apos;,:create=&gt;true)
index = Index::Index.new()

# allow command line index/search
site = ARGV[0] || &apos;http://www.cnn.com/&apos;
query = ARGV[1] || &apos;iraq&apos;

puts &quot;Indexing: #{site}&quot;

# fetch the content (note in this simple example, redirections aren&apos;t followed)
url = URI.parse(site)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http|
   http.request(req)
}

# create a new doc index and store some data
doc = Document.new
doc &lt; &lt; Field.new(&apos;uri&apos;,url.to_s,Field::Store::YES,Field::Index::UNTOKENIZED)
doc &lt;&lt; Field.new(&apos;content&apos;,res.body,Field::Store::YES,Field::Index::TOKENIZED)
index &lt;&lt; doc

puts &quot;Index document count: #{index.size}, now searching: #{query}&quot;

# construct a query and now search our index
q = &quot;content:\&quot;#{query}\&quot;&quot;
found = 0
index.search_each(q) do |doc_num,score|
   doc = index[doc_num]
   uri = doc.field(&apos;uri&apos;).data
   found+=1
   puts &quot;Document id: #{doc_num} found with a score of #{score} at #{uri}&quot;
end

if found==0
  puts &apos;Search query did not produce any matches&apos;
else
  puts &quot;Search found #{found} documents&quot;
end
</pre>
<p>Viola! Now, execute:</p>
<pre style='background-color:#ffffcc;border:1px solid brown;border-left:4px solid brown;border-right:4px solid brown;'>
mycomputer:~ jhaynie$ ruby lucene.rb http://news.com.com/ microsoft
Indexing: http://news.com.com/
Index document count: 1, now searching: microsoft
Document id: 0 found with a score of 0.0139269828796387 at http://news.com.com/
Search found 1 documents
</pre>
<p>I love Ruby.</p>
<hr />
<p><b>Technorati Tags:</b> <a href="http://www.technorati.com/tags/lucene" rel="tag">lucene</a>, <a href="http://www.technorati.com/tags/nutch" rel="tag">nutch</a>, <a href="http://www.technorati.com/tags/ruby" rel="tag">ruby</a>, <a href="http://www.technorati.com/tags/ferret" rel="tag">ferret</a></p>
<img src="http://blog.jeffhaynie.us/?ak_action=api_record_view&id=29&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.jeffhaynie.us/why-i-love-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

