Firefox's new Cognitive Shield and Running Multiple Firefoxes Side by Side on OS X

Firefox has got a hot new thing they're calling "Cognitive Shield", which is a "new tab" page that shows you all your most visited sites. Google Chrome was the first browser that I'm aware of that did this, but I'm sure the Opera guys will probably jump in and say "we've had this forever". Safari's Beta 4 has one too and they're calling it "Top Sites" where they show you your most visited sites in a cover-flow style.

The design idea behind Safari's Top Sites and Firefox's Cognitive Shield could not be further apart from each other. Apple predictably went the sex appeal route with thumbnails of all the sites on a reflective black background. Contrast with Firefox's screen which appears blank until you move your mouse, then the light grey text appears, showing you the most visited sites. Use Safari Beta 4 for a few days and you'll quickly see one of it's huge drawbacks: it consumes a lot of memory trying to keep those thumbnails up-to-date. Firefox on the other hand does not consume any more memory, because it's just plain text. Safari is literally running like it has 12 (the max number of "top sites" shown) tabs open at all times, plus whatever tabs the user may have open. From a development perspective, I'm a bit perplexed as to how they would actually implement this feature in such a poor manner.

I don't want to talk a whole lot more about this, since the point of this post was to share with other people how to run different versions of Firefox side-by-side without having to worry about the beta version (3.1) overwriting profile data in your stable 3.0 version. One last thing I will say about "tab pages" is that I like them. I like this new trend to introduce tab pages to web browsers and I am especially keen on the Mozilla approach of not cluttering the screen or consuming resources keeping that screen up-to-date.

Over on the Firefox lab blog, they have detailed exactly what you need to do to try out this new feature, but it requires installing a development build of Firefox, which is undesirable if you need your browser to test functionality in other stuff you work on. Here's a couple steps to get you running multiple Firefox's at the same time, these steps are assuming you have already installed the latest stable version:

  1. Launch Firefox with the profile manager, use the terminal and launch: /Applications/Firefox.app/Contents/MacOS/firefox-bin --profilemanager
  2. Create a new profile (I called mine "3.1 user") and uncheck the box "Don't show at startup".
  3. Exit the profile manager and go download the latest Firefox 3.1 development version.
  4. When you're ready to install, instead of dropping Firefox in your Applications directory, put it somewhere else and then rename the app to something like "Firefox 3.1" or whatever makes sense for you. Optionally at this step, change the icon for this app so you will be able to tell the difference between the two versions when they are both running in your dock.
  5. Now drag the app into your Applications and launch it as normal, but make sure to choose the correct profile depending on what version you are using.

If you ever remove the development version, the next time you launch Firefox just check the box "Don't show at startup" and you will no longer be bothered with the profile manager at launch. One other thing, try not to launch your different versions of Firefox and use the wrong profile. This will corrupt your profile data across versions.

Written in / March 23rd, 2009 / 0 Comments

Running Ruby as a CGI Script with Apache on OS X (Leopard)

It took me a couple different documents to get me running a Ruby script on the built-in Apache webserver that comes with OS X, so I figured I'd document the steps.

First of all you have to have the web server running, but I'm going to assume that's already setup.

The out-of-the-box Apache config file (/etc/apache2/httpd.conf) is setup to alias the webroot path /cgi-bin/ into the directory /Library/WebServer/CGI-Executables/. Write a little Ruby script and drop it in that directory. It needs to be executable by all (chmod a+x hello_world.cgi). Make sure to include the script declaration statement to let the CGI process know how to execute it. Here is an example (hello_world.cgi):

#!/usr/bin/ruby
require 'cgi'

cgi = CGI.new('html3')
cgi.out do
  cgi.html do
    cgi.body do
      cgi.p { 'Hello World' }
    end
  end
end

I used Ruby's CGI library because it removes a lot of boilerplate crap but more importantly because when I wrote a plain script that outputted its own HTTP Headers, I kept getting script errors (500s). The Apache log file told me there was something wrong with my headers, but I couldn't for the life of me figure out what was wrong with it.

OK we've got our Hello World Ruby script that is in /Library/WebSite/CGI-Executables/ so now all we have to do is edit the Apache config file (/etc/apache2/httpd.conf) to setup the execution of .cgi files. So edit the config file by uncommenting the following line: AddHandler cgi-script .cgi. In my file it was on line #391, but yours may be different. Note that this line will be located in a block that is tagged like: IfModule mime_module.

Now just make sure your CGI module is loaded by uncommenting the following line: LoadModule cgi_module libexec/apache2/mod_cgi.so. Mine was on line #102 but again, your config file may be different.

