ARCHIVE: May, 2007

Nice Quotes

THU, 31 MAY 2007

I wonder how many of us are into blog-adding spree, when you are starting, it’s kind of fun, but soon, it’s kind of scary, as the list of blogs gets longer, and it’s freaky to look at hundreds of new posts calling you up to read them each day.

So, I ended up with creating a new must-read category and choosing best-of-the-best blogs I should read each day. Even that, for the past few days, I have not been able to find time to read. So tonight, I decided to catch up with my reading, since tomorrow is Vesak day, and it’s a public holiday!

Soon some hours passed, Vesak day should have officially started for four and a half hours. I was wondering, why I am still awake at 4:30 am in the morning reading blog posts. I must be nuts I thought.

For those who understand, they will know that it feels great to be able to clear your blog posts. When you are done, somehow it felt like spring-cleaning, deep inside, it felt clean, fresh, delighted, informed, learned and if you are lucky, inspired.

And I was lucky; I found two inspiring quotes while following the Rails Conference Friday evening’s keynotes, from John Nanemaker’s post.

First they ignore you, then they laugh at you, then they fight you, then you win.

–Mohandas Gandhi

The best way to predict the future is to invent it.

–Alan Kay

RolloverImage rollover is the classic effect that we all have been playing for ages. And we often use it to rollover image tabs or menus.

Although I personally prefer to use text for navigation, but at times, when wearing the designer’s hat, I just can’t resist the temptation to make the design looks perfect through images.

Image rollover started with the traditional lengthy Javascript codes that preload the rollover images, and and setting the onmouseover and onmouseout events for each of the link involved.

<script text="type/javascript">
  // some javascript codes to preload images, 
  // rollover and rollback images
</script>

<a href="#" onmouseover="rolloverImage('about_us')" 
    onmouseout="rollbackImage('about_us')">
  <img src="images/about_us.gif" width="100" height="25" 
    alt="About Us" border="0" />
</a>

Many hated to write the Javascript rollover codes, because the codes are lengthy and ugly. So, people found a new way to create the rollover effect through Cascading Style Sheet (CSS) or Flash. I’m not going to talk about flash over here. So, no Javascript involved, great!

But, writing the CSS rollover ain’t a simple task too. Instead of writing Javascript, now you have to write the CSS styles, and the normal state and the hover state.

a.about_us {
  display: block;
  width: 100px;
  height: 50px; 
  background: url(images/about_us.gif) 0 0 no-repeat;
}
a.about_us:hover, a.about_us:active {
  background: url(images/about_us_over.gif) 0 0 no-repeat;
}

If you have 10 links, rest assured, you will need to write a pretty long CSS. And if you need display a different image for the currently selected link.

There is also another disadvantage of using CSS Image rollover, the famous flicker effect on IE 6. So on some occasions, you may want to just use a simple unobtrusive image rollover javascript.

With Rollover, you just have to bother about creating your images, the normal state and the hover state, write your HTML codes like usual without the mouseover or mouseout event, and unobtrusively add the rollover effect through a simple javascript call. Rollover also automatically preloads the rollover images on document load.

<ul id="nav">
  <li><a href="images/about_us.gif" width="100" height="50"
       alt="About Us"></a></li>
  ....
</ul>

<script type="text/javascript">
  window.onload = function() {
    new Rollover('nav');
  }
</script>

// or add you can add it to body onload event
<body onload="new Rollover('nav');">

No CSS involved, and with just a simple javascript call, you are done.

Demo and Download

A few months ago, when I migrated BookJetty from Java to Ruby On Rails (RoR) platform, one obstacle I faced was I could not find any object pooling library that checks for idle objects on a fixed interval, and evicts invalid and expired objects in the pool.

While in Java I used Apache Commons Pool, in Ruby, I was scratching my head back then.

