<?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>Scott Rutherford &#187; Home</title>
	<atom:link href="http://blog.thatsuseful.com/category/home/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thatsuseful.com</link>
	<description>Life on and off the Rails</description>
	<lastBuildDate>Wed, 21 Jul 2010 16:35:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Exclude Records With UltraSphinx</title>
		<link>http://blog.thatsuseful.com/2008/08/20/exclude-records-with-ultrasphinx/</link>
		<comments>http://blog.thatsuseful.com/2008/08/20/exclude-records-with-ultrasphinx/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 17:47:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/08/20/exclude-records-with-ultrasphinx</guid>
		<description><![CDATA[So been using Sphinx with the UltraSphinx plugin and I came across the requirement to use filters to reject records. Unfortunately in the plugin the filters are hardwired to submit the &#8216;exclude&#8217; parameter as &#8216;false&#8217; i.e include. Time for a quick hack I think&#8230;&#8230;. Very easy to fix, just open up the &#8216;internals.rb&#8217; file in [...]]]></description>
			<content:encoded><![CDATA[<p>So been using <a href="http://www.sphinxsearch.com/">Sphinx</a> with the <a href="http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/files/README.html">UltraSphinx</a> plugin and I came across the requirement to use filters to reject records. Unfortunately in the plugin the filters are hardwired to submit the &#8216;exclude&#8217; parameter as &#8216;false&#8217; i.e include. Time for a quick hack I think&#8230;&#8230;.</p>
<p>Very easy to fix, just open up the &#8216;internals.rb&#8217; file in the UltraSphinx plugin or include the gem using &#8216;rake gems:unpack <span class="caps">GEM</span>=ultrasphinx&#8217; (need to have config.gem &#8220;ultrasphinx&#8221; set in envrinoment.rb) and then find that file.</p>
<p>Ok, so found the file? On line 97 is this loop:</p>
<pre>
Array(opts['filters']).each do |field, value|
  ....
 begin
     case value
     when Integer, Float, BigDecimal, NilClass, Array
       # XXX Hack to force floats to be floats
       value = value.to_f if type == 'float'
       # Just bomb the filter in there
       request.filters &lt;&lt; Riddle::Client::Filter.new(field, Array(value), false)
     when Range
     ....
end
</pre>
<p>The &#8216;Riddle::Client::Filter.new(field, Array(value), false)&#8217; call is the one we need to change (the &#8216;false&#8217; is the exclude param).</p>
<p>            <span id="more-9719"></span></p>
<p>So what I did was to change that loop to:</p>
<pre>
        Array(opts['filters']).each do |field, value|

          field = field.to_s
          type = Fields.instance.types[field]

          # Special derived attribute
          if field == 'distance' and options['location']
            field, type = '@geodist', 'float'
          end

          raise UsageError, "field #{field.inspect} is invalid" unless type

# ADDED FROM HERE
          exclude = false
          # check for exclude flag
          if value.is_a? Hash
            exclude = value[:exclude]
            value = value[:value]
          end
# TO HERE

          begin
            case value
              when Integer, Float, BigDecimal, NilClass, Array
                # XXX Hack to force floats to be floats
                value = value.to_f if type == 'float'
                # Just bomb the filter in there

# CHANGE CALL HERE TO PASS THE exclude PARAMETER
                request.filters &lt;&lt; Riddle::Client::Filter.new(field, Array(value), exclude)
              when Range
                # Make sure ranges point in the right direction
                min, max = [value.begin, value.end].map {|x| x._to_numeric }
                raise NoMethodError unless min &lt;=&gt; max and max &lt;=&gt; min
                min, max = max, min if min &gt; max
                # XXX Hack to force floats to be floats
                min, max = min.to_f, max.to_f if type == 'float'

# CHANGE CALL HERE TO PASS THE exclude PARAMETER
                request.filters &lt;&lt; Riddle::Client::Filter.new(field, min..max, exclude)
              when String
                # XXX Hack to move text filters into the query
                opts['parsed_query'] &lt;&lt; " @#{field} #{value}"
              else
                raise NoMethodError
            end
          rescue NoMethodError =&gt; e
            raise UsageError, "Filter value #{value.inspect} for field #{field.inspect} is invalid"
          end
        end
</pre>
<p>Now I can do searches like</p>
<pre>
    @search = Ultrasphinx::Search.new(
      :query =&gt; params[:q],
      :page =&gt; page,
      :class_names =&gt; ["User"],
      :filters =&gt; {:id =&gt; {:value =&gt; current_user.id, :exclude =&gt; true}}
    )
</pre>
<p>And the current_user gets excluded, cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/08/20/exclude-records-with-ultrasphinx/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hop Toad</title>
		<link>http://blog.thatsuseful.com/2008/08/20/hoptoad/</link>
		<comments>http://blog.thatsuseful.com/2008/08/20/hoptoad/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 15:49:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/08/20/hoptoad</guid>
		<description><![CDATA[I&#8217;ve been using the Hop Toad web app for a while now to collect errors from my Rails apps and its been working out great. It drops in very simply and replaces the Exception Notifier plugin I was using. Big advantages are the archive of errors and the ability to mark them as dealt with. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the <a href="http://www.hoptoadapp.com">Hop Toad</a> web app for a while now to collect errors from my Rails apps and its been working out great. It drops in very simply and replaces the Exception Notifier plugin I was using.</p>
<p>Big advantages are the archive of errors and the ability to mark them as dealt with. Of course I could do that with email folders and the like, but I&#8217;m lazy and this appears to do it all. Oh and its free!!!</p>
<p><img src="http://blog.caronsoftware.com/assets/2008/8/19/Picture_1.png" width="500px"></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/08/20/hoptoad/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux &#8211; Just say no&#8230;&#8230;.</title>
		<link>http://blog.thatsuseful.com/2008/08/01/linux-just-say-no/</link>
		<comments>http://blog.thatsuseful.com/2008/08/01/linux-just-say-no/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 01:13:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/08/01/linux-just-say-no</guid>
		<description><![CDATA[More from the excellent xkcd]]></description>
			<content:encoded><![CDATA[<p>More from the excellent <a href="http://www.xkcd.com">xkcd</a></p>
<p><br/><br />
<br/><br />
<img src="http://imgs.xkcd.com/comics/cautionary.png" width="510"></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/08/01/linux-just-say-no/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mashup of the Day &#8211; Tweetlists</title>
		<link>http://blog.thatsuseful.com/2008/07/30/mashup-of-the-day-tweetlists/</link>
		<comments>http://blog.thatsuseful.com/2008/07/30/mashup-of-the-day-tweetlists/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 15:42:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/07/30/mashup-of-the-day-tweetlists</guid>
		<description><![CDATA[So, I got a great email about an hour ago: To the creative genius[es] behind TweetLists, We&#8217;d like to congratulate you on being selected as our MASHUP OF THE DAY at MashupAwards.com for July 30, 2008. So, not all that familiar with The Mashup Awards, but others clearly are as the resulting traffic killed the [...]]]></description>
			<content:encoded><![CDATA[<p>So, I got a great email about an hour ago:</p>
<p>To the creative genius[es] behind TweetLists,</p>
<p>We&#8217;d like to congratulate you on being selected as our MASHUP OF THE DAY at MashupAwards.com for July 30, 2008.</p>
<p><a href="http://mashupawards.com/tweetlists"><img src="http://mashupawards.com/img/badges/motd.gif" alt="Mashup of the Day" border="0" /></a></p>
<p><br/></p>
<p>So, not all that familiar with <a href="http://mashupawards.com">The Mashup Awards</a>, but others clearly are as the resulting traffic killed the site (not that that would of been hard)! I would like to say thank you to them for the award and also take this opportunity to thank my manager, parents, producer, jesus, god, twitter!, Tim Berners Lee, Matz&#8230;&#8230;..</p>
<p>Right then off to &#8216;enjoy basking in the glow of my well deserved recognition&#8217; as suggested by &#8216;The Mashup Awards Judging Panel&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/07/30/mashup-of-the-day-tweetlists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing Rails log files with JSON</title>
		<link>http://blog.thatsuseful.com/2008/07/28/parsing-rails-log-files-with-json/</link>
		<comments>http://blog.thatsuseful.com/2008/07/28/parsing-rails-log-files-with-json/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 12:38:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/07/28/parsing-rails-log-files-with-json</guid>
		<description><![CDATA[So I needed to parse the log files for SlimTimer this weekend to correct a data loss issue due to a small issue with implementing https for subscribers. The issue required looking for requests that had returned something other than &#8220;200 OK&#8221; collecting the parameters and entering any data that had got lost. After a [...]]]></description>
			<content:encoded><![CDATA[<p>So I needed to parse the log files for <a href="http://slimtimer.com">SlimTimer</a> this weekend to correct a data loss issue due to a small issue with implementing https for subscribers. The issue required looking for requests that had returned something other than &#8220;200 OK&#8221; collecting the parameters and entering any data that had got lost. After a bit of messing around it occured to me the the format of the parameters string in the Rail&#8217;s logs was not a million miles from the <span class="caps">JSON</span> format, so I came up with this to turn the string into a useable hash:</p>
<pre>
params =~ /.*: Parameters: (\{.*\})$/
str_hash = JSON.parse(params.gsub('=&gt;',':'))
</pre>
<p>This provides a hash of the parameters used in the request. Of course the keys here are strings so to convert to symbols we can then use:</p>
<pre>
def create_symbol_hash(input)
  ret = input
  if input.is_a? Hash
    ret = {}
    input.each do |k, v|
      ret[k.to_sym] = create_symbol_hash(v)
    end
    ret
  else
    ret
  end
end
</pre>
<p>and simply pass in the output from the <span class="caps">JSON</span> library. Seemed quite neat to me anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/07/28/parsing-rails-log-files-with-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How not to return your hire car!!!</title>
		<link>http://blog.thatsuseful.com/2008/07/18/how-not-to-return-your-hire-car/</link>
		<comments>http://blog.thatsuseful.com/2008/07/18/how-not-to-return-your-hire-car/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 08:22:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/07/18/how-not-to-return-your-hire-car</guid>
		<description><![CDATA[So just got back from a great 2 weeks in California, went to Foo camp, Social Media Camp, Mashable and a couple of other meetups &#8211; all excellent. One slight hiccup with the hire car&#8230;&#8230;.. I claim it was the taxi&#8217;s fault (of course), although its a bit of a blur to be honest. On [...]]]></description>
			<content:encoded><![CDATA[<p>So just got back from a great 2 weeks in California, went to Foo camp, Social Media Camp, Mashable and a couple of other meetups &#8211; all excellent. One slight hiccup with the hire car&#8230;&#8230;.. I claim it was the taxi&#8217;s fault (of course), although its a bit of a blur to be honest.</p>
<p><img src="http://blog.caronsoftware.com/assets/2008/7/18/crash.jpg" alt="" /></p>
<p>On the up side I can highly recommend Enterprise (and taking out the full coverage), they were very helpful and polite. Even offered me a new car &#8211; which would of seemed like a better idea if I could move properly!! At least no one was badly hurt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/07/18/how-not-to-return-your-hire-car/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TweetLists Comedy</title>
		<link>http://blog.thatsuseful.com/2008/06/22/tweetlists-comedy/</link>
		<comments>http://blog.thatsuseful.com/2008/06/22/tweetlists-comedy/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 14:52:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/06/22/tweetlists-comedy</guid>
		<description><![CDATA[So, couple of pretty funny links creeping up the popular chart over at TweetLists 1) Yahoo Resigner (by Mat Honan) 2) Instant Rim Shot (by Scott Carver)]]></description>
			<content:encoded><![CDATA[<p>So, couple of pretty funny links creeping up the popular chart over at <a href="http://www.tweetlists.com">TweetLists</a></p>
<p>1) <a href="http://yahoorezinr.com/">Yahoo Resigner</a> (by Mat Honan)</p>
<p>2) <a href="http://www.instantrimshot.com/">Instant Rim Shot</a> (by <a href="http://scottcarver.info/">Scott Carver</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/06/22/tweetlists-comedy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goosh</title>
		<link>http://blog.thatsuseful.com/2008/06/21/goosh/</link>
		<comments>http://blog.thatsuseful.com/2008/06/21/goosh/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 22:10:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/06/21/goosh</guid>
		<description><![CDATA[One of the top links that came from Tweetlists over the past couple of weeks is Goosh, an online google shell. Its great, well worth checking out. I really like the &#8220;translate&#8221; mode.]]></description>
			<content:encoded><![CDATA[<p>One of the top links that came from <a href="http://www.tweetlists.com">Tweetlists</a> over the past couple of weeks is <a href="http://www.goosh.org">Goosh</a>, an online google shell. Its great, well worth checking out. I really like the &#8220;translate&#8221; mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/06/21/goosh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FCKeditor Plugin 0.5.1 Released</title>
		<link>http://blog.thatsuseful.com/2008/06/21/fckeditor-plugin-0-5-1-released/</link>
		<comments>http://blog.thatsuseful.com/2008/06/21/fckeditor-plugin-0-5-1-released/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 22:04:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[FCKeditor]]></category>
		<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/06/21/fckeditor-plugin-0-5-1-released</guid>
		<description><![CDATA[Thanks to George Chatzigeorgiou there is now a version of the FCKeditor plugin that works with Rails 2.1. I have put the packages on Ruby Forge and updated the repository. If you are interested as to what the issue was check out George&#8217;s comments on the previous post.]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.fortytwo.gr/">George Chatzigeorgiou</a> there is now a version of the FCKeditor plugin that works with Rails 2.1. I have put the packages on Ruby Forge and updated the repository. If you are interested as to what the issue was check out George&#8217;s comments on the previous <a href="http://blog.caronsoftware.com/2008/6/4/fckeditor-plugin-0-5-0">post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/06/21/fckeditor-plugin-0-5-1-released/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Wordle</title>
		<link>http://blog.thatsuseful.com/2008/06/19/wordle/</link>
		<comments>http://blog.thatsuseful.com/2008/06/19/wordle/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 15:55:00 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Home]]></category>

		<guid isPermaLink="false">http://blog.caronsoftware.com/2008/06/19/wordle</guid>
		<description><![CDATA[My Delicious tag cloud from Wordle very cool]]></description>
			<content:encoded><![CDATA[<p>My Delicious tag cloud from <a href="http://www.wordle.net">Wordle</a> very cool</p>
<p><br/><br />
<img src="http://blog.caronsoftware.com/assets/2008/6/19/Picture_1.png" width="500px"></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thatsuseful.com/2008/06/19/wordle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
