Facebook Notes: Everyone sees something different

One of the interesting things about Facebook is that, of the interesting pages on Facebook, everyone sees a different version of that page.

Search is clearly filtered to show stuff that is more relevant to you first. Your ‘facebook’ page has stuff filtered out depending on what Facebook thinks is interesting to you (with input from the tiny ‘Preferences’ settings that I expect no-one actually changes)

Search is the tricky one. If someone tells you to type something into Google, you’ll see the same results as them. On Facebook, probably not! This could give Facebook great opportunities for advertising, but their search actually sucks! e.g. I searched for an app the other day and couldn’t find it – I was using the singular form of the name when I should have used the plural. Now I have that app installed, it shows up higher in the search, but now it’s too late.

Posted by Tom Sat, 08 Mar 2008 09:24:45 GMT


My latest Rails project is live

I’ve been working on a project for a while. The site has been live for a month or so, and seems to be stable. If you visit my site to read the posts, you may have noticed the top section of the left sidebar has been showing a widget from my new site VideoSlush:http://videoslush.com

VideoSlush:http://videoslush.com is a trading game for YouTube videos. You find cool videos that you think may get a lot of views in a short amount of time. You ‘buy’ the video and also take a guess at how many views it may get by noon the next day to earn a bonus. Then you see how your video does over time, using the graphs to see when the price peaks and then selling.

Sign-up is free and open, so check it out.

Posted by Tom Sun, 23 Dec 2007 06:29:02 GMT


Making Rails fragment caching usable

Caching is a real pain to get right. Actually, the caching part is quite easy with Rails, its the expiry that causes the trouble. All the simple cases are easy! Its when you have a page with various pieces of data, with different expiry conditions that the trouble starts.

I’ve written some code to use versioning in my fragment cache that is working for my most recent project. This technique relies on using Memcache to work correctly. I’ve been thinking about packaging this up as a plugin and releasing it. Luckily, I never got around to it.

Today, I read this post on how to do better caching. This plugin has documentation and tests, and is easier to configure than mine.

Go check it out.

http://blog.evanweaver.com/articles/2007/12/13/better-rails-caching/

Posted by Tom Fri, 14 Dec 2007 06:47:40 GMT


Rails validates_uniqueness_of is completely broken

If you are using the Rails implementation of validates_uniqueness_of in your model to ensure duplicate data doesn’t get into your database, your application is broken. If you don’t use the database to ensure uniqueness with a key, then your app will fail at some point in the future. Probably just when you start getting some decent traffic and would like the app to not fail.

How do I know this? It happened to me this last weekend.

In checking this out, I find that Michael Koziarski of the Rails core team recently wrote

validates_uniqueness_of gives a nice error message, and does an ok job at guaranteeing uniqueness. Validates uniqueness of + a unique index does both.

In my app, does a nice job isn’t really good enough when it comes to uniqueness.

Michael has also posted that, hey, if you don’t like it, fix it and submit a patch, which is a great idea, but for this case is a really hard problem to solve for the general case across many databases.

I didn’t find a lot of specific fixes with code that I liked, so here’s how I fixed it in my app.

For my case, I already had a do some stuff and save the model method. In this method, I added some code (I stripped out my app specific code in the example).

  DUPLICATE_ERROR_MESSAGES = [
      "Duplicate entry"
  ]

  def save_new
    begin
      save    
    rescue ActiveRecord::StatementInvalid => error
      if DUPLICATE_ERROR_MESSAGES.any? { |msg| error.message =~ /#{Regexp.escape(msg)}/ }
        logger.info "Duplicate Entry exception from DB"
        errors.add_to_base('Duplicate item not allow')
        return false
      else
        raise
      end
    end
  end

I also added a unique key to the table to ensure the MySQL database throws the exception that the above code relies on.

I still keep the validates_uniqueness_of call, as this does give a more specific error message, but now I don’t rely on it to enforce uniqueness.

Shh, don’t tell DHH that I’m putting integrity checks into my database.

Posted by Tom Tue, 11 Dec 2007 04:59:43 GMT


Postfix stops working suddenly

Today I had a strange problem. Mail suddenly stopped being processed by my Postfix configuration that’s been running for months. The logs looked fine up until 4:06pm, and then nothing!

Restarting Postfix didn’t make it work either. Google failed to come to my rescue too.

I eventually started thinking about the logging aspect. My Syslog stopped at the same time. Was I out of disk space? Nope. What else?

Eventually, I restarted the syslog daemon (sysklogd on Ubuntu) and it started working again.

I guess syslog needs to be working correctly for Postfix to do anything.

Posted by Tom Tue, 06 Nov 2007 07:53:44 GMT


Google thinks I'm evil

Some of my sites, including this one, are hosted at Dreamhost. At the beginning of June, Dreamhost had a security lapse (that they have still not explained fully) that allowed someone access to many accounts. It looks like an automated process went looking for index.html and index.cgi files and swapped them out for some Bad Code. Luckily, this attack skipped my Rails sites.

Since my blog was working Ok when I checked, I thought I was in good shape, but it turns out that the http://craz8.com part of my site had been compromised. A few weeks later, Google noticed this problem and has marked everything on the craz8.com domain, including sub-domains, as being harmful.

I think I’ve made all the required changes to clean up the broken hosts, but it will probably take StopBadware.org and Google some time to process these changes and unlock me from the world of the undead.

Posted by Tom Thu, 12 Jul 2007 17:59:22 GMT


2 Best Firefox plugins for Rails developers

Usually these lists are 10 best, but really, for Rails developers, there are only two plugins you really need.

DevBoi plugin, with Rails addon

The DevBoi plugin adds a sidebar with documentation lookup for HTML, CSS, DOM and Javascript.

The Rails addon pack gives you Rails and Ruby documentation too. Ctrl-F9 (on Windows) brings up the sidebar.

I can’t work without this plugin.

Install it from here: http://www.martincohen.info/products/devboi/

Web Developer plugin

This plugin allows you to view all sorts of useful information about the current page. When you’re building pages, and nothing seems to be working, the information this plugin provides is invaluable.

Get the Web Developer plugin here: https://addons.mozilla.org/firefox/60/

Posted by Tom Mon, 05 Feb 2007 05:38:38 GMT


Why is my code in a loop?

Today, I wrote some code that looked a little bit like this:

class Model < ActiveRecord::Base

  ...

  def update
    RAILS_DEFAULT_LOGGER.info "Update Called"
    # Read some data from wherever
    # Set some properties on my object
    save!
  end
end

Imagine my surprise when my log output was a long stream of Update Called lines.

What happened here is that save is implemented as a call to update when the object already exists.

Inadvertently picking a method name that is the same as an important Rails method can be hard to track down. I already had my logging in there, so I wasn’t left wondering why the call never completed.

Posted by Tom Thu, 25 Jan 2007 04:09:42 GMT


Start the weekend with a boat rescue!

Lisa and I just had a ‘Joe and Petunia’ moment.

I noticed a small boat in trouble just off shore from the Kirkland marina today. The boat just stopped and they started waving an orange flag – they also started bailing. Lisa called 911.

Before the rescue boat arrived, the boat in trouble drifted into the docks at the North end of Marina Park and the two gentlemen rescued themselves.

Living on the lake provides so much entertainment.

Posted by Tom Sat, 20 Jan 2007 21:29:47 GMT