(More) Ajax Woes in Safari

The more I deal with Ajax and Safari, the more interesting problems I get with the combo from time to time. Since my last run in with the dual, which forced me to rebuild that particular section of the site using more traditional means, I have recently discovered one more issue having to do with multiple

1
XMLHttpRequest

calls via the same object from the same page. The short version of the story is: It CAN’T be done in Safari* (or not in the method that I know of). Firefox and IE, however, seem perfectly happy with using a single object to make multiple asynchronous calls.

Fortunately I am not crazy. I found an article that briefly touches on this issue. This article is also a very good short tutorial on how to get started on Ajax (though the author uses a Ruby backend to iterate the codes, which can easily be replaced using any code you are comfortable with.). Another article offers more depth on the same issue with some code samples to show (via Ajaxian.com).

To get around the problem, one way is to simply create multiple objects, one for each call request, as opposed to have one object to handle all the requests. If you don’t do this, when you make one

1
XMLHttpRequest

call, all the other Ajax fields on the same page will start loading as if they are expecting something back from the same request (for which they’ll wait an eternity and never get anything back).

Sometimes I just don’t know how I solve these kinds of voodoo-like problems. Even Google is powerless before I knew what the problem was. I mean, how do you Google for problems you don’t even know how to describe? And this issue was particularly annoying because Safari’s Javascript console didn’t report any errors.

*I also discovered that the same issue takes place in Webkit (the HTML rendering engine at the heat of Safari) based browsers, including Shiira. Though strangely enough, Camino (a cousin of Mozilla FireFox), much of whose gut is based on Safari’s renderer, didn’t have the problem at all! It’s also interesting to note that Opera 9 also suffers from the same issue.

Back in Web Development

I have been working on a project non-stop for 2 weeks to get the final features up and running. But I just couldn’t stop squeezing in some good-to-have features to boost the overall “value” of the product a bit. Here’s a short list of what I thought were really slick features:

1. Javascript lightbox: This one feature can probably single-handedly describe what the Web2.0 movement is all about. The BEST part is, integrating Lokesh Dhakar’s code to the project (or ANY project, really) is just a couple of copy and pastes and one line of code change!! That guy is a genius.

2. Recursive delete: This a pretty kick-ass class for recursively deleting whole directory structures even if they are not empty (PHP programming in Unix environments, this is a big deal). My project requires my PHP scripts to interact with physical directories. I thought it’d be a complete waste of my time to write a function/class to do this if someone else’s already got a solid script. Implementing this just took one line of code.

3. Directory compress & backup: I used this script to work in conjunction with “Recursive delete”. Basically before anyone deletes a whole directory, my PHP application will automatically back it up and nicely tug the compressed file in a safe place. Again, this is a kick ass class because it only takes a copy/paste and defining of a couple of variables.

4. Unique ID check via Ajax + PHP: I wrote this myself using an Ajax class I assembled from prior projects. It simply goes to the database and checks if whatever the user ID (or product ID or whatever) already exists. One bug I encountered under Safari was that if

1
XMLHttpRequest

returns nothing from the database (which means the ID the user entered was unique), Safari makes

1
status undefined

or

1
null value

complaints. One way to get past solve this problem is for

1
XMLHttpRequest

to return an empty space via PHP (or whatever language you prefer)… i.e.

1
echo " "

. Here’s a nice blog about Ajax related issues. This issue is also pretty well documented here though “bitterpill.org’s particular trick didn’t solve the problem for me.

5. Multiple file uploads: The Stickman has some really neat references to a handful of technologies I am currently exploring. This “multiple file upload” script isn’t particularly elegant but does its job exceptionally well. I was able to integrate this, along with everything above, into one coherent code base, fortunately.

6. Snif (stands for “simple and nice index file” ) is probably one of the best-looking and utilitarian directory and file index script I have found thus far. There are tons of others that do way too much or too little (some of which cost quite a bit too). The downside of snif is that the code hasn’t been maintained for quite a while, and its forum is littered with more questions than answers. But I did find some nice “mods” to enhance its core functionalities quite a bit. Another problem I had with snif was how hard it was to integrate into my existing code base. That said, snif is still a very solid standalone directory index script though!

