Ruby on Rails date_finder plugin

Posted by Daniel Butler Wed, 20 Sep 2006 13:07:00 GMT

Jonathan Viney of New Zealand has announced his date_finder plugin for Ruby on Rails. The plugin allows the following types of actions:

  • To find the next five Mondays and Fridays:

DateFinderBase.weekly.day(:monday).day(:friday).find(:max => 5)

  • To find the 10th of the month for the next five months:

DateFinderBase.monthly.day_number(10).find(:max => 5)

  • To find the last Thursday in September for the next 3 years

DateFinderBase.yearly.month (:september).day(:thursday).day_occurrence(:last).find(:max => 3)

  • To find the next 5 Wednesdays on a fortnightly basis (skips every second week):

DateFinderBase.weekly(2).day(:wednesday).find(:max => 5)

To install, execute script/plugin install http://svn.viney.net.nz/things/rails/plugins/date_finder.

Thanks, Jonathan.

Date Finder @ Ruby Plugins Directory

Posted in  | Tags  | no comments

A Manifesto for Tags

Posted by Daniel Butler Tue, 19 Sep 2006 23:05:00 GMT

Someone from Manchester, England's vagueware.com--Innovation in Software blog (presumably Paul Robinson) wrote an excellent article describing the modern need for "tags" for classifying information in the digital realm. Here's the problem: it's hard to find stuff that you don't know that much about ... yet. In the classic Dewey Decimal System method, you go find one book about something you're interested in, and viola, there's more right there. But with information, how to you create a "distance function" that allows information to be found near other information that is similar. He conveys the scope of the problem:

It gets worse when you realise that you could be dealing with not just a few thousand items in a library, but the entire sum of human knowledge. Every document, photo, film, sound recording, computer program and physical object. Imagine trying to classify and then later find everything related to piegeons, cooking and hunting in that lot.

So instead of taxonomies, hierarchies, ontologies, we have something that is quite easy and powerful: tagging. Paul continues:

The purpose of tagging is to replace taxonomies. We want to do this for lots of reasons, including:

  • We don’t want to have to worry about where we put stuff into the system. We want to mark the item up without having to spend an hour - or decade - debating which part of the taxonomy it belongs in.
  • We want to know it can be easily retrieved by those who may be interested in finding it at a later date.
  • We want to be able to easily find ‘neighbours’ even if they belong in a traditionally unrelated taxonomy.

Overall, a well-written manifesto which you should read if you have any question about how tags can and will help you in your information-filled future.

A Manifesto for Tags

Posted in  | Tags , , , , ,  | no comments

Leonard Richardson on Ruby Libraries

Posted by Daniel Butler Mon, 11 Sep 2006 22:53:00 GMT

Pat Eyler has a short interview with the author of Ruby Cookbook, Leonard Richardson, who touches on the ability of great Ruby libraries which change the way you think about the problems of programming.

Leonard: I'm looking forward to more libraries that use Ruby's idioms to radically simplify entire domains. I think this is where dynamic languages like Ruby and Python show their power: Rails, ActiveRecord, ActiveResource, gserver, DRb, Starfish, Twisted, PyGame, etc. These libraries tackle a problem that's been around for years, and succeed by hiding a huge amount of the work and/or changing the way you think about the problem.

Leonard even lists his top 5 libraries in Ruby, including mine, Hpricot:

Leonard: Hard to pick just five, but I'll showcase some lesser-known libraries that I think deserve attention:

  • hpricot, by _why, which makes me think I should just pack up Rubyful Soup.
  • Starfish, a really simple distributed programming library that Lucas wrote.
  • char-encodings deserves more attention. By which I mean, people should work on it as a way to improve Ruby's internationalization support, and yet I shouldn't have to do any work on it.
  • Ferret is a Ruby port of Lucene, the best Java library ever. It lets you do full-text search on structured data.
  • Finally, ActiveResource isn't a real library yet, and everybody knows about it, but it's going to be awesome.

Leonard Richardson Interview

Posted in  | 1 comment

A Natural Language Date/Time Parser for Ruby: chronic

Posted by Daniel Butler Sun, 10 Sep 2006 23:00:00 GMT

Chronic is a natural language date/time parser written in pure Ruby.

require 'chronic'

Time.now #=> Sun Aug 27 23:18:25 PDT 2006

#---

Chronic.parse('tomorrow') #=> Mon Aug 28 12:00:00 PDT 2006

Chronic.parse('monday', :context => :past) #=> Mon Aug 21 12:00:00 PDT 2006

Chronic.parse('this tuesday 5:00') #=> Tue Aug 29 17:00:00 PDT 2006

Chronic.parse('this tuesday 5:00', :ambiguoustimerange => :none) #=> Tue Aug 29 05:00:00 PDT 2006

Chronic.parse('may 27th', :now => Time.local(2000, 1, 1)) #=> Sat May 27 12:00:00 PDT 2000

Chronic.parse('may 27th', :guess => false) #=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007

Chronic uses Ruby’s built in Time class for all time storage and computation. Because of this, only times that the Time class can handle will be properly parsed. Parsing for times outside of this range will simply return nil. Support for a wider range of times is planned for a future release.

Time zones other than the local one are not currently supported. Support for other time zones is planned for a future release.

Cronic @ Rubyforge

Posted in  | 2 comments

Ruby on Rails Plugin: CriteriaQuery

Posted by Daniel Butler Thu, 07 Sep 2006 01:00:00 GMT

You'll like this code:

Person.query.namelike('name').join('address').citylike('city')

... and CriteriaQuery brings it to you (via Max Muermann) as a Ruby on Rails plugin. Head to the README for some useful examples, like this awkward beauty:

pq = Person.query pq.disjunction.firstnameeq(params[:name]).lastnameeq(params[:name]) if params[:name] pq.category_id_eq(params[:category]) if params[:category] ... address = pq.join("address") address.state_eq(params[:address[:state]]) if params[:address[:state]] ... end

Neat, huh?

CriteriaQuery Plugin Documentation Page
Ruby Plugins Directory Entry

Posted in  | no comments

Prototype Carousel Class for Ruby on Rails

Posted by Daniel Butler Wed, 06 Sep 2006 23:32:00 GMT

Sébastien Gruhier of Carquefou, France, a new Rails convert (after 13 years of C++/Java) has provided a handy Prototype/Scriptaculous Carousel component, which does not use any Yahoo User Interface JavaScript components. A carousel component allows you to view a window into a image stream, with forward and reverse buttons that allow you to navigate through the images.

Yahoo's page describes the component:

The carousel component manages a list of content (HTML UL and LI elements) that can be displayed horizontally or vertically. The content can be scrolled back and forth with or without animation. The content can reference static HTML content or the list items can be created dynamically on-the-fly (with or without Ajax).

The current version supports both static and Ajax content.

Prototype Carousel Component Home Page
Original Carousel Component Documentation

Posted in ,  | 1 comment