Technology

Bulletproof Web Design

Bulletproof Web Design -- Improving flexibility and protecting against worst-case scenarios with XHTML and CSS by Dan Cederholm

Let me start off by saying I'm a programmer, not a designer. Before reading Bulletproof Web Design, I had a basic understanding of just enough CSS structure and concepts to get by. This approach lead to very inefficient markup that was hard to read and maintain. What I was missing was a deeper understanding as to when to use the different constructs and why. I found this and much more in this book.

Dan Cederholm used a brilliant format in Bulletproof Web Design. Each chapter takes a single concept illustrated by an example site that employees a traditional "unbulletproof" approach and explains the pitfalls of the traditional methods. He then deconstructs the page and rebuilds it step-by-step using semantic XHTML and CSS. The books step-by-step approach of modifying only a couple lines of CSS and explaining the results make the book a quick, yet informative read.

The book starts by explaining why and how to design your site for flexible text sizes. He uses this as the driving point for the rest of the book. How to make your navigation, tables, tabs, lists, widget boxes, rounded corners, and layouts flexible. How to design your site to be valuable to users who either can not or choose not to use images and / or style sheets. The book ends with the step-by-step approach of creating a page that ties every concept together.

Reading the book has made me feel much more confident in my CSS usage. I have already seen the payoff as I have used the methodologies in the book to both design new widgets and to refactor existing code. I feel lucky to have stumbled upon it and am looking forward to reading his sequel book, Handcrafted CSS -- More Bulletproof Web Design.

ActiveRecord object caching in Ruby on Rails

Yesterday I started playing with basic caching for PriceChirp and tried what I thought would be easy. Boy was I wrong. It turns out what I was attempting to do is not supported by :memory_store in the development environment. Before moving to :mem_cache_store, I was able to find a work around. The work around is outlined below for those who do not have the option of using memcached. However, if you can use memcached, it is by far the better route to take.

My goal was to cut down on the number of database hit by caching the resultant ActiveRecord object in :memory_store.

PriceChirp has improved wishlist support


This week I improved the Amazon wishlist support in PriceChirp. One of the cool features of PriceChirp from the beginning has been how easy it is to import an Amazon wishlist into PriceChirp. The only problem with this feature is it was an all or nothing proposition. Now, we have the ability to view our wishlists in PriceChirp and select which items we wish to import. The old feature of importing everything is still thee, but now we have options.

To see this feature in action, log into your PriceChirp account and do a wishlist search. This is done by searching for the email address associated to your Amazon wishlist. Once your wishlists are displayed, you can select "view wishlist" to get a listing of your items. From this page you can easily select which item to import into your personalized tracker.

Have fun!

PriceChirp tracks prices on Internationial Amazon sites


PriceChirp is growing. This week I added support to allow people to track prices and be alerted of changes for all the international Amazon sites. This includes Amazon US, Canada, France, Germany, Japan, and the UK. Just select the location of Amazon you are interested in searching, and use PriceChirp like normal. It was designed to make it easy to manage products from multiple sites at once. I'm hoping this design decision will pay off if in the future I add more vendors to PriceChirp.

Number to Currency Outside Rails

I created a module I am also using both in rails and for some batch processing outside of rails. In order to ensure my data was formatted the same with both environments, I needed to figure out how to get access to the active_view helper number_to_currency outside of rails. Here is how I did it:

require 'rubygems'
require 'action_view'
 
def number_to_currency(number, options = {})
  ActionView::Base.new.number_to_currency(number, options)
end

Rescuing from open-uri timeouts

Found an issue with open-uri because today Amazon's API is wonky. The same issue will occur when accessing any remote data via open-uri (like a RSS feed) if the data source is going to slow. The relevant part of my ruby code looks like:

  begin
    doc = Nokogiri(open(api_url))
  rescue
    print "Connection failed: #{$!}\n"
    next
  end

For some reason, the rescue does not catch a timeout error.