7. By accident, I stumbled upon a list of Web2.0 sites from Tucows. I look forward to studying up the latest eye candies these sites offer for my future projects.

So now that most of the core features are done, I just need to find a fast(er) Windows environment to test the css layouts, mostly for IE. I wish IE would just go away so that us web programming types don’t have to deal with Microsoft’s snobbish approach towards web standards. Go Firefox, Opera and Safari.
.
.
.
Apple finally decided to release Core 2 Dual version of MacBook Pro right before Christmas! How kind. I made a pseudo promise that I’d get a MacBook Pro if they upgraded it to Core 2 Dual… not knowing they’d do it before January’s Macworld… But since the budget is kind of tight these days, I will hang on to my trusty old PowerBook G4 until OSX.5 Leopard comes standard with MacBook Pros! Hah!

Upgrading to Fedora Core 5

After having successsfully upgraded my spared Dell box to Fedora Core 5, I messed up the boot partition and had to do it all over again. So I decided I might as well document it here since the processs wasn’t quite as smooth as one’d hope.

UPGRADING FEDORA CORE 4 TO CORE 5 USING YUM
1. First, make sure

1
yum

is up to date. If you are going to upgrade your system with it, you might as well make sure the tool is up to pars.

me@localhost$

1
yum -y upgrade yum

This is going to download a bunch of other stuff other than

1
yum

. So be patient.

2a. Next, make sure sure your

1
kernel

is up to date as well. Or else when you upgrade to FC5, it will throw a bunch of errors like this:

1
2
Error: Package initscripts needs kernel < 2.6.12, this is not available.
  Error: Package kudzu needs kernel < 2.6.13, this is not available.

So here we go:

me@localhost$

1
 yum -y upgrade kernel

For multi-CPU systems, do the following instead:
me@localhost$

1
yum -y upgrade kernel-smp

2b. Just to be on the safe side, some packages may need to be removed before upgrading. This script should tell you what needs to go:

me@localhost$

1
perl -ne 'print "$1\n" if ((/Error: Missing Dependency:.*is needed by package (.*)$/) || (/Error: Package (.*?) needs.*, this is not available./))' /tmp/yum_upgrade | sort | uniq

3. Reboot. Make sure you boot into the latest

1
kernel

or else you are going to have the same problems as I mentioned before.

4a. Now delete any old

1
kernels

you have still on your system. First, let’s see what’s there:

me@localhost$

1
rpm -q kernel kernel-smp kernel-devel kernel-smp-devel | sort

4b. Delete old

1
kernels

:

me@localhost$

1
rpm -e kernel-version-number

I read somewhere that you should delete

1
kernels

by using

1
rpm

since it also tidies up your bootloader file for you.

Optional: Update

1
rpm

packages:

me@localhost$

1
rpm --rebuilddb

5. Now we are ready to get the FC5 upgrade package:

me@localhost$

