We are (UserVoice that is) about to release a new api that is based on a combination of 2-legged and 3-legged oauth. While checking the functional tests that had been written I noticed that they contained a lot of mocked methods, which while not a bad thing in itself, in this case meant a lot of functionality (specifically authorization) was not being checked.

So, I had a poke about in the gem (Oauth (0.3.6)) and wrote a couple of helper methods to allow for testing oauth based requests without mocking too much out, or in the case of integration tests, mocking nothing.

Continue reading »

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).

Continue reading »

Aug 202008

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.

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.

May 292008

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

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…….