Thursday, May 11, 2006

Neat Safari trick

Did everyone know this one already?

In Safari i have a bunch of my common links in my links bar: GMail, Squib, metrics, Bloglines, Techmeme and so on and they're easy enough to click.

But if I hit Cmd+1 it loads the first link from the links bar in the current window, Cmd+2 the second and so on.

What a neat trick.

11/05/2006 10:50 by Matt Mower | Permalink | comments:
More about:

Information Asymmetry

Euan's got an interesting article about information asymmetry which is the term economists use to describe the imbalance in a transaction where one party has better knowledge than the other.

11/05/2006 12:08 by Matt Mower | Permalink | comments:

Team Amerika have their priorities right

As Jon points out, the top US priority in Iraq is clearly to build the biggest swimming pool and country club in the country.

Who wastes good money ($592 million of it) on water, electricity, and health care for the natives when they dont even make a good workforce!?!

11/05/2006 12:23 by Matt Mower | Permalink | comments:
More about:

Scattershot learning

From Pauls tips comes a 6-step program for learning any difficult subject. It's a somewhat scattershot process and appeals to me because it is, more or less, how I approach the problem myself: fast paced immersion in a broad subset of the topic with regular breaks to give my brain a chance to cool down. I've noticed the breaks get a little longer and more frequent every year ;-)

11/05/2006 15:18 by Matt Mower | Permalink | comments:
More about:

All hail recipe 24!

I am of course talking about Rails Recipe No.24 "Adding Behaviour To Your ActiveRecord Associations". It's magical.

In one of my applications there is a relationship from a Feed to a FeedExpression where the expression tracks the degree to which that feed associates with a concept (actually a value). In Rails that's a pretty typical situation that you handle with has_many, so:

class Feed < ActiveRecord::Base
    has_many :feed_expressions

Now I can refer to:


to process the expressions.

But I also use the concept of a Slice which is allows for the division of the database into time periods like 'today', 'yesterday', 'last week', 'May 2005'. Each feed may actually have many different expressions for the same concept in different slices overlapping. But feed_expressions acts like an Array which gives me a problem. I'm going to get the expressions from every slice.

In that case I'm going to have to manually filter out the expressions from just the slice I am interested in, e.g.:

slice = Slice.find_by_name( 'this_week' ) { |e| e.slice == slice }

That looks pretty ugly and things are only going to get worse when we realise how much overhead filtering all those unwanted slices is going to create on every access.

However Recipe 24 to the rescue... It turns out that feed_expressions is not a real Array but an AssociationProxy masquerading as an Array. And Rails lets you add functionality to those proxies, so:

module BySlices
    def for_slice( slice )
        find( :all, :conditions => ['slice_id = ?',] )

and a slight modification to Feed along the lines of:

class Feed < ActiveRecord::Base
    has_many :feed_expressions, :extend => BySlices

means that I can now use:

feed.feed_expressions.for_slice( Slice.find_by_name( 'this_week' ) )

to get exactly the expressions I want and the filtering happens in SQL before ActiveRecord has to instantiate anything. Neat!

11/05/2006 20:15 by Matt Mower | Permalink | comments:
More about:

Todays coding is brought to you by...

Monaco 10pt without anti-aliasing, respect to hasmanyjosh. I'm still tempted by Fabrizio Schiavi's Pragmata but I don't feel like paying £60 for a font.

11/05/2006 21:49 by Matt Mower | Permalink | comments:
More about: