Mac OS X compatible external web camera

I use my macbook with an Apple 23 inch monitor at work and so I can’t use the inbuilt iSight camera. Since Apple stopped selling the external iSight camera there is not much choice for Apple compatible web cams since most of the web cameras on the market don’t come with Mac OS X drivers.

One surprisingly option is the xbox360 web cam. This external usb camera works without any drivers and just plugs straight in and works. I managed to pick up a brand new one on eBay for A$35. The quality is pretty good and it sits without any problems on top of my monitor. Nice work microsoft.

Adding iso repository under XenServer 5.5

If you want to install an OS from a local repository under XenServer 5.5 then you need to do the following. The documentation on how to do this in the xenserver manual is incomplete.

first ssh into the xenserver
mkdir -p /var/opt/xen/iso_import
Copy your ISO images to the /var/opt/xen/iso_import directory using scp.
Create a repository with this command:
xe sr-create name-label=ISOs type=iso device-config:location=/var/opt/xen/iso_import device-config:legacy_mode=true content-type=iso
You then need to attach the ISO library with this command (nicely not mentioned in the citrix documentation)
xe-mount-iso-sr /var/opt/xen/iso_import

You should then be able to create a VM using the .iso

Apple Bootcamp 2.1 and Windows XP SP3

There is a problem with Bootcamp 2.1 in that you can’t install the Apple drivers under Windows XP SP3. I recently bought a new MacBook Pro and installed Windows XP SP3 from an image and then tried to update the XP hardware drivers using bootcamp 2.1. This didn’t work an instead gave a nice cryptic error 2762. It seems it is not possible to install the drivers manually either as windows can’t install the drivers for the wireless network, iSight camera, and trackpad.

The solution is to install XP from a SP2 image (luckily I had kept one), then install the drivers, and then upgrade to SP3. I hope this saves someone a bit of time.

Update. This has apparently been fixed in snow leopard. I guess another reason to update.

How to get total folder / directory size with Linux

If you want to know how much disk space is being used by a directory (including all the sub-directories) then you can use the following command. It will output a single number in human readable form (eg 8.2G). I have found this very useful for finding where all my disk space has gone.

du -h | grep -v '/' | awk '{print $1}'

X11 ssh-forwarding of a gnome-session to Mac OS X 10.5

If you want to X11 ssh-forward a gnome-session on a remote linux server to MacOS X Leopard there seems to be some bug in the 10.5 X11 that causes the gnome desktop to take over the whole screen and you can’t access the session. The solution is to open the gnome-session using Xnest instead. This opens the session in a small X11 window (1024×768 in the example below).

Xnest -geometry 1024x768 :1& DISPLAY=:1 ssh -X <HOST> gnome-session

Random PHP string

I needed to generate a random string in php that did not repeat. This little snippet will generate a random non-repeating 32 character string.

// Generate random 32 character string
$string = md5(time());

IE 6 javascript onchange() problem

I really hate IE6, but as it is still so common it is important to support it. I recently ran into a problem with the javascript onchange function. I was using onchange to update a text box on the page when the check box was selected. I was using “…onchange(this.checked)…” This worked fine for everything except IE6. It turns out that IE doesn’t fire the onchange state until the checkbox loses focus and so my update was not occurring.

The simple way around for this problem was to change onchange() to onclick(). The function now works in all browsers.

PHP number_format function problem

I have been using the php number_function() to format currency values in my code and was recently caught by the thousand separator comma. If you use the function and just specify the the number of decimal places (ie $x = number_format ($y,2) ) then you will get a comma introduced for all numbers above 999.99. This comma will break any maths functions that you might use downstream.

The solution is to specify the decimal point but remove the comma. The format to use to achieve this is $x = $number_format ($y,2,”.”,””) – the empty double quotes tell the number format function to not include the thousand separator comma.

Best Javascript compressor to use

I recently had a relatively large javascript (14KB) that I want to compress down. There are a lot of online JS compressors out there unfortunately not all of them actually work. After testing around a dozen of them I found the best two are JavaScript Utility and Javascript Compressor. JavaScript Utility was able to compress down my code to 5.0KB while Javascript Compressor compressed down to 6.3KB.

While both are good I would recommend using Javascript Utility, not only because it achieved a better compression ratio, but it also has a large number of other JS utilities that are worth using (especially JSLint). The only problem I found is I was only able to get the UTF-8 encoding option to actually run.

How to compare the remote and local versions of a file in Dreamweaver

I was recently faced with working out what had changed in one of my big php files on the remote server (someone naughty had been playing with it). I use Mac OSX Dreamweaver and after a bit of searching around I found the following way to make Dreamweaver easily show you what has changed. This is not really anything major but it might save someone a bit of time.

First download and install TextWrangler. It is free and quite a nice text editing program.

Next open “Preferences” in Dreamweaver and select “File Compare”.

In “File Compare” browse to the “usr/bin/” folder and select “twdiff”.

Press OK and then go back to the main menu.

Open in Dreamweaver the local file in that you want to compare with the remote version. Select “Compare with Remote” from the “File” menu.

TextWrangler will now launch showing you the difference between the local version and the remote version. You can then chose to keep or reject any of the changes.