Skip to content

Easter holidays

I finally have a 4-day break from work ahead of me, and I have to say I could not wait. I intentionally did not get copies of movies and tv show episodes to watch so I don’t end up spending most of the days bumming — I have regular weekends for that.

These four days are for:

  1. Jogging,
  2. Setting up Debian with development environment on the MacBook,
  3. Some progress on work project #1,
  4. Some progress on work project #2,
  5. Prototype for toy web application (integrated with Facebook),
  6. More park time,
  7. Further planning for some things I realized still matter to me, and
  8. Savoring a good cups of coffee.

Hello again, lovely world! Keep me excited.

Tagged , ,

ActiveRecord association :reset

Is it just me, or is the use of reset() on one-to-many and many-to-many ActiveRecord associations quite unpopular? I actually have never used it (maybe never needed to use it) and have never seen it used yet.

I was looking into performance issues in one of our projects, and noticed some bit of association loading within a loop. I realized it is actually quite deceiving if we don’t remember some things.

Consider the following scenario:

  persons = Person.find(:all)
  persons.each do |person|
    books = persons.books
    # ... And then say a bunch of rendering goes here.
  end

Whatever the reason, let us say there are on the average 50 books associated to each person, and we need a list of all books associated to each of 50 persons in a single go. That could grow a pretty large data set.

Sure, the books for each person record are assigned to a variable within the scope of the each block and would normally be garbage collected as soon as the loop ends an iteration, but we might be ignoring that these books have been stored for the :books association of each person record. Each person record then is still referenced in the persons array, so there will be no garbage collection happening there either.

In goes the reset() function. The reset() function on associations simply clears the association data @target and updates the boolean tracker @loaded to put things back how they are before association data is loaded.


  persons = Person.find(:all)
  persons.each do |person|
    persons.books
    # ... And then let's say a bunch of rendering goes here.
    person.books.reset
  end

This did not help the particular area I was looking at as we are dealing with a harmlessly small collection there. Large index pages and sitemaps should employ memory-efficient tricks too, like combinations of pre-loading record IDs and paginated fetching, so this might not exactly be useful knowledge. It really is something to watch out for, though, and it could contribute much in memory optimization.

Tagged , ,

Maryland, et al

(Haha, before you even think about it: I am working remotely on Philippine time, not on vacation.)

My second sister and I flew over to Maryland on the 13th so we could spend the holidays with the rest of the family. We are just about to end our fifth day here.

So far everything is good. We have been around Washington D.C. this weekend, have driven through Maryland a bit, and will be in New York City tomorrow til Friday (Hopefully, I can drop by MET this time.). The company is great, of course. A different range of shops, the Wii, HD on demand, and GPS also deserve so much more than a bit of mentioning. I’m especially looking forward to possible skiing and eat-all-you-can cheesecake feast.

Hmm, what else to say. I’m starting colds because of the cold and some lack of sleep, but I’m just about to pwn it. :-) So forget about that.

I got some books earlier today. I wonder what else I’ll end up bringing home.

Tagged ,

voobys.com

I recently came across an interesting web tool: voobys.com. I’ve tried out its service for YouTube video downloads — the procedure is pretty brilliant.

Say I wanted to download the video in http://youtube.com/watch?v=F2TSy0Z5qTEw. I’d just have to replace the string “youtube” (as in “youtube.com”) in the URI with “voobys” (for “voobys.com”) and go to that URI. For this example, the resulting URI would be http://voobys.com/watch?v=F2TSy0Z5qTEw. This page will then contain a hyperlink with which I could download the video.

Convenient, portable, and easy to remember. A pretty creative solution, huh. There is a potential issue with terms of use, but that’s another topic.

Tagged , ,

validates_as_phone on GitHub

A second plugin to GitHub today.

validates_as_phone is a Ruby on Rails plugin that provides strict validation for phone numbers. At the moment, only phone numbers in Australia are supported. This will still be extended to support classifications and areas in the future.

validates_as_phone
==================

Strict validation module for phone numbers that supports classifications and
areas.

= General usage

== Installation

You can install the plugin the traditional way. Go to your application root
and do:

  script/plugin install git://github.com/kristinalim/validates_as_phone.git

== Validate your model attributes

Example:

  class Person < ActiveRecord::Base
    validates_as_phone :phone, :allow_blank => true, :set => true
  end

= License

Written by Kristina Lim (http://i-think.com.ph/kristina/)

Copyright (c) 2008 Syndeo Media
http://syndeomedia.com

= Contributing

If you wish to contribute to the project, you may contact the author through:

'kristinasyndeomediacom'.insert(8, '@').insert(20, '.')

= Acknowledgements

This plugin is named after the validates_as_phone plugin of Jerrod Blavos
(http://code.google.com/p/validates-as-phone/). Admittedly, this plugin was
built over the latter, but as the purposes of this plugin is more complex than
that of the minimal one, practically all of the code has been written over by
now.
Tagged , , , , ,