1
2
3
rpm -Uvh <a href="http://download.fedora.redhat.com/pub/fedora/linux/core/5/i386/os/Fedora/RPMS/fedora-release-5-5.noarch.rpm" target="_blank">http://download.fedora
.redhat.com/pub/fedora/linux/core/5/i386/os
/Fedora/RPMS/fedora-release-5-5.noarch.rpm</a> (this code wraps for cosmetic reasons. But you should copy/paste this as if it's one unbroken line.)

6. Finally. Show time. Let’s upgrade this puppy…

me@localhost$

1
yum -y upgrade

Now sit tight and wait. This could take a while depending on your Internet connection. It took me roughly 5-7 hours on a moderately fast DSL.

7. Once everything is downloaded and installed, reboot.

8. It’s probably a good idea to keep your old

1
kernels

. But I deleted my FC4 kernels.

INSTALLING VMWARE 5.5.1.x
Nothing is EVER easy on Linux. The same assumption (and proof) goes to updating VMWare after the FC5 upgrade. VMWare complained about not being able to find “the directory of C header files”. To resolve this problem, you must download the

1
<a href="http://ftp.cvut.cz/vmware/vmware-any-any-update101.tar.gz" target="_blank">vmware-any-any-update101.tar.gz</a>

and run it. Everything will hum just fine after this update is applied to VMWare.

Much thanks to: brandonhutchinson.com and LinuxSky.com (Simplified Chinese only)

Remedy to Firefox Memory Leak

I wrote about reclaiming memory from Firefox’s memory leak problem. But apparently this supposedly memory leak is really a feature:

Excerpt from the Slashdot article:

“The Firefox memory leak is not a bug. It’s a feature! The ‘feature’ is how the pages are cached in a tabbed environment.” From the article: “To improve performance when navigating (studies show that 39% of all page navigations are renavigations to pages visited less than 10 pages ago, usually using the back button), Firefox 1.5 implements a Back-Forward cache that retains the rendered document for the last five session history entries for each tab. This is a lot of data. If you have a lot of tabs, Firefox’s memory usage can climb dramatically. It’s a trade-off. What you get out of it is faster performance as you navigate the web.”

Someone on that thread also found a way to remedy this memory leak once and for all…

1. In the Firefox URL box, type

1
about:config

2. Look for

1
browser.sessionhistory.max_total_viewers

and set it to “0” (default should have been “-1” )

According to Firefox’s online documenation, setting the value to “0” disables page caching and will damatically increase the time it takes to go back to a page using the back/front buttons (yeah, if you on dialup). But the documentation also gives guidelines on what values to set for the level of page caching you can tolerate (proportion to the memory Firefox will use).

Why Linux Will Never Make It to the Mainstream

To get ready for a Linux class I am taking, I have to put Linux back on the old Dell I have abandoned ever since moving Grace to the Mac. I decided to try the latest flavors out there — Ubuntu 5.10 and Fedora Core 4.

Linux has been great as a server environment for me. But I have been frustrated with it since the Redhat 8.0 days (precursor to the current Fedora project). Nothing has been intuitive in almost every aspect of the Linux wold. Everything from application naming convention (WTF is “Gimp” if you don’t Google it?), install, setup to the simplest things such as application upgrades. I have picked up quite a bit of Linux just from Googling and learning everything myself with occassional Q&A sessions with Kyung. But it never seems to get any easier.

Ubuntu
Start with Ubuntu, the latest and the greatest and the most recent “king of ease of use”. Sure enough, the entire installation and setup process was seamlessly fast — took less than 3 hours with everything installed and done. It was as easy to install as the Windows installation process, I thought. And all it took was one 700MB disc. Easy! I liked the experience so far.

But it sucked when it came to upgrading Firefox from the default 1.07 to the latest 1.5.0.1. I had to download Firefox, extract the file to some other directory, make symbolic links in one directory while changing other files and variables to make everything happy. Screw that. I tried using apt-get to update the software automatically, but then I was too lazy to figure out where to fix the repository list so that it’d get the latest Firefox, so I ditched Ubuntu.

Fedora Core 4
On with Fedora. I have used it quite a bit before. But that didn’t make the experience any easier. Upgrading Firefox was a bit simpler. But I still had to go through similar hoops. The main stumbling block on Fedora was trying to get VNC server to work properly (so that I can free up the monitor for my laptop). To demonstrate how much crap I had to do to make it work, here’s what I did…

1. Install VNC server by issuing this command

1
yum -y install vncserver

2. Check to see if vnc server has the right runlevel:

1
/sbin/chkconfig --list | grep vnc

;
but I got this:

1
vncserver 0: off 1: off 2: off 3: off 4: off 5: off 6: off

(hint: runlevel 5 should be

1
on

)
3. Change runlevel:

1
/sbin/chkconfig --level 5 vncserver

4. In

1
~/.vnc/xstartup

file, uncomment these two lines:

1
2
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

5. From the menu, go to “Applications > Preferences > Remote Desktop” and change options to allow remote users to control the workstation
6. Change rules in the iptables file (Linux version of a firewall) in

1
/etc/sysconfig/iptables

by adding a new rule:

1
-A INPUT -p tcp -m tcp --dport 5900 -j ACCEPT

(5900 being the port I need to open to allow VNC to accept communications through that port)
7. Restart iptables:

1
sudo /etc/init.d/iptables restart

8. Start VNC server:

1
sudo /etc/init.d/vncserver start

Yeah sure, I have everything in one place now. It sure took me some work and digging to put all the pieces together. Can an average Joe get VNC to work not knowing all this? The answer is obviouly a NO. And I rest my case… Unless things drastically change in simplifying the environment, it will never be in the mainstream.

UPDATE 06/14/2006: More info on how to set screen resolutions for vncviewer.

All the Web Colors Under the Sun

I was looking for more variety of colors other than the standard web-safe colors provided by BBedit, my preferred plain text editor for programming on my Mac. I found a pretty damn cool site that converts Pantone colors to RGB and Hexdecimal colors.

This color conversion tool allows you to convert Pantone® Spot Colors to RGB (sRGB) color values (Red/Green/Blue) and Hexadecimal color values (Hex). You can also view a Web Safe Color Palette and X11 Color Keywords with RGB, Hexadecimal and CSS Shorthand Hex color values.

It’s unfortunate that the combinations of web browsers, monitors and operating systems all treat colors differently. There’s no real way to have a uniform color palate… But the website is pretty cool nonetheless.

Home Made DVD Problem Resolved

After having some issues with burning DVDs using Apple’s iDVD dvd authoring software on Grace’s slower Mac, I decided to encode the project file on my laptop and see what happens. And it turns out that CPU speed DID matter in the case of dvd video encoding, at least in this one instance. Another cool thing I found out is that Apple’s iDVD can pull source files (raw video footage) over the network! All I had was the iDVD project file on my laptop, the rest of the source files (videos and music) were all on Grace’s Mac. It was way faster to encode the DVD on my Mac pulling source materials from Grace’s Mac over the network than encoding locally on her Mac!! WOW!

So the blue flickering is gone now. Copies will be made to anyone who wants one (namely, our moms and maybe friends of Grace).

Make Mac OSX Support Third Party DVD Burners

PatchBurn logo I inherited a nice Sony DVDRW drive (specifically Sony RW DW-U18A) from Kyung when he went back to NYC. Unfortunately Apple has issues with “unauthorized” third party dvd burners working with its apps (iTunes, iDVD… etc) in Panther (OSX 10.3). I couldn’t burn my iTunes playlist or home made DVD movies with it, rending the drive essentially useless with those apps. Fortunately PatchBurn pretty much resolved that problem. It’s a collection of drivers and patch files to allow Apple apps to recognize third party burners. With the release of Tiger (OSX 10.4) though, the drive was supported natively right out of the box without installing PatchBurn. Nonetheless, it’s a very nice collection of patches for Mac OSX before Tiger.

Name That Tune!

If you are anything like me with the music (who knows very little about), you will appreciate the convenience of being able to know what song is being played on the radio at all times, that is, if you are listening on your Mac or PC.

Name that tune with Tunatic

Tunatic is a tiny software that is capable of identifying pretty much any modern song within seconds of listening to it. It analyzes the music that’s being played, compare the data with a server and fetches the name of the song and the artist. The downside of this software is that it relies on the speaker of the computer (I guess that can be the upside if you are listening to the conventional radio). That means if you speak when it samples the music, it will take your voice into consideration… not good.

All in all, this little app has been able to identify most of the music I threw at it (nothing fancy though; it failed to identify non-English songs as well as Jazz). Another application the company makes is Tunalyzer, which is an app that sits in the background and analyzes everything in your music folder and sends the meta data back to the database that Tunatic uses. The idea is to sample as much music as possible with the right tags that people give to their music.

Reclaim Memory from Firefox

I still keep an eye on the browsers, even though now I have 1GB of RAM installed, for their memory leaks. Firefox and Safari are nortorious for leaking memory when too many tabs are open for too long. But thanks to this blog, there’s now a way to reclaim unused memory space back from Firefox:

If you minimize Firefox, it will (automagically) reclaim memory that it’s no longer using.

IT WORKS! Firefox was using 180+MB of RAM even though only 3 tabs were open at the time. By simply minimizing the window, the memory usage went down to just above 110MB. Nuts.

But seriously, a browser that requires 100+MB of RAM to run is just crazy. When Firefox is first launched, it only takes about 85MB of RAM. It creeps up as more and more tabs are opened/closed… etc. And the longer you run Firefox in one shot straight, the more memory it will take up over time. The same issue applies to Safari. But at least now there’s a work around for Firefox.

Damn you, Apple Safari team.