Scott Rutherford

Life on and off the Rails

 

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 ‘exclude’ parameter as ‘false’ i.e include. Time for a quick hack I think…....

Very easy to fix, just open up the ‘internals.rb’ file in the UltraSphinx plugin or include the gem using ‘rake gems:unpack GEM=ultrasphinx’ (need to have config.gem “ultrasphinx” set in envrinoment.rb) and then find that file.

Ok, so found the file? On line 97 is this loop:

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 << Riddle::Client::Filter.new(field, Array(value), false)
     when Range
     ....
end

The ‘Riddle::Client::Filter.new(field, Array(value), false)’ call is the one we need to change (the ‘false’ is the exclude param).

Read the rest of this entry

Hop Toad

August 20th, 2008

I'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. Of course I could do that with email folders and the like, but I'm lazy and this appears to do it all. Oh and its free!!!

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 “200 OK” 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’s logs was not a million miles from the JSON format, so I came up with this to turn the string into a useable hash:

params =~ /.*: Parameters: (\{.*\})$/
str_hash = JSON.parse(params.gsub('=>',':'))

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:

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

and simply pass in the output from the JSON library. Seemed quite neat to me anyway.

Twitter API: User IDs

May 29th, 2008

So, next lesson from TweetLists: the user id given in the xml from the public timeline is not a unique identifier. The screen name is the only way to identify a user. I ended up with 17 different ids for one user!!! Hence, gave up fixed it and dropped the database – too much effort to fix when its only been running for 12 hours.

TweetLists

May 29th, 2008

I released TweetLists last night, well actually this morning (about 3am), the idea being to try and capture a little of the zeitgeist on Twitter by aggregating the links people are talking about. At the moment there are 3 lists, the live feed, a popular feed (the links ordered by the number of times they appeared) and one I have chosen to call Twitterati (quite proud of that!) which is the links ordered by the number of followers people have.

At the moment there is no time aspect to the Twitterati or Popular lists (not relevant on the live one) but I guess I will make them for the last 7 days?

Lesson one form this has been: don’t try and be clever with your scheduling – cron just works. I tried to use the Rufus Scheduler and it had stopped running by the time I got up again this morning.

Anyhoo, I’ve found it to be fun and interesting so far, any ideas for other lists?

Found a bit of a gotcha when building a form recently using form_for, fields_for and the check_box helper. Because Rails adds a hidden field for each checkbox and fields_for for new objects produces ids like ‘users_invites__selected’, if you try to generate multiple new objects in the same form things can get a little confused. I found that when selecting a single checkbox things worked ok, but when selecting multiple the values would bleed across each other. I haven’t investigated this very far just switched to check_box_tag instead (no hidden field).

Actually just found this post mentioning that the checkboxes might be broken in Rails 2.0.2. Which could be the cause of the issue.

I added the UserVoice feedback system to the FCKeditor demo page today. So any bugs or ideas for the plugin can be stored in a central place. If you have found any issues recently (and can be bothered) it would be great if you could put them up there. I will copy over any ones I find going back over the comments. Ta.

I think this is great, very useful and gets YSlow off your back…...

Asset Packager

Key Features

  • Merges and compresses javascript and css when running in production.
  • Uses uncompressed originals when running in development.
  • Handles caching correctly. (No querystring parameters – filename timestamps)
  • Uses subversion revision numbers instead of timestamps if within a subversion controlled directory.
  • Guarantees new version will get downloaded the next time you deploy.

Thank you Scott Becker

Recommendbox Live!!!

April 1st, 2008

After a couple of months of intense coding Robert Loch and I launched RecommendBox yesterday. Its a site based around requesting and giving recommendations to your friends. There were a few immediate issues!! IE 6 is not yet fully supported, but on the whole it went ok. Now, sleep…....

FCKeditor Plugin 0.4.3 Released

February 6th, 2008

There is a new version of the Fckeditor plugin available. It is a very minor bug fix release to deal with the improper constantizing of model names as reported by a couple of people. Oh and I also checked it works with Rails 2. The demo is running on 2.0.2.

The plugin is available from Ruby Forge or by doing this:

ruby script/plugin install svn://rubyforge.org//var/svn/fckeditorp/trunk/fckeditor

If you have seen this sort of thing:

ActionView::TemplateError: Expected image.rb to define Image

or this:

SystemExit (exit):
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:70:in `exit'
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:70:in `rootdir'
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:84:in `directory'
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:258:in `so_name'
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:294:in `load_cache'
    /usr/local/lib/ruby/gems/1.8/gems/RubyInline-3.6.5/lib/inline.rb:678:in `inline'
    /usr/local/lib/ruby/gems/1.8/gems/image_science-1.1.3/lib/image_science.rb:84

in your log files when using ImageScience you may well of been a bit confused and frustrated – I was.

Read the rest of this entry

Kropper

December 20th, 2007

I was looking for a neat way to crop images last night and had originally planned to use the excellent jsCropper library from Dave Spurr, which I have used on projects before. When, during a bit of googling about I came across Kropper from Jonathon Wolke. It takes a slightly different approach to Cropper with the crop area staying put and the image moving under the crop area, but also includes a neat zooming feature and some pretty slick design. Another plus, from a Rails perspective, is that the code comes in an example Rails app!!! Makes it very easy to integrate.

Yabb.com Finally In Beta

December 4th, 2007

Its taken a long time (well about a year) and a lot of messing about with Skype, but the first site from the Cominded stable is open for invitations to join the beta. Yabb is a social utility based on conversation, “talk more, type less” being the motto. So go along and sign up, I look forward to chatting with you online.

It has to be said integrating with the Skype API is an experience, and not usually a particularly consistent one!! Anyway now we are out of stealth mode I guess it ok to start sharing some of the issues we came up against and how we solved them.

Oh and Nothing is doing quite well, 627 installs in 27 countries in 8 days. I know its not exactly explosive growth. But, its not in the directory and lets face it it does actually do nothing.

Rails 2 and the iPhone

December 4th, 2007

Ben Smith who I work with over at Cominded has put up a good article on getting your site to work with the iPhone. Definitely worth a read (as is much of his blog), now all I need to do is find a way to get one – I knew I shouldn’t of been tempted by the N95 (its spent more time being fixed than anything else)!!!!

I have just completed (well apart from moving any assets over) the switch from Typo to Mephisto. It was fairly painless. There was one :dependent declaration that needed fixing in the converter code and other than that pretty much everything I needed to know was in these two posts.

How I converted Type to Mephisto

Finally switched to Mephisto

The solution given for fixing your routes found in the later of these I found also needed this line:

Mephisto::Routing.redirect '/articles' => '/'

to get all my permalinks to work. The result on my memory usage is pretty dramatic and hopefully I won’t get as much spam…..

This blog used the Shay theme as a base and is powered by Mephisto