Pragmatic AJAX


Today, my hardcopy of Pragmatic Ajax arrived. I bought the bundle edition consisting of the PDF beta version of the book and the printed edition.

It’s a wonderful book. I have been doing AJAX since a bit earlier than the launch of Google Maps, but I still thought that I need some brushing up especially in the matters of usable frameworks (I’ve been doing everything from scratch) and useful practices.

Considering that I liked every book of the Pragmatic Programmers I’ve read so far (we share the same mindset I guess), the decision to buy that book was a non-issue.

I’ve been reading the PDF-edition so far and completed about the first half of it, but I’m very happy now to see the dead-tree edition as reading that is much easier in terms of handling (no cheap printouts and no computer needed to read it).

The first half was very interesting, but I think I’ll better write a complete review once I’m through with it.

And in case you wonder what that picture above means… Well… Here in Switzerland, we have a brand of cleaner fluid which is called AJAX.

And we have had that for years, so they are not just riding some strange fashion mood like these guys. I wonder if the inventor of the AJAX acronym knew :-)

GPRS, Bluetooth and Mac OS X

GPRS in your mobile phone and bluetooth are a real dream-team: Phones like that are small, fit in your pocket and still, they allow you to connect to the internet from your laptop – and even at reasonable speeds.

In contrast to the widely spread PC-Cards or wired connections, the handling too rocks: Just keep your phone in your pocked, dial from the laptop and use the internet. No fiddling with cards (or drivers. or strange software. your OS comes with all it needs to get the connection going), no problems with forgotten cables.

Bluetooth brought simplicity to the connection with your phone. Earlier we had infrared or cables, but nothing works as reproducibly as bluetooth does – at least in Windows.

As you know, I switched over to using Mac OS for my main office workstation. And today I was in the situation of needing internet in train and at a customers site.

Naturally, I wanted to use my mac to connect via Bluetooth to my K750i to use it’s GPRS capability.

While the bluetooth stack provides a very nice assistant to add a new bluetooth device and even allows you to create the GPRS connection, unfortunately, it does not work in the end.

Apple does provide some very specialized modem scripts, which is both good and bad. Good because if there’s a script for your modem/phone, it’ll work perfectly. Bad because if there is no script, it won’t work at all.

The assistant provided a list of Ericsson phone scripts and suggested using “Ericsson Infrared”. Naturally I first tried connecting with that, dialing *99***3# as I would in windows (the GPRS data connection being the third configured connection on the phone).

The phone did not even begin the dialing process.

I rebooted the Mac, launched Windows, created the RAS connection there and connected via GPRS to google for a solution (oh the irony…).

And I quickly found one: The modem scripts by Kia ora Ross

One thing to note though: You must use the script using a CID which is not configured on your phone (which is different from windows) and use the name of the APN as phone number (which also is different). With that in mind, connecting is easy.

What remains to be told: Apple which claims to be the superior OS usability-wise fails on this not-so-advanced task. Not only that. It fails in multiple ways:

  • It does not provide a generic modem script (like Windows does)
  • It suggests a completely non-working solution (instead of telling “sorry. I have not matching script.”)
  • One you get the right scripts, you have to click the “Show all”-Checkbox to be actually able to select it – despite all scripts listed in the default configuration being completely unusable.

So I’m coming back to what I was saying all the way: OS X or Windows? Doesn’t matter. Both have advantages. Both have disadvantages. Neither is clearly more usable than the other. Just go with what you feel more comfortable and live with the problems.

Oh and: Setting up a GPRS connection via a bluetooth-connected phone arguably is not a task doable at all for the people OSX was designed for. So it’s probably OK if it’s a bit harder. But still…. I’m not very happy about this.

PS: This is written and posted during a train ride. Connected via GPRS. Written on my MacBook Pro.

Tweaking Mac OS X for the Linux/Windows user

As you no doubt know by now, I’m gradually switching over from using Windows to using Mac OS X.

I have quite some experience with using Unix and I’d love to have the power of the command-line combined with the simplicity of a GUI here and then.

OSX provides that advantage to me: For one, I’m getting a very styled and time-tested UI, the ability to run most applications I need (this is where Linux still has some problems) and on the other hand, I’m getting a nice well-known (to me) command line-environment.

