Active Scaffold for Rails: Many to Many

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

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

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

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

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

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.

Clients for SOLR in Python Java Ruby Rails Drupal JSON C#

May 1st, 2007

Apache Solr really seems to be taking off. Its a web-based wrapper supporting a simple REST protocol. There are clients available in quite a few languages

There are also integrations for many major platforms

No excuses, get your Solr on

Top 5 Skills for Online Media Engineers

April 30th, 2007

I’ve been reviewing a lot of resumes for contract positions at several of the 10 ten online media companies. Its interesting to see the common set of java skill develop. So if you want to be a java developer here are the skills the market is presenting.

  • Struts MVC - the MVC everyone uses, inhouse MVC are dying out replace by open source versions
  • AJAX - everyone has this on their resume, but everyone means form validation without reloads (see Struts above)
  • XML - its the new way to write configuration files
  • JSP - This means understanding the servlet lifecycle and the ability to do gunt work by adapting the web pages for constant updates
  • CSS - everyone knows the basics of CSS which is good, big change from 2 years ago
  • JSTL & Tags - shows up on almost all resumes and everyone has a different level of experience
  • ORM & DAO - anything goes, lots of inhouse code which people are afraid to change
  • Spring - but only as an IOC container for Hibernate and the occasions bean configuration management

To me the interesting thing is the lack of variety. My favorite question so far has been:

Q: “Which XML parser did you use?”
A: “DOM & SAX”
Q: “Oh sorry let me rephrase, which implementation of an XML parser did you use?”
A: “DOM & SAX”

Its always the same! I’m not sure how exactly people are doing XML parsing with out knowing the implementation. I must be missing some super easy parsenow function in java. A quick google shows that even the Sun tutorial lists the XML parsers

What interests me the most is how shallow the tool box is. Take the MVC layer. I expected more variety like Wicket or Struts2. Spring is a good solution, but it doesn’t go far enough (especially in the view and model departments). Additional packages like Tiles and Sitemesh make a big difference.

Spring is a nice and people should use the configuration management and aspect oriented features more.

No one seems to have any knowledge of javascript libraries, which is really a shame. Pick a simple one and learn it. Its easy and lots of fun. I recommend script.aculo.us or JQuery. Exhibit is a standout facited browser written in javascript.

Lastly would be search. Search is a key skill for an online media company. Pick a searching technology and learn it. I suggest Solr, but MySQL full text search is a simple alternative. Egothor is all java and interesting, but I haven’t used it. A nice little project would be to create a simple collection and use scriptaculous to make suggestions as you type.

With all the good stuff out there why doesn’t more of it show up on resumes?

5 Great Things About Rails MVC layer

April 26th, 2007

Everyone can learn something from looking at the Rails MVC framework. Here are some highlights

1) The model is feature rich, making it easy to data manipulation in the model. For example code is often put in the controller to determine if an object is an update or an insert. This code should live in the model; it shouldn’t pollute the controller
2) There are helpers which are only accessible in the view. So little if then statements, popup windows, and javascript generation may be tucked away with out the temptation to manipulate them before the view is rendered. Today there is too much side effect programming where a controller will generate view code.
3) RJS templates provide a mechanism for injecting javascript, while keeping it separate from the view and controller. This rocks, the javascript can live on its own manipulating the page after its rendered and it can read session data.
4) Patterns for manipulating hashes make parameter logic easy. Rails has patterns for removing empty elements from hashes and combining hashes together, then digesting the resulting hash. This gets rid of all the if/then logic to check if a parameter has a value
5) Lots of helpers. Link helpers, URL helpers, image helpers, javascript lib helpers. This ensures that all paths get a little wrapper tag. This is a life saver when developing multi-channel or multi-partner sites

Patent Claims and Marshall TX

April 24th, 2007

Techdirt reported Patent Trolls love Marshall TX. Which was also reported in a recent Slashdot article

People are often critical of patents sighting examples of big companies picking on little ones. Honestly I see it the other way around. Small companies get acquired while large companies get picked on by small companies with nothing to loose. I would rather have the current system for intellectual property then no system at all.