That's all you have to do in the config file, so save your changes (need sudo) and then restart Apache: sudo apachectl restart

Hit your script in the browser at the path: http://localhost/cgi-bin/hello_world.cgi and it should work.

Now that you've got it working, you can tweak your apache config a bit more to add directories in your home Sites directory to be CGI-executable so you don't have to save everything in the obscure /Library/WebSite/CGI-Executables/ path. You can also add some other extension types besides .cgi if you want, but I prefer to leave it at the default extension because it doesn't reveal to the client what type of code is being executed.

If you're the only one that uses that webserver, then I recommend changing the DocumentRoot directory to be your Sites directory. This setting is on line #163 in my config file.

Written in / February 26th, 2009 / 0 Comments

Page.Select Rails RJS Problem with Ruby 1.8.7

Yeah I know Ruby 1.9.1 is out now so posting something that is specific to Ruby 1.8.7 is pretty lame, but I have to.

I recently ran into (yet another) problem with a Rails site I have running with Dreamhost. It is on one of their 64-bit Debian 4 machines, so maybe it's specific to that environment, or maybe it's an issue across all Ruby 1.8.7 installations. I can't really confirm it because I'm running 1.8.6 on my home computer and my other dreamhost server is running 1.8.5.

Anyway, anything using the RJS Select method will raise an exception like this:

undefined method `[]' for #<Enumerable::Enumerator:0x........>

Initially, to get around this I just broke out my RJS into straight up JavaScript. It was clunky, but it worked. Then an excellent Dreamhost support person got back to me about the issue and pointed me to this documentation page on the Radiant CMS site, which included this little snippet that could be used to monkey-patch the issue:

unless '1.9'.respond_to?(:force_encoding)
  String.class_eval do
    begin
      remove_method :chars
    rescue NameError
      # OK
    end
  end
end

Works like a champ.

Note: This issue just started happening about a month ago, which means Dreamhost just upgraded this server to Ruby 1.8.7 for some reason. I hope they don't do all their servers, they'll undoubtedly cause headaches when they do since this error is so obscure.

Written in / February 6th, 2009 / 0 Comments

Inherently Bad or Lost in the Dark?

In a recent blogpost with a sensationalist headline "Why Programmers Suck at CSS", Stefano Mazzocchi starts off abrasively by stating:

I think that programmers tend to avoid doing certain things not because they are inherently bad at it, but because they don’t know how to proceed. They find themselves in an uncharted and foggy territory, without a map, no sense of direction, and with a limited ability to know if they’re getting any closer to where they want to be.

Are we talking about some deep philosophical subject here or are we talking about HTML and CSS? What's this? Seven paragraphs (before any talk of actual CSS) of "I have studied the programmer. I know his faults and understand his learning methods"? Really?

If a programmer wants to learn CSS, he buys a book and starts coding. If he doesn't want to learn it, he is not asking to be berated by some self-proclaimed CSS guru.

Stehano's article is filled with CSS that does not work in Internet Explorer, aka does not work in the real world. His proposed fix? Include some magic JavaScript files that supposedly make everything better in Internet Explorer 6 and 7. Why does he do that? Shouldn't we understand why these things don't work and what we can change in our CSS to not require some magic JavaScript file? It's almost like Stefano is in the dark, with no sense of direction. Or maybe he's just inherently bad at IE bugs.

Written in / October 27th, 2008 / 0 Comments

TextMate Halloween Style All Over Again

For Halloween in 2006, TextMate pushed down a little update on everyone that added a new Halloween-styled theme, a new dock icon and a new splash image. It was awesome, but they took a lot of shit for it because apparently the world is filled with a one or two uptight developers. Go figure.

Well I doubt TextMate will ever make the mistake again of "having a bit of fun" with their fanbase, but I still love that theme and am rejoicing at the opportunity to bring it out from the cobwebs.

Here is how I brought it back:

  1. Download this large PNG (cobweb splash image)
  2. Download this Mac OS X icon
  3. Quit TextMate
  4. Copy the splash.png image to ~/Library/Application Support/TextMate/Spash.png
  5. Replace your TextMate.app icon with the one from step 2.
  6. Start TextMate and smile.

Update: For those who want to go all the way, you need the Halloween theme as well. Download the All Hallow's Eve TextMate theme here and then unpack it to your ~/Library/Application Support/TextMate/Themes directory, then go into TextMate (you might have to restart it to pick up the theme) preferences and choose this theme.

Written in / October 13th, 2008 / 0 Comments