Archive for May, 2007

Active Scaffold for Rails: Many to Many

Monday, May 21st, 2007

Yesterday I downloaded Active Scaffold and played around with it. I have to say its pretty nice and really easy to use.

  1. script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold
  2. create three tables items, baskets, and baskets_items (see SQL below)
  3. create a simple layout with two includes

    < %= javascript_include_tag :defaults %>
    < %= active_scaffold_includes %>
  4. create two models examples below SQL, Item and Basket and add has_and_belongs_to_many :items to Basket
  5. create two controllers one for Item and one for Basket and make sure each has the keyword active_scaffold
  6. navigate to items or baskets and enjoy!
SQL for tables


DROP TABLE IF EXISTS baskets;

CREATE TABLE baskets (
id INT(11) NOT NULL AUTO_INCREMENT,
basket_name VARCHAR(40) NOT NULL COMMENT 'name of the basket, should match event',
PRIMARY KEY (id)
)
ENGINE=INNODB;

DROP TABLE IF EXISTS items;

CREATE TABLE items (
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(40) NOT NULL COMMENT 'name of the item',
qualities VARCHAR(40) NOT NULL COMMENT 'comma seperated list of qualities we may infer about the person consuming the item',
PRIMARY KEY (id)
)
ENGINE=INNODB;

DROP TABLE IF EXISTS baskets_items;

CREATE TABLE baskets_items (
basket_id INT(11) NOT NULL,
item_id INT(11) NOT NULL,
PRIMARY KEY (basket_id,item_id)
)
ENGINE=INNODB;

Many-to-Many models


class Basket < ActiveRecord::Base
has_and_belongs_to_many :items
end

class Item < ActiveRecord::Base
end

Controllers


class BasketsController < ApplicationController

layout "active_scaffold"
active_scaffold :basket

end

class ItemsController < ApplicationController

layout "active_scaffold"
active_scaffold :items

end

Installing Pidgin 2.0 on Debian Etch

Thursday, May 10th, 2007

Wow, lots of libraries to install if you want to build Pidgin from src on Debain Etch. I can’t even name them all.

  • Get the Pidgin source.
  • Unpack tar xjf pidgin*.bz2
  • run ./configure
  • keep installing development libs and perl XML::Parser (which requires libexpat-dev) until config stops complaining
  • make
  • sudo make install

You may also pick up the experimental debs here. For me the experimental debs had too many unfamiliar dependencies.

Peer code review tools for java

Tuesday, May 8th, 2007

Everyone says code reviews are great, but I’ve always had trouble getting them off the ground. I spend some time looking for tools to assist in peer reviews. Usually I’m the first to say buy it, but with commercial tools costing up to $400 a seat who want to buy a tool to manage a process which may not even exist.

Tracs has a plug-in to do peer code reviews. Thats pretty cool, as Tracs is widely used.

I would love to get my hands on Mondorian but thats not going to happy with all that proprietary google code.

Code striker looks like a decent peer review tool. Its very active with the last release in Mach 2007.

Finally in a different category is Quilt a code coverage tool. It says optimized to work with ant and Maven and jUnit so I’ll have to check it out.

update: I found one more code coverage tool Emma . It is supposed to be very easy to use and set up.

Scalling with YouTube’s oracle algorithm for speeding up writes

Friday, May 4th, 2007

Paul Tuckfield from YouTube presented at the mySQL conference. He devised the oracle algorithm to speed up MySQL replication.

The short of it is pretty simple. Scan the replication log then create/execute SQL queries to ensure to-be-altered data is already in memory on the slave.

MySQL One Large Table is better than many small tables

Friday, May 4th, 2007

With MySQL one large table is almost always faster then many small tables. This is attributed to MySQL’s exclusive use of a nested join algorithm. Check out Peter Zaitsev comment at the end of the page.

The nested join algorithm has to loop through the inner and outer elements of the loop to find matches. The more joins, the more nested loops. So one large table is almost always better.

Of course, a huge de-normalized table has some problems, namely data duplication. If you have a list of people with addresses, changing something simple like a zip code or a city name is a pain. You have to scan the whole table changing multiple rows. A db in 3rd normal form would enable a zip code or city update of just one row.

Faceted Searching With Solr

Thursday, May 3rd, 2007

Chris Hostetter presented this presentation at Apache Con 2006. Faceted searching with Solr. Its pretty good and well worth the read. Solr has some special caching mechanisms to deal with facetes. I know one of the first implementations of Solr at CNET was to support facted search. So you wouldn’t be wrong in saying Solr was built to do faceted search.