But, the beauty of Ruby-and-Rails world is the citizen love to hack, when they can’t find a way, well, they always hack a way out. So being a good citizen wannabe, I wrote the Ruby version of first-in-first-out (FIFO) object pool library inspired by Apache Commons Pool.

It currently supports the following configuration parameters:

  • min_idle
  • max_idle
  • max_idle_time
  • max_active
  • timeout
  • validation_timeout
  • idle_check_no_per_run
  • idle_check_interval

This morning I’ve just got the time to wrap it up as a gem. To get started:

$ gem install common-pool

And some code snippets:

require 'common_pool'    
  
# Extend data source object
class RandomNumberDataSource < CommonPool::PoolDataSource
  # Overwrite to return object to be stored in the pool.
  def create_object
    rand(1000)
  end
    
  # Overwrite to check if idle object in the pool is still valid.
  def valid?(object)
    true
  end
end
  
# Create a new object pool
object_pool = ObjectPool.new(RandomNumberDataSource.new)
  
# Borrow object from the pool
object = object_pool.borrow_object

# Return object to the pool
object_pool.return_object(object)
  
# Or invalidate object and remove it from the pool
object_pool.invalidate_object(object)
  
# Create object pool with idle objects eviction thread
object_pool = ObjectPool.new(RandomNumberDataSource.new) do |config|
  config.min_idle = 5
  config.max_idle = 10
  
  # max 10 idle objects checked per run
  config.idle_check_no_per_run = 10

  # check idle objects every 10 minutes
  config.idle_check_interval = 10 * 60
end

# Return a hash of pool instance status variables, i.e.
# active and idle lists size, and configuration options
object_pool.status_info

For more information, visit common-pool rdoc documentation.

Time flies, the last time I worked on BookJetty, it was in February, three months has passed, and I’m glad that I finally am able to work on it again.

The recent features added are meant to make BookJetty more blogger friendly. We all love to show some books on our blog, be it the recommended list, currently reading list, wanted list and etc. So the new feature added, the blog widget, comes to our rescue.

Blog Widget

I have always wanted to link up my book list to my blog site. So the blog widget comes in handy. I created it to be as user friendly and flexible as possible. You can filter by your reading status, tag name and even by ISBNs.

Create blog widget

Vertical and horizontal list types are provided with options to hide and show cover, title, and author. You can also show the title below covers; left, right or center align your books, select the book cover size, and linking book directly to Amazon US with your associate ID.

One thing I like about widget, it works like magic, you just have to copy and paste some HTML codes to your page and your books will be linked up automatically.

The widget is so flexible that you can easily create a script that link to a bookmarked book based on ISBN. For those who often review books in their blog, they can use the same script, and just change the ISBN no. The old way just takes too many steps, find the book in Amazon or BookJetty, copy the image url, copy the book link and title, and manually format the html codes in your blog post. Now you just need to change the ISBN no.

Life is now so much easier with widget. I love widget.

Blog This Book Links

Blog thisThe other way to link to a book other than using widget is using the Blog this book links, shown below the book cover. Clicking on that link will show up four types of links, i.e. by book title, small cover, large cover and lastly a huge cover.

The difference with the widget way, is that widget will require you to bookmark a book before linking it up, and widget book covers are pre-formatted with nice borders, while blog this book links are available for all books; they are just plain html codes that link up with book cover images or book title.

Gravatar Integration

GravatarGravatar.com is the site to keep a central copy of your avatar. The idea is so you do not need to upload 10 avatars for 10 different sites that you signed up with.

BookJetty is now integrated with Gravatar.com, it will automatically look for your gravatar if you do not upload any avatar in BookJetty.

Others

There are other small enhancements made, like:

  • Shoutbox links are now replaced with some nice icons from famfamfam.com.
  • User profile page is reformatted to make it more pleasant.
  • User signed up process was streamlined to automatically logged user in after activation.
  • When filtering book list, differentiate selected tag name or reading status category, by increasing its font size and taking out its hyperlink.

And that’s about all for now. Hope you would love the new features.