/usr/lib64/ruby/1.8/timeout.rb:54:in `rbuf_fill': execution expired (Timeout::Error)

Explicitly catching the timeout error fixes the code.

  begin
    doc = Nokogiri(open(api_url))
  rescue Timeout::Error
    print "Timeout::Error: #{$!}\n"
    next
  rescue
    print "Connection failed: #{$!}\n"
    next
  end

Good to know, as you never know when your remote data provider will be slow.

Gravatars on Rails


Gravatar is the globally recognized avatar run by the folks who run Wordpress.com.

Your Gravatar is an image that follows you from site to site appearing beside your name when you do things like comment or post on a blog. This is done by associating an image to the users email address. Adding Gravatar to PriceChirp seemed like a fun thing to do.

The API is very simple, so adding it to a Ruby on Rails site is easy.

First, add a few lines to your application-helper.rb:

  def gravatar_url_for(email, options = {})
    url_for({
      :gravatar_id => Digest::MD5.hexdigest(email),
      :host => 'www.gravatar.com',
      :protocol => 'http://',
      :only_path => false,
      :skip_relative_url_root => true,
      :controller => '/avatar'
    }.merge(options)
    )
  end

You may also need to add:

Upgrading PriceChirp from Rails 2.2.2 to Rails 2.3.3

Today I updated PriceChirp from rails 2.2.2 to rails 2.3.3. It was easier than expected, but I ran into several gotchas along the way. Here's an outline of the major issues I encountered and how I addressed them.  Depending on your code, this may or may not be any any use.  Note: Several of these steps had to be performed on both the development and production boxes.

1) Updating gems

To upgrade the base system gems, as root I ran:

gem update

This upgraded the system gems such as rails, mysql, passenger, etc. The gems built into PriceChirp in the /vendor/gems directory had to be updated separately. I'll get to those in a few minutes.

2) Updating passenger

iTunes: Restoring Deleted Podcasts

Had a problem with iTunes today when I ran out of disk space while downloading some new podcasts. To quickly get some space, I deleted a hand full of podcasts to make room for new ones. After I recovered some space elsewhere on the drive, I returned to iTunes to restore a handful of podcasts I didn't really want to delete.

Problem is, once I deleted a podcast, there appeared to be no way to restore it. Using the "refresh" podcast option did not return these items to the list, nor are there any options in the menus to restore the deleted podcasts.

After poking around the web, I discovered that on a Mac, clicking on the triangle next to the podcast name while holding the "option" key, will return all the deleted episodes to the podcast's list. Not having a Mac, I tried the Ctl, Alt, and shift keys while clicking the triangle.

Eureka! "Shift" clicking the triangle restored the missing podcasts to the list allowing me to download them again. I also discovered "Control" clicking the triangle will open or collapse all podcasts at once.

I can understand why a deleted podcast is removed from the play list as normally once I delete a podcast, I am done with it. However, I would have thought it would have been documented somewhere how to restore these files.

 

iPhone 3G

58/365 - iPhone 3G After much hassle, I finally have an iPhone 3G. It's my first "smart phone" and I love it.

My biggest complaint with the iPhone is it's battery life. After setting up the iPhone to sync both my gmail and exchange mail, I was lucky if the battery would last until I got home from work.

Turning off the Wi-Fi helped a lot. Over the weekend I turned off the auto syncing of mail and all of a sudden, the battery seemed to last forever.

Thus far, I have found two "killer apps" that are really making me love the iPhone.

The first is Shazam. Ever heard a song in the background and wonder, what song that is? Well, you don't have to wonder any more. Shazam has the ability to pick out songs in loud places and determine what is playing. It then provides links to iTunes and YouTube for the song.

The second apps is Pandora Radio. You tell Pandora a song you like, then it starts streaming songs similar to it over the iPhone. A few votes up or down on what it selects, then you have a stream full of songs you like. Now I have the ability to stream internet music in my car. Sweet! Best part, it doesn't seem to kill the battery (that fast).

Syndicate content