Of course, in my process of switching over, I made some tweaks to the system, I’m sure some of my readers may find useful:

  • Use a useful default shell: I very much prefer ZSH, so chsh -s /bin/zsh was the first thing I did.
  • Use a useful configuration for said shell: I’m using this .zshrc. It configures some options, enables a nice prompt, fixes the delete-key, sets the path and does other small cosmetical things.
  • Install the developer tools. They are on your install DVD(s).
  • Go and install Fink. No UNIX without some GNU utilities and other small tools. The current source-distribution works perfectly well with the intel macs.
  • Fix the Home- and End-Keys.
  • Tweak the terminal: Open the Window-Settings, chose “Display”, use a reasonable cursor (underline) and set your terminal to Latin-1 (I had numerous problems using UTF with ZSH). If you want, enable Anti-Aliasing. Then chose “Color”, use the “White on Black” preselection and play with the transparency slider. Use the settings as default.
  • Install VLC – your solution for every thinkable multimedia need. Watch out to get the Intel nightly if you have an Intel Mac.
  • I never use sleep-mode because it feels “wrong” not to shut the machine down completely. That’s why I entered sudo pmset -a hibernatemode 1 to make the “Sleep” option in the Apple-Menu work like Hibernate in Windows.

If you are a web developer on an intel mac and consider using PostgreSQL, don’t use the premade builds on because they are still built for PPC. You may use the StartupItem which is provided there though. If you do, call PostgreSQL’s configure like this to get the paths right:

./configure --prefix=/usr/local/pgsql --bindir=/usr/local/bin --with-openssl
--with-pam --with-perl --with-readline --with-libs=/sw/lib

This is after you’ve installed readline using fink. OS X itself does not come with readline and psql without readline sucks.

After installing PostgreSQL with make install, the paths are set correctly for the premade StartupItem, which makes PostgreSQL start when you turn on your machine.

Furthermore, I created my own customized PHP-installation (5.1.2) using the following configure line:

./configure --enable-cli --prefix=/usr/local --with-pear --with-libxml-dir=/sw
--with-apxs=/usr/sbin/apxs --enable-soap --with-pgsql=/usr/local/pgsql
--with-readline=/sw --with-pdo-pgsql=/usr/local/pgsql --enable-pcntl
--with-curl=/usr --enable-ftp --with-gd --with-png-dir=/sw --with-jpeg-dir=/sw
--with-zlib-dir=/usr --with-freetype-dir=/usr/X11R6 --with-bz2

Use fink to install libxml2, libjpeg and libpng

Using the hints provided here, you’ll get a configuration which makes working with the machine much easier for a UNIX/Windows guy. I hope it’s of some use for you.

Praise to VLC

Now that I can be assured to have a windows system ready at hand should I need one, I’m more and more switching over to using Mac OS X for day-to-day productivity work – at least if it’s not about doing delphi work.

Now this sounds crazy, but in the end it all boils down to (IMHO) better font rendering and a
alpha-blended terminal.

Functionality-wise and productivity-wise, MacOS and Windows are on par. Both systems have little things that suck and both have advantages in other little things.

In the end, both are OSes.

Today, I was in the position of wanting to listen to the streaming version of OCRemixes once again.

They are using an .ogg-stream which I appreciate because of two things: For one it provides a
better Bandwith:Quality ratio and furthermore ogg’s a patent-free technology.

Problem: How to listen to a OGG-Stream on OS X?

Apples arrogance in regards of QuickTime is one of those things that bother me in OSX. Apple: There’s more to the world of multimedia than just QuickTime and MP3, so make the infrastructure extendable in a sense so it actually works (Hint: DirectShow works quite well – despite being a Microsoft product).

There are some QT/Ogg-plugins available on the net, but none of them (not even one I compiled myself to be 100% sure to have an Intel build) actually worked.

Just when I thought that all was lost, I remembered VLC.

My experience with video already showed it to me: VLC just plays everything you can possibly throw at it. And yes: It managed (and still manages) to play the remixes stream.

And the UI is great on OS X (if you don’t look at the awful preferences dialog).

VLC IMHO is a really nice example how a cross-platfrom UI should be done: It looks like it’s perfectly at home on my OSX. And it ALSO looks like it’s perfectly at home on Windows XP (a bit
minimalistic, but it does it’s job).

