Archive

Archive for the ‘Development’ Category

Booko updates

February 14th, 2008 1 comment

Well, it’s been a while, but it looks like someone (Tim you’re the only person who looks at cooking books) found a bug. Searching for a book which has an ISBN which is only available via Fishpond and not Amazon, means that you could find the book, but that it didn’t have a title, author or image. Well, I’ve fixed that now.

Also, you can now click on the book cover image to take you to the price lookup page.

Lastly, shipping price can now be more than just a single number – I can define rules for shipping. So, for example ( the only one I’ve found so far ) Fishpond have free shipping for books over $50 – this is now correctly accounted for.

Categories: Booko, Development, Geeky, Ruby Tags:

Testing with Watir

December 11th, 2007 Comments off

Watir ( “Web Application Testing in Ruby” – pronounced water ) is a sweet little system used to automate browsers for the purposes of testing your site. Unfortunately, it’s for IE on Windows. Despite being odd in that most Ruby software is Linux or MacOS it’s also frustrating because I don’t use Windows. Luckily the Tubes have granted us two alternatives, SafariWatir and FireWatir. They achieve browser automation in very different ways.

[More…]

Categories: Development, Geeky, Ruby, testing, Watir Tags:

Booko gets new search engine.

December 5th, 2007 Comments off

I’ve updated Booko to have a default new search engine: fishpond.com.au. Thanks to Tim Evans for finding bugs in it immediately.

Unlike Amazon, Fishpond ( or any Australian bookstore as far as I can tell ) don’t provide an interface for searching their site. Fishpond take the inconvenience one step further by not providing a standard way of finding a book by ISBN. You have to search for the ISBN, then get the Fishpond ID of the book. ( BTW — searching for an ISBN can return multiple results — the same book, but often with different prices. Apparently it’s due to having multiple suppliers for the same book. ) Aside from these annoying bits, Fishpond seems to have a very complete listing. They have an associate program too, so sending traffic to their sites may provide some return.

So, I wrote a searching module for Fishpond. Let me know if you find bugs.

Categories: Booko, Development, Ruby Tags:

Bookie becomes…. Booko

November 12th, 2007 Comments off

The domain name bookie.com.au was taken, so I figured I’d carry on the tradition of naming the product like it was a person whose name was Book…. Booko. So you can now find the cheapest place to buy books at booko.com.au.

Found another bug today when one of the remote shops was misbehaving. The open-uri library was throwing exceptions I wasn’t catching.

The original version in the shop model:

def get_pricing(book)
    eval( self.price_function + "(book)" )
end

Replaced by this version:

def get_pricing(book)
  begin
    eval( self.price_function + "(book)" )
  rescue Errno::ECONNRESET => e
    logger.info(">>> Connection Reset checking #{self.name}")
  rescue OpenURI::HTTPError => e
    logger.info(">>> Connection Reset checking #{self.name}")
  end
end

Seems to work quite well.

Categories: Booko, Development, Geeky, Ruby Tags:

My First Ruby Patch

November 4th, 2007 Comments off

Seems like Sunday is my blog day. Yesterday I submitted a patch for Ruby’s Open-URI module. It’s a tiny, 2 line patch, which could probably be written better, but it works and scratches an itch of mine. I think this is the first patch I’ve submitted to a software project. Hopefully it won’t languish like another patch to the same module.

Categories: Development, Geeky, Ruby Tags:

Threading the Bookie

October 27th, 2007 Comments off

Bookie currently checks prices at 9 shops. When you view a new book or refresh the pricing, it checks each of those shops in sequence. A nice little optimisation is to check the shops in parallel. Threading in rails appears to be pretty straight forward — provided you clean up before the request-response cycle is complete.

Here’s the sequential version:

for shop in Shop.find(:all)
   shop.get_pricing(@book)
 end

And the threaded version:

threads =[]
for shop in Shop.find(:all)
  threads << Thread.new(shop) do |lookup|
    lookup.get_pricing(@book)
  end
end
threads.each{|thr| thr.join}
ActiveRecord::Base.verify_active_connections!()

By default ActiveRecord doesn’t allow multiple threads to access its mysql connection, so you need to allow concurrency by adding the following line to your environment.rb file:

config.active_record.allow_concurrency = true

That last line in the example is used to close database connections which are no longer attached to a thread. You’d have thought that joining the thread would have closed it’s database connection, but there you go. Without this you’ll eventually exhaust your database connections.

Categories: Booko, Development, Geeky, Ruby Tags:

Another Shop for Bookie

October 13th, 2007 Comments off

I’ve updated Bookie by adding another online Australian retailer, Fishpond. They seem to have good pricing on some books, and as a big plus, they have an Affiliate program which I’ve signed up for. I’ll get a cut on any books purchased via Fishpond, Amazon UK & Amazon US.

Adding Fishpond wasn’t as straight forward as the other stores. When searching for an ISBN, you can get multiple results, with different product ids and different prices. (According to their support guys, it’s because they give different product ids to books provided by different suppliers.) Just to make life difficult, the product id needed to generate Associate Links isn’t simply the ISBN. After a little bit of Hpricot work, I figured out how to grab all the data required to select the cheapest book ( if there’s multiple results ) and to generate Associate Links.

Categories: Booko, Development, Fishpond, Ruby Tags:

Database migration

October 11th, 2007 Comments off

Lots of you have been noticing that “Bookie” craps out pretty frequently — turns out it’s due to SQLite3:

ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked: SELECT * FROM books WHERE (books.”isbn10” = ‘978-0596005696’) LIMIT 1):

Session data ( stored in the DB ) was a major culprit, but it looks like more than one concurrent user ( It happens! ) can cause this problem. SQLite’s homepage states that write operations lock the whole table, but since this should only take milliseconds, it shouldn’t be a problem.

I’ve migrated over to MySQL and performance feels much snappier. Maybe that’s just because I was hoping it’d be faster. With luck, bookie should be far more stable now.

Categories: Booko, Development, Geeky, MySQL, Ruby, SQLite, SysAdmin Tags:

Bookie updates

September 24th, 2007 Comments off

Couple of small updates to Bookie, the most interesting of which was to filter the “Recent Searches” list to exclude filthy words. Timo was both the cause of the problem and suggested the solution. Thanks. I think ;-)

Here’s how it used to look:

( Note: It’s searching the book prices as they maintain an “updated at” value )

Price.find(:all).sort_by {|p| p.updated_at }.reverse.collect {|p| p.book}.uniq.compact.slice(0..14)

To filter out books with bad words in their title, I changed it to this:

Price.find(:all).sort_by {|p| p.updated_at }.reverse.collect {|p| p.book}.uniq.delete_if { |b| b.title =~ / shit| piss| cunt/i }.compact.slice(0..14)

Adding the following will delete the Books containing rude words:

.delete_if { |b| b.title =~ / shit| piss| cunt/i }

How sweet is that? You can practically read it like a sentence.

Categories: Booko, Development, Geeky, Ruby Tags:

Clever Image scaling

September 8th, 2007 Comments off

Found some links via Rob & Ben’s Delicious links on clever image scaling techniques. Sounded boring until I watched the video:

;/embed>

If you’re so inclined you can check out the PDF explaining it more technically.

Categories: Development, Geeky Tags: