Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of script.aculo.us, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Noko Time Tracking and Every Time Zone and write books like Retinafy.me.
   Want me to speak at your conference? Contact me!

ActiveRecord, eager loading, and SQL LIMIT/OFFSET

June 12th, 2005

The eager loading of associations that where first introduced in Rails 0.12.0 suffer from one drawback: It’s not possible to specify :limit or :offset on ActiveRecord’s find method.

Here’s a way to work around this, by using an SQL subquery to select the correct ids:


page = 1
per_page = 25
limit = "LIMIT #{per_page} OFFSET #{(page-1)*per_page}"
stuff = Sometable.find(:all,
  :conditions =>
     "sometable.id IN (SELECT id FROM sometable #{limit})",
  :include => [:someassoc, :someotherassoc])

This code works fine with PostgreSQL, as it is my database of choice. Your mileage with other databases may vary.

JavaScript Drag-and-Drop extension for Prototype hitting beta

June 9th, 2005

My JavaScript Drag-and-Drop extension for Prototype is finally declared beta!

Features:

  • Any element can be declared draggable and/or a drop target
  • Callbacks (onDrop, onHover)
  • Integrated CSS class change to add class drophover if hovering over an possible droptarget
  • Constraints (drag only vertically or horizontally)
  • Sortable lists (UL, OL)
  • Sortable float containers (DIV containing any sort of floating elements)
  • Easy to do sortable lists that also can drag-and-drop to another list
  • Sort order can be serialized to use with Prototype’s Ajax functions
  • Uses the Effect2 library for transparency and snap-back visual effects

There are some minor issues left, but feel free to start using this—please report any bugs or annoyances you hit!

Why I think Apple’s switch to Intel is great

June 7th, 2005

On Monday, Steve Jobs announced Apple will start using Intel microprocessors beginning in 2006.

Some Mac fans have criticised this move and already there are huge amounts of FUD on the net.

What those guys don’t realize is:

  • Your Mac will still look and feel the same. It’s just the processor that gets changed. Not the OS. Not the Hardware/Software integration that Apple is famous for.
  • Wine for Mac/Intel: run any Windows app under Mac OS X/Intel in its own window at native speed. Wine already works fine with x86 FreeBSD. I can’t emphasize this enough.
  • Free to exploit FreeBSD’s ability to run Linux apps ‘out-of-the-box’, including those who include x86 assembly.
  • Most old PowerPC apps will continue to work. All new programs will come as a univseral binary, optimized for both architectures (it’s two binaries in one package actually).

Also, one of the things that very much appeal to me is that Ruby will probably get a VM/just-in-time compiler for 2.0 and from looking at the source I gather it will be optimized towards x86 (first).

JavaScript drag-and-drop for Prototype, early alpha playground

June 3rd, 2005

I’ve put up a working demo and JavaScript code for drag-and-drop with nice usage of the Effects2 package.

To make an element draggable, just use:


  new Draggable('id_of_element');

To mark it as a drop target:


  Droppables.add('id_of_element');

Of course it’s early alpha and lacks refactoring and a polished API, but it works. Tested in Safari in Firefox.

UPDATE: I’ve updated the demo page above, and also added a second demo page on sortable floats and lists

Have fun!

Visual effects website, final beta stages

June 2nd, 2005

I’m proud to annouce that the website for the Visual Effects V2 for Prototype is now available. Check out the demo on the start page!

Mostly, I’ve added a (still not complete) reference and documentation page which also demos the usage of the effects on various HTML elements (they’re not bound to DIVs only, so try to experiment a bit…).

The .js file is now a seperate download, so you can easily integrate it into your apps. It’s side-by-side compatible with the old Effects. Of course you need the Prototype JavaScript library too, to use the new effects package (Ruby on Rails already has this built-in for free!).

Enjoy!