And with feeling at home I don’t mean: “It looks the same on both platforms”. No. It’s perfectly adapting to the look & feel of the platform it’s running on. No common theme, no quasi OS-look. It looks as much as your native Mac OS X application as, say, iTunes or TextMate does.

So: Thanks guys. This is great stuff!

XP on the MacBook Pro

As I’ve announced earlier, I’ve bought myself a MacBook Pro with the intention of running Windows XP on it (see that other post for the reasoning behind that), thought I changed my mind considering the multimedia capabilities: VLC (the preview for intel macs) plays whatever I throw at it, has a nice GUI and does NOT use 100% CPU time all the time.

One day after I made that blog post, I actually got my machine and immediately used the XOM EFI-Hack to actually install XP.

The process went quite smoothly despite it being quite a hack. The installation process actually was one of the fastest I’ve ever seen so far.

The problem with the XOM solution is the lack of drivers where it hurts the most: Power Management and Graphics

Having no graphics driver means: No acceleration, no DVI, no 2560 pixels resolution.

Useless for my purpose.

Yesterday, Apple announced Bootcamp, their solution for installing XP (or any other x86 OS for that matter) on the Intel Macs. Bootcamp requires a firmware update on the Macs which actually does nothing more but adding a real BIOS compatibility layer, allowing to install any non-EFI system.

Bootcamp itself is a graphical partitioning tool with the capability of resizing HFS+ paritions without data loss. And it comes fully packed with drivers for most of the integrated hardware (only iSight, the harddisk shock protection and the keyboard backlight don’t work)

As installing that driver package on a XOM solution sounded risky to me (and does not work as I’ve learned afterwards), I’ve installed the whole thing from scratch, deleting the former two paritions and letting bootcamp create new ones.

Installing XP was fast as ever and installing the drivers was one of the most pleasant experiences: Just doubleclick that large MSI and let it do it’s work. Reboot. Done.

Here’s my desktop in full 2560×1600 resolution (warning: The linked full-size picture is large) of my 30-inch cinema display, showing some CPU specs, the resolution control panel applet and the tool for selecting the default OS which was installed by Apple’a driver package.

The OS you select there is booted by default, but you can hold the Alt-Key while booting to bring up a boot manager.

I’m very plesed by the speed and low noise of the machine. Now the only thing I’m still whishing for is a docking solution as I now have to plug in three (DVI, USB, Power) or four (if I want ethernet) cables each day.

Well done, Apple. And: Thanks!

Update: This is a screenshot of the same machine running OS X. The installation is quite fresh still, but the most important things are installed already: Textmate, X11 and SSHKeychain.

Ruby on Rails

Today, our first project done in Ruby on Rails went live.

Christoph has done a wonderful job on it. The only thing I had to do was to fix up some CSS buglets in IE and install a deployment environement (developement was done using the Rails-integrated WEBRick server)

Personally, I think I’d have preferred using LightTPD with FastCGI instead of Apache, but the current setup pretty much prevented me from doing so.

Which is why I’ve installed mod_fastcgi on apache which was very, very easy on Gentoo (emerge mod_fastcgi – as usual).

Once I’ve corrected the interpreter path in dispatch.fcgi (which was set to the location of Christophs developement environment), the thing began working quite nicely.

And fast.

Considering the incredible amount of magic rails does behind the scenes, those 73.15 requests per second I got are very, very impressive (ab -n 100 -c 5). And actually so much faster than a comparable PHP application running using mod_php on a little faster server (19.36 req/s, same ab call).

The results have to be taken with a grain of salt as it’s different machines, different load and a different application.

But it’s similar enough to be comparable for me: the PHP application is running on a framework somewhat similar to rails with lesser optimization but also with lesser complexity. Both benchmarks ran against the unauthenticated start page which comes pretty much down to including some files and rendering a template. No relevant database queries.

I wonder how much of this higher speed is caused by FastCGI (a very convincing technology) instead of running the code in the apache server itself and how much is just rails being faster.

I will set up a test environement which is better defined to actually allow an accurate performance comparison: Comparable application in mod_php, php-fastcgi and rails-fastcgi. And if I have time, I’m going to run the two fastcgi-tests on LightTPD aswell.

Benchmarking is fun. Time-consuming, but fun.

For now, I’m content with the knowledge that an application that took a very small effort to write (even considering that Christoph had to learn the rails environment first) is running fast enough for its intended purpose.

As Christoph said: Rails Rules

thanks, guys