July 25, 2008

TimeMachine FTW!

Listen to this articleListen to this article

Not withstanding the fact that I needed to restore my operating system in the first place--due to an inexplicable and catastrophic failure of the Java installation resulting in segfaults--I was able to restore my entire 100GB system in around 4 hours. For posterity:

  • Boot off the OS X System Install DVD--hold down option while the system starts
  • Connect the external drive with the TimeMachine backup--in my case a TimeCapsule attached via ethernet
  • Select "Restore from TimeMachine backup" in the Utilities menu
  • Select the specific backup (by timestamp) from which to restore
  • And away you go!

The disk is then automatically erased and a fully bootable system is restored sans temp directories and cache files. It even managed to restore my PostgreSQL databases that were running at the time--which probably says more about PostgreSQL than anything.

The one grumble I do have is that the timestamps in the name of the backups were some non-obvious period relative to the actual date the backup was made. The difference wouldn't have been much of an issue had I simply needed to restore the most recent backup but as it turned out I needed to go back a couple of days in order to get a clean system. Thankfully I got lucky on the second attempt :)

Once I had restored the system I took a look at the backup folders and sure enough there are two timestamps: the one in the folder name, and the created date. The created timestamp was spot on but the one in the folder name--the one presented to you when restoring--was whacky. I honestly didn't spend long enough to calculate if the difference was consistent.

What is really interesting is that I had SuperDuper! on my list of software to start using but it would appear there is little need--at least in my case.

March 06, 2008

TimePustule

Listen to this articleListen to this article

I bought an Apple TimeCapsule for backups *sniggers from the usual suspects*. The fact is I had perfectly good backups working with an external 500GB LaCie drive but being the glutton for punishment thought I'd give TC a whirl.

So I unpacked it, hooked it up, configured it and then mysteriously, I couldn't get it to work @ 5Ghz (a/n) which for me is an absolute must as my apartment building seems to have a at least one 2.4Ghz network for every apartment! By work I mean broadcast, be visible, locatable, whatever you want to call it. At 2.4Ghz, there it is. At 5Ghz, where did my TimeCapsule go?

The odd thing is that I made darn sure I had it configured identically to the AirportExtreme it was to replace which ran just dandy @ 5Ghz, even down to the passwords.

Having had it for 3 days with no joy and a couple of other users complaining of the same problem I decided it was time to take it back to the apple store today but before I do so, I thought I'd better erase the hard drive and reset to factory settings. For whatever reason (masochism?) I felt compelled to try giving it one more go, this time changing settings one at a time and restarting the capsule.

It starts off in 2.4Ghz g-mode so the first thing I changed was to have it run at 5Ghz n-mode leaving everything else at the factory default. Restart. There it is. I double check my network configuration (using the network utility). Yup, 5Ghz, 300Mbps. Ok. Change another setting. Restart. Still there.

Next, multicast rate. Chnage that from 6 to 24Mbps. Restart. Fine. Use wide-channels. Fine. Change country from the default New Zealand (go figure!) to Australia. Where did my wireless network go? WTF!?

Whatever changing the country does, it's not good! At first I thought it might change the channel (which seems hard-wired to 36 by default) but no, it still thinks it's broadcasting on channel 36. I can still connect to it via ethernet but it won't show up over WiFi at 5Ghz.

So it's now running quite happily (somewhere in NewZealand), locked up as tightly as the proverbial duck's bum, at 5Ghz. I'm honestly still not convinced it's as reliable as my AirportExtreme though and it seems to be slower than when I backed up to mac mini which, theoretically, should be slower as it had to make more network hops and compete with half-a-dozen CPU and Disk intensive application on it (including recording and playback of TV, movies, music, etc.)

Not happy Jan. How hard can it be to take an AirportExtreme and whack a bloody 1TB hard disk inside it!? Though what can I really expect of a one-dot-oh product from a vendor that seems to be slipping in quality as it's market share increases.

February 07, 2008

Lock Your Screen with LaunchBar

Listen to this articleListen to this article

Mostly just so I don't forget, here are some stupidly simple instructions for locking your screen using LaunchBar. (Technically, this actually starts the screen saver but as that is password protected it has the same effect as locking the screen.)

  • Open the the Script Editor, /Applications/AppleScript/Script Editor
  • Enter the text activate application "ScreenSaverEngine"
  • Save it to ~/Library/Scripts/Lock Screen
  • Open LaunchBar > Configuration > Scripts > Options
  • Enable "Home Library Scripts"
  • Save and Rescan

To lock the screen, simply open LaunchBar and type lock screen (on my setup loc is enough) and hit enter. Voila!

Hotkey fans will probably want to consider using something like MenuMaster or iKey to execute the AppleScript.

March 05, 2007

Monitoring Java Processes under Mac OS X

Listen to this articleListen to this article

Update: After a bit of googling I discovered that it's a bug which is fixed in Java 6 (Mustang) and relates to, wait for it, user names containing an underscore. Go figure!

So today, after I don't know how many years of doing Java development, I find out there is a command to list all the running Java processes. It's available on all platforms I could find and it's called jps. On most platforms it'll display something like:

1170 Jps -lm
1162 org.apache.tools.ant.launch.Launcher -cp  dist

Except under Mac OS X where you'll get something more like:

1170 Jps -lm
1162 -- process information unavailable

Pretty bloody useless!

So, I wrote a little ruby script to simulate the desired behaviour as much as possible (by using the built-in jps to collect the process ids; then filtering the output from ps accordingly):

#!/usr/bin/env ruby

require 'set'

pids = Set.new

`#{ENV['JAVA_HOME']}/bin/jps`.each_line do |line|
  pids.add($1) if line =~ /^(\d+) /
end

`ps -x -w -w -o pid,command`.each_line do |line|
  print line if line =~ /^ *(\d+) / && pids.include?($1)
end

Which, when run, produces output similar to (line continuation not included):

1162 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java \
  -classpath /opt/local/share/java/apache-ant/lib/ant-launcher.jar \
  -Dant.home=/opt/local/share/java/apache-ant \
  -Dant.library.dir=/opt/local/share/java/apache-ant/lib \
  org.apache.tools.ant.launch.Launcher -cp  dist

Granted it does produce lots more output than standard jps but it does at least produce something useful to look at when monitoring Java processes. Best of all, it means we can automate the monitoring in a manner that works across most platforms.

If anyone has a Better Way™, I'm all ears.

February 11, 2007

Integrating with MacPorts

Listen to this articleListen to this article

When I used to run FreeBSD, I loved the ports system that comes as the standard mechanism for installing most freely available (and some commercial) software. When switched to the Mac, I immediately starting using DarwinPortsMacPorts as my main method for obtaining and installing all my "geekware": PostgreSQL; Subversion; Ruby; and even Ant to name but a few.

Installing a new bit of software using MacPorts is usually pretty trivial. Something like:

sudo port install subversion

is all that's needed to install Subversion and all its dependencies.

Sure, there are Mac-specific GUI-based installers for some software that I use but I generally find it easier to use MacPorts for managing dependencies, versioning, updates, etc.

There are however, other command-line based software such as Pulse that, although relatively simple to install, still take some time and thinking not only to install but to install in such a way as to not turn my Mac into a glorified Windoze machine with all those lovely security holes. If only there was a way to create a MacPort installation for these too.

Well, there is: Create one yourself. So this morning I decided to see how difficult it would be to do just that.

Reading the quick-start guide, I soon learned that writing a Portfile—Literally a TCL script named Portfile—is often all you need to do. Unfortunately, the "quick" in "quick-start" is pretty much just that, leaving quite a lot to the imagination.

So, after reading a few existing Portfiles and following a bit of experimentation, I managed to get a relatively clean (and importantly, working) Portfile for installing Pulse which I figured I'd not only share with you but I would use as a guide to creating your own.

Now, before we continue, if you haven't already done so, I highly recommend reading the quick-start guide. It's ok, I'll wait...

The start of a Portfile looks something like this:

PortSystem 1.0
name              pulse
version           1.2.14
categories        java
maintainers       simon@redhillconsulting.com.au
description       Pulse automated build server
long_description  Pulse is an automated build or continuous integration server. \
                  Pulse regularly checks out your project's source code from your \
                  SCM, builds the project and reports on the results. A project \
                  build typically involves compiling the source code and running \
                  tests to ensure the quality of the code. By automating this \
                  process, pulse allows you to constantly monitor the health of \
                  your project.
homepage          http://www.zutubi.com/products/pulse/
master_sites      http://www.zutubi.com/download/

All pretty self explanatory really: The name and version of the software; what exactly it is and why I'd want to use it; who to blame when something goes wrong; and where to download the installation (in this case .tar.gz) file from.

Following on, we have:

checksums         md5 dcebf03b7a7099a476371b8142ba7624
depends_lib       bin:java:kaffe

These specify the MD5 checksum for the installation file to ensue we download the correct one, and any dependencies; in this case we need a Java runtime which comes pre-installed on most Macs anyway but I figured it doesn't hurt to make sure.

Next, we set up some variables for use later on in the script, again all pretty self explanatory:

set pulseuser     pulse
set pulsegroup    pulse
set home          ${prefix}/share/java/${name}
set bin           ${home}/bin
set executable    ${bin}/pulse
set dbdir         ${prefix}/var/db/${name}

(${prefix} is pre-defined by the port system as the path to the base of the installation—usually /opt/local.)

Now for something kinda cool: launchctl integration. If you don't know, launchctl is the preferred method for starting, stopping and otherwise controlling server processes under OS X. It can be a little tricky to get right with various XML configuration files, etc. however MacPorts comes to the rescue. With a few simple TCL commands, the installer will magically do all the heavy-lifting for us:

startupitem.create  yes
startupitem.init    "PULSE_HOME=${home}"
startupitem.start   "su ${pulseuser} -c \"${executable} start\""
startupitem.stop    "su ${pulseuser} -c \"${executable} shutdown\""

Neat huh? Now when we install the port, we'll automagically have scripts generated in all the right places so the pulse server can be started and stopped by the system.

We're almost up to the installation part but before we get to that, we need to stub out a few things.

You see, the whole installation process caters not only for unpacking and deploying of files but in the case of C/C++, etc. also configuring, patching and compiling, etc. In our case though, not only are these latter steps unnecessary, they're not even possible—we're dealing with a binary distribution—so we need to override them to do nothing:

configure {}
build {}

At last we get to the actual deployment of the files, creation of users, setting of permissions, etc.:

destroot {
  # Create the Pulse user
  addgroup ${pulsegroup}
  set gid [existsgroup ${pulsegroup}]
  adduser ${pulseuser} shell=/bin/sh gid=${gid} home=${dbdir} realname=Pulse\ Server

  # Ensure we have the needed directories
  xinstall -m 755 -d ${destroot}${home}

  # Copy the files
  system "cp -R ${worksrcpath}/ ${destroot}${home}"

  # Keep empty directories
  destroot.keepdirs-append ${destroot}${home}/logs ${destroot}${home}/versions

  # Fix ownership of some directories pulse really needs to write to
	system "chown -R ${osuser}:${osgroup} ${destroot}${home}/logs"
	system "chown -R ${osuser}:${osgroup} ${destroot}${home}/versions"

  # Add a symlink from bin directory to the pulse script
  system "ln -fs ${executable} ${destroot}${prefix}/bin/pulse"
}

Once again, pretty straight forward except for that odd looking ${destroot}. Why is it being used in some cases and not in others you may ask.

This actually got me for a while to until I realised that what the destroot step actually does is create an "image" of the installed software in a working directory—${destroot}—after which the predefined install step copies the staged files into their final destination. Not a bad idea really when you think about it. Certainly saves screwing up the production environment when something goes horribly wrong—like when you're playing around with things to see what happens ;-).

Last but not least, a little bit of post-installation goodness to instruct the user with any manual (or perhaps optional) processes, or even just a nice message to say "why thanks for using our software":

post-install {
  ui_msg "#"
  ui_msg "# The script ${executable} has been installed to facilitate starting and"
  ui_msg "# stopping ${name} as a true daemon process. It must be run as ${osuser}."
  ui_msg "# For example:"
  ui_msg "#"
  ui_msg "#   sudo su pulse -c "${executable} start"
  ui_msg "#"
  ui_msg "# This script assumes it is run from ${home}. To run from outside this"
  ui_msg "# directory, you must set the value of PULSE_HOME to the absolute path"
  ui_msg "# of this directory. For example:"
  ui_msg "#"
  ui_msg "#   PULSE_HOME=${home} sudo su pulse -c "${executable} start"
  ui_msg "#"
  ui_msg "# You will also need To create the directory ${dbdir} if it does not"
  ui_msg "# already exist:"
  ui_msg "#"
  ui_msg "#   sudo mkdir -p ${dbdir}"
  ui_msg "#   sudo chown ${osuser}:${osgroup} ${dbdir}"
  ui_msg "#"
}

And there you have it. Not too bad really and although we didn't cover quite a number of the other features the port system provides, I think you will have seen enough to get you started and on your way to integrating your favourite software into the ports system.

It sure beats rememberingforgetting a lot of manual steps each time you need to install/re-install software.

January 12, 2006

The Joy of Mighty Mouse

Listen to this articleListen to this article

My tolerance for things (anything) that don't work the way I expect them to is about as low as you could possibly imagine. Just ask my work colleagues about how painful it is to work with me when I have to use Eclipse. (And before the flame wars start, it's not a bad product it just doesn't work the same way I do. In fact after my last blog entry, Jon described Eclipse as well and truly "Opinionated Software". I couldn't agree more.)

So anyway, it came to pass that on Friday 23rd of December, 2005 my laptop died. Yes, my beloved PowerBook just wouldn't start up. (Of course those same colleagues that deride me for my whining about Eclipse also took great pride in cajoling me over my woosey "laptop".) Unfortunately it had apparently suffered one too many falls—about half-a-dozen to be precise—as I made my way around the globe earlier in the year.

Distressed as I was I naturally raced off to the Mac store to hand over the carcass and purchase a new, emergency, computer. Knowing full well that the MacIntel laptops were just around the corner—and being prepared to wait for one— I decided to buy an iMac instead. (Yes, yes. It was a G5 which as of three, count 'em, three days ago has become obsolete.)

As I was wandering around the store waiting for my machine to have 2GB RAM installed, my brother—oh yes, he was with me for moral support :)—started playing with a Mighty Mouse; just like the one included with my new iMac and the same ones that nobody (including me) liked. (I had twice attempted to use one and twice failed. James even offered me his for nix as he disliked it so much!) "Hey! This is pretty cool!" my brother yells across the shop floor. "You have to be kidding me!? Those things suck ass! I just can't seem to get the right-click thing to work!" I replied.

It was true. I had just never been able to get the right-click to work. It was a shame really because I really like the tactile sense of the track-ball thingy; it's almost erotic..ok, forget I said that. Anyway, after explaining my issues and demonstrating my complete inability to operate the Mighty Mouse my brother emphatically exclaims "You're a retard! How can you find it so difficult to use? The only explanation is you're a retard!" Nice. So after some investigation in the shop and after providing much entertainment to the staff as a matter of consequence, he (my brother) deduces the problem: "You're resting your hand on it and gripping" hey says. "Of course I am. How else does one use a mouse?" I enquired. "My arm and hand will get tired if I don't!" I refused to believe that this mouse was any good at all. What a piece of crap. I wouldn't be budged until he said something that really hit a chord: "Think about how pianists hold their hands. They don't rest there entire hand on the keys, just their finger tips and they don't get tired arms." And what do you know? It worked.

The moment I stopped gripping the mouse and instead lightly holding it with my fingertips, the moment I was able to right-click just fine. What's even more impressive is that at the end of a day in front of the computer, my hand no longer feels fatigued from using the mouse all day. Who would have thought? I wonder if the mouse was design in this way purposefully or whether it was sheer luck? Whatever the reason, I now love my Mighty Mouse and what's more, I actually miss it!

September 09, 2005

Managing Sensitive Data on Mac OS X

Listen to this articleListen to this article

One of the clients I'm working for at the moment mandates—quite rightly so—that any data taken offsite must be encrypted. Mac OS X provides two ways to achieve this: FileVault; and Encrypted Disk Images. (If you want to know how to encrypt emails, see this article.)

FileVault (System Preferences>Security>Turn On FileVault...) is kinda cool: It allows you to encrypt your entire home directory. This might be handy if you're super paranoid but I'm not; neither do I want the overhead of having everything I write to disk encrypted.

Encrypted Disk Images on the other hand are super cool for this kind of thing. If you're familiar with Mac OSX then you've no doubt used plain disk images before. They're the .dmg files that are used for distributing most of the software you install. The neat thing about them is that you can mount a disk image and use it just like any other disk on your machine. On top of this, you can encyrpt them so that unless you have the password, no one can peek at the data.

To create a blank disk image:

  • Open Applications>Utilities>Disk Utility
  • Select File>New>Blank Disk Image...

To create an encypted disk image:

  • Open Applications>Utilities>Disk Utility
  • Select File>New>Disk Image From Folder...
  • Choose the folder you wish to use as the source of your disk image; and
  • Press Image

In either case:

  • Enter a filename and location and choose an initial size—disk images dynamically resize so don't worry too much about this
  • Select AES-128 (recommended) for Encryption; and
  • Press Create

You'll then be prompted for a password with which to encrypt—and decrypt—the file. You're also given the opportunity to save the password in your keychain. This just means you won't have to remember the password when mounting it on your own machine—If you move the file to another machine or send it to someone else, a password must be entered manually.

Now anytime someone tries to mount the disk image, they'll be prompted for a password; if they don't have the password the data is protected, even if they try to read it using another tool.

Once mounted, you can use it as you would any other drive: as a mounted image in Finder; or under /Volumes/ using the filesystem.

September 02, 2005

Multiple Mac (Tiger) Logins for Testing

Listen to this articleListen to this article

I do all my development on my mac powerbook which, up until today, has had only one account: mine. But this morning, as we were trying to solve the last of the MT issues, I needed another login with which to quickly try something out.

It seem as though there was something peculiar about my login that was causing some of the problems so, I open Accounts and created a test user. So far nothing special about his—I'm sure you create test accounts all the time— however it's always annoyed me that you have to logout to switch users. I mean really, this is supposed to be unix right?.

Tiger (OS X 10.4) has a nifty "Fast User Switching" option which allows you to switch between users while leaving all the applications running. I had heard about this feature some time ago and thought to myself "phe! what do I care?" but I'd never thought about it in the context of testing.

To enable fast user switching, open "Accounts" in "System Preferences" and and click "Login Options". Tick the box titled "Enable fast user switching" (it's down the bottom). You should then see a list of accounts in the top-right of the menu-bar.

The great thing about this for me is that I can quickly blow away the account and re-create it; or have multiple accounts all logged in to my apps at once, all from the one machine. Of course the fact that I need to get down to manual testing says more than anything but alas, in this case, I didn't have much choice. Besides, as James has berated me for in the past: Just because you have automated tests, doesn't mean you can avoid manual testing as well.

On a side note, I also love SSH as it allowed me to install a public-key for the MT support guy to login to my shell account without needing me to create new users—which I can't do anyway because it's not my server :)

Update (2 September 2005): I noticed today that Redstone Software have a new version of OSXvnc that supports this, allowing you to view (and control) the other logins without even switching! It's a free download; as is Chicken of the VNC—A VNC client—which you'll also need.

August 24, 2005

PGP for Mac Mail

Listen to this articleListen to this article

If you've ever needed (perhaps need is too strong a word, how about wanted) to digitally sign—or encrypt for that matter—your emails from within the Mac Mail client, it's pretty simple. Even though there are plenty of mail applications that support PGP, I've grown fond of Mail.app so this morning—for no real good reason—I installed a few plugins, etc. and was up and running in literally 5 mins (ok 10 mins—I didn't have a clue what kind of signature I should use).

First go and get GPGMail. The download is a .DMG file and the instructions on the web site are easy to follow. In addition to GPGMail, you'll also need GNU PG for the Mac (GPGMac and GPG Keychain Access as a minimum).

I also found I needed to go into the Preferences>PGP>Composing and switch on "By default, use OpenPGP/MIME". This allows signed messages to be sent using MIME rather than the old-school format which surrounds the text in the signature and makes it look as though your email was sent through some kind of full-on nerdifier—a bit scary for mum.

Now that I have the ability to sign emails I'll just, well, probably never use it really—quite frankly, I can't imagine anyone being bothered to impersonate me in an email—but at least I feel "safer" LOL.

So anyway, here is my PGP key (valid until August 22, 2006) for anyone who cares:

Key ID: 0xD56C95B07EA87B26
Key Type: RSA
Expires: 2006-08-23
Key Size: 2048
Fingerprint: AF94 4D3E F229 1A40 4F79 17DD D56C 95B0 7EA8 7B26
UserID: Simon Harris <simon@redhillconsulting.com.au>

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (Darwin)

mQELBEMLpCoBCAD1qKqEmXhnbg8unu7n3wL8d8qyqu9M7iIhLMn6ZIxHPe91vXCi
3NxCu9J5p+nenKcwyPV4i/TA4G6lr6hGAv6yOkCKXg/kMX/oPoqVALBnzz+NNXXO
v9xZ1/DnQuyMXj/JP3u/rMrGErO5BEq+RtxQ3BwdbF8TsEktaaIrPPG/ZRWlSSCn
FhTbS4F+J8bNNgmB2M8AYbk5F2FJc68ikSDDKz28F/pF1Xal+O/s3nVtXgQkf6o5
sV/YnIGogDP419XQ8C9tb4dqoe8oR8v25g6umNEDcUMtOS3Utyds2q7mfdlczjAu
YpixCLk8QMbEfsaQqGJU7b7YjK9iaVJqS/Z3AAYptC1TaW1vbiBIYXJyaXMgPHNp
bW9uQHJlZGhpbGxjb25zdWx0aW5nLmNvbS5hdT6JATcEEwECACEFAkMLpCoFCQHf
4gAGCwkIBwMCAxUCAwMWAgECHgECF4AACgkQ1WyVsH6oeyZa4gf9Fus1SDOwBYG6
RLiQomXWhfHibGZnrssw9ECemI6I81kgKC6rd+srxbiKit09TIMIUzZ/oecNVtxg
80rgbYsOT4EGniq/As5c6xfYNcxwgGW00Xf6txvMGCRzkierHWlE0KajOW94AnuA
tzHC9vsPVxTjt4dM08IHWS9VeuqGq8ULokcHh9uF4e24s/maJFUGikYm2dACKS8v
NPImFHUcV17pTm4gptag4bm1+KmFWS1wnUS/I1jfmUc+xJOrXFRadkEbiYJEi1aa
PyvgyvXzupia6RDyMvPfUILZLO1L4be/KGf6R6jdhE4T+9U4dNHbGnukIqkIQLRx
gNqhtklgkA==
=2DOr
-----END PGP PUBLIC KEY BLOCK-----

Of course it occurs to me that someone could also spoof my blog and change the public key here but again, I'm thinking people have better things to waste their valuable time on like say, RAD for example ;-).

August 23, 2005

Invasion of the Battery-Life Snatchers

Listen to this articleListen to this article

Over the past 6-9 months, I've been doing a lot of development using my PowerBook running on battery. For the most part it works really well: The performance is just fine (with some tweaking of the power-saving settings), giving me around 2 hours of editing, browsing, emailing, etc. That is unless I'm developing code using IntelliJ.

When running in the foreground, IntelliJ seems to use anywhere between 3.0% and 6.0% of the CPU. Not too bad you might think but that is when I'm not doing anything with it. Even when IntelliJ is in the background -- either hidden or minimized -- it still uses around 3.0% of the CPU as this screen-shot from top clearly shows:

     PID COMMAND      %CPU   TIME   #TH #PRTS #MREGS RPRVT  RSHRD  RSIZE  VSIZE
    1259 top         14.5%  0:29.70   1    18    22   776K   372K  2.62M  26.9M 
-->  670 idea         2.7% 11:11.22  26   >>>   485   270M  28.3M   231M   831M <--
    1248 Safari       0.2%  0:06.22   6   127   238  8.89M  27.9M  18.8M   243M 
    1247 SyncServer   0.0%  0:03.65   2    53    48  12.2M  3.36M  15.1M  47.3M
    1225 mdimport     0.0%  0:01.11   4    66    67  1.39M  3.27M  5.16M  39.7M
     668 bash         0.0%  0:00.02   1    14    17   220K   820K   904K  27.1M

A quick check of the Java version indicates that I am running JDK 1.5 by default:

simon$ java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-56)
Java HotSpot(TM) Client VM (build 1.5.0_02-36, mixed mode, sharing)

And a quick check of the About Box in IntelliJ confirms this.

Now admittedly I haven't tried any other Java applications so I'm not too sure if it's a Java issue, a Java on OS X issue, an IntelliJ issue or what but it is driving me nuts because it pretty much turns my 2+ hours of battery life into 30-45 minutes.

So if anyone has any idea how I might get IntelliJ to stop using CPU when it's idle, please, please, please let me know.

Oh and Jeaves, "use Eclipse" and "get a real computer" will not be considered helpful answers ;-)

Update (30 August 2005): Vote for the bug.

August 17, 2005

Prevent Mac Droppings on Network Drives

Listen to this articleListen to this article

In my current gig, I'm using my PowerBook in an all M$ Windoze (with the exception of Linux servers) environment and it's working a treat. Except for one thing: all those .DS_Store files.

Finder in Mac OS X (and probably previous versions too I imagine) creates .DS_Store files whenever you browse a directory. The file is seems pretty harmless - apparently it contains little more than window preferences, etc. - and Finder hides them from view.

Unfortunately, it does get the back up of some of the other developers. Not really because the files exist, but more because, for some reason, the files get created with a timestamp in the future which causes all manner of problems for the guys writing their MFC applications - with asserts turned on the applications barf all over the place.

So, I did a quick hunt on google and found this article that explains how to prevent the behaviour. It's a pretty simple fix and involves entering the following at the command-line (possibly followed by a re-boot?):

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Now if someone could only tell me why I seem to end up with all these ._XXX files lying around that don't appear in Finder, nor when running ls -la but do end up in my zip and tar balls.

July 27, 2005

You See I Am Trying To Be Objective About It.

Listen to this articleListen to this article

It was an unsettling feeling, one I was sure I had experienced before.

Seven days ago today, I boarded the good-ship Xcode bound for the land of Cocoa. I was promised a bumpy but nevertheless enjoyable ride over well charted sea, enjoyable smalltalk and no bugs. Life would be wonderful and applications would spew forth from the finger tips of those who chose to take the journey.

Seven days later, I'm in pain. I'm hurting. I'm surrounded by square brackets. I have a hard time keeping track of my memory (maybe it's alzheimer's?). I wish I new what was wrong with me but even the good Dr. GCC seems to have a heck of a time diagnosing my condition. I have a sneaking suspicion it's a form of jet-lag - I feel as though I've travelled back in time (about 15 years to be precise) but I'm not sure.

Humour (such that it is) aside, I've been getting into Objective-C the past week as there's a project I'm about to start working on that is targetted at Mac OS X and will be written in said programming language. So, I thought I'd go head first and use Xcode as well. Ouch, ouch, hurty, hurty. Why do I feel like someone just cut off my arms and stuck red hot pokers in my eyes? To be honest, I think I should have started off with TextMate and GCC. But nevertheless I'm percervering.

I do like the Smalltalk like features such as dynamic binding and the calling syntax is quite simialr too. I don't care much for the use of square brackets - though I'm not sure I could come up with anything much better for a language that is (or at least was) essentially a pre-processor for a C compiler. The fact that I have to use pointers all over the place is particularly irritating too.

Ahh yes, I was once a member of the K&R club: First C; then C++. All those calls to malloc & free, new and delete. Endless hours of trying to remember what happens when I use array indexing on something declared as int **. In the end though, I guess it comes down to what you're used to and for the last 6 years (I think?) that's been Java; a language that for all it's short-comings (of which there are plenty), is a pretty simple language to learn and understand - at least it was for me anyway. I've become acustomed to garbage collection, packages and object references (the last being syntactic sugar mostly) and I like them. And of course then there's IntelliJ and Eclipse to help me out, suggest class names, think for me.

So it came as rather a shock to the system to go back to an IDE that seems to require soooo much configuration for apparently soooo little benefit, a language that forced me to think about when to call release to cleanup unused objects, and an overall environment that let me compile and run something that, on subsequent inspection, didn't even seem to be valid code - more likely a "feature" of Xcode than any underlying problem with GCC or the language itself.

Of course many of you will argue that I've forgotten what it's like to be a Real Programmer™; that it's character building. To this I say phooey. I was once an assembler programmer and I loved it. Then I became a C/C++ developer and I loved it. Then I moved to Java and never looked back (well maybe once but nobody saw me do it so you can't prove a thing). Moving to Objective-C is thus a painful yet disturbingly rewarding experience; like pulling out the old Commodore-64 and playing Galaga: The graphics suck but they're cute and the game is nevertheless fun to play.

So, the things I like about Objective-C so far:

  • Dynamic dispatch - ie. run-time method binding;
  • Categories - adding methods to objects at run-time;
  • Smalltalk-like calling syntax; and
  • self - I don't know why but it's somehow more appealing (or just different) than this;

Things I dislike about Objective-C so far:

  • Manual (yes as far as I'm concerned even reference counting is manual) memory management;
  • Square brackets;
  • + and - for marking static and instance methods respectively;
  • @whatever - smacks of pre-processor hackedy hack hack hack; and
  • Needing to manually call the super "constructor" - it's not really a constructor so, yes, I know why it's necessary but it still sucks.

But in the end, who can resist the sexy look-and-feel of Mac OS X apps? Not I. And I want to try my hand at creating some so what better way to do so than Objective-C/Cocoa. I'm assured that once I get into using the Cocoa stuff, life get's a lot more fun and interesting, fingers crossed. Or perhaps I'm just too old and grumpy ;-)

If anyone has tips, links, experience they'd like to share on how to make this a more pleasant journey (no, shut-up and take it like a man doesn't count), please please please let me know.

May 04, 2005

Desperately Seeking Key Bindings

Listen to this articleListen to this article

As you're no doubt aware by now, I'm a Mac weenie (one of us, one of us, ...) and have been for 9 months or so now having switched from Gentoo Linux - I got sick of managing my irrational need to constantly upgrade and re-compile the kernel.

When I made The Switch(tm), it took me a few weeks to re-learn the keyboard so that I could get back to using mac apps the way I had used X and before that Windoze apps. I'm also an IntelliJ weenie and the one thing I've found that frustrates the hell out of me is that the keybindings (for the Mac) are totally and utterly non-standard. For example, I want to use Command-W to close a tab.

I know I could go in and change the keymap myself but there are probably dozens if not hundreds of commands to map and, as I'm fundamentally lazy, I figured I'd make a plea to anyone who may have performed this heroic effort already ;-). So, if anyone out there has a comprehensive Mac OS X keymap for IntelliJ, feel free to fling it my way and in return, I'll...um...sing your praises?

P.S. telling me to use Eclipse or be a real man and use VI key bindings aint gonna cut it either - I prefer IntelliJ flavoured kool-ade ;-)

May 01, 2005

Two Tigers For Two Days In Two Minutes

Listen to this articleListen to this article

I've been playing with Tiger (OS X) and Tiger (JDK 1.5) for almost 2 days now and I like it. Spotlight rocks. Dashboard widgets are neat and finally I get to do some stuff with Java 5! So here are some some observations and a few gotchas I've discovered so far.

First up I did an archive and install so I admit I didn't start with a totally clean slate.

Overall OS X 10.4 seems to be a little slower and a little buggier than 10.3. Safari hangs or crashes on me every now and then and the little colour wheel is becoming an all too frequent experience. Again this may be due to the fact that I did an "upgrade" rather than a fresh install. A friend of mine did suggest that perhaps spotlights indexing was chewing a bit of CPU from time-to-time. Not sure. I'll have to wait and see.

The RSS reader in Safari is beautiful though rather less than I had hoped for. Seriously, it would have made much more sense to build RSS support into the mail client than the web browser. There doesn't appear to be any way to see at a glance, which feeds have new articles. The only way seems to be to "show all" in which case my news feeds totally swamp any others that I might be interested in. Maybe it's just what I'm used to so, we'll see how it goes.

Speaking of mail clients, Mail 2 as it's now called has had a new face-lift and I can't say I'm that impressed. I kinda liked the old L&F. They've taken away my Outbox and status bar. I had found both of these particularly useful when accidentally pressing send before I had completed an email. Again, maybe I'm just a doofus but I can't see anyway to turn these back on. Guess I'm going to have to be more careful when I compose my emails from now on.

Spotlight (Apple+Space) is pretty damn cool even if it is probably little more than a Google Desktop but I like the fact that it's built in, let's me search inside files as well as through file names and it's fast enough (for me) that I've stopped using Quicksilver. Spotlight categorises files that it finds; one of those categories being applications. It has integration with mail, safari, address book, etc. so it's able to search all your emails, bookmarks, contacts, you name it. This is not to say that spotlight can really compete in any way with Quicksilver, it can't. But I'm no power user and it was really only an application launher for me so I can probably live without it, maybe.

No matter what your feelings on the OS are, if you want to play with JDK 1.5, then you have little choice but to switch over - Apple aren't going to ship a version for 10.3.9 or below. I downloaded and installed JDK 1.5 and followed the instructions on how to make it the default runtime for applications. This meant IntelliJ now starts up using Java 5 runtime but running java from the command-line still brings up JDK 1.4.2. The trick it seems is to play with some symbolic links in the bowels of the totally non-standard distribution that apple concocted for reasons known only to a select few I'm sure. So, to get JDK 1.5 from the command-line, I found I needed to do the following:

cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm CurrentJDK
sudo ln -s 1.5 CurrentJDK

On that note, the latest EAP of IntelliJ seems to be a lot more stable. I'm not sure if it's the EAP, JDK 1.5, OS X 10.4 or a combination but whatever it is, I'm grateful as I was getting sick of the weirdness with dialogs losing focus and disappearing on me all the time.

The dashboard (F12 by default) is rather like Konfabulator only it resides on a transluscent pane that appears on top of all other applications. I've been using the Weather, Calculator, Translator and Dictionary widgets quite a lot. Unfortunately the YellowPages widget is for US numbers only. Ooh ooh, the Flight Tracker is very cool! Not sure how often I'll actually use it but it is pretty neat.

I also use the World Clock. Like all widgets, you can have as many open as you like on the dashboard. I currently have only three open: one each for London, Calgary and Bangalore :X. Two widgets I'd like are one for monitoring my email and another for tailing a file such as the system log. Anyone?

My next little hack is to do with the Weather widget. It seems that when creating the widget, the developers decided that evey user would of course be residing in the US; try putting in Melbourne for the city. I had no idea there was a Melbourne in Florida! But after a little sniffing around the AccuWeather website I discovered that they have a "special" syntax for describing "foreign" cities: CountryCode;StateCode;CityName which in the case of Melbourne, Victoria, Australia, translates into AU;VT;MELBOURNE. So, I thought I'd try putting that into the weather widget and bingo! I now have weather for the "real" Melbourne ;-)

I use iSync with my Motorola V3 Phone and my iPod and the new version definitely works better than the old, not to mention synchronising more of my contact details.

And that's about it I think. Oh, the only other observation I'd make is that I do get the impression that the battery-life is a tad longer. That seems strange to me and maybe it's just hope played out as reality but anyway, I'll be curious to see how long that impression lasts ;-)

So, was it worth the price of admission? I'm yet to be convinced. It's all fun geeky stuff but not much substance really when it comes down to it. Certainly most of the new features I could have had already simply by using more mature 3rd-party tools but hey, I'm a technophile so, as much as I'll berate people for wanting to play with cool toys at work, playing with them in the privacy of your own living room is an entirely different story ;-)

November 06, 2004

McAppy Time

Listen to this articleListen to this article

Something appeals to me about the way Mac OS X applications are distributed. Sometimes there is an installer (boo!) but more often than not there is only one "file" to drag into /Applications. I say "file" because although it looks like a single file, it's actually an entire directory structure with a special folder Contents containing meta-info that the Mac OS X GUI understands. Sort of like an unpacked Jar file but for native applications. Best of all, if I decide to remove the application (I've played with about 10 IM clients so far) just delete the application and whoosh, it's gone. In most cases about the only thing left lying around are preferences in ~/Library/Preferences.

So, finally understanding all that, I thought I'd try my hand at building a deployable application - called a bundle. I found a web site that documented most of the steps required. I also found an Ant target that allows you to generate a bundle from a build. The next step was to build an application.

Being the Java Snob that I apparently am, I naturally decided to try deploying a Swing app. The fact that Mac OS X comes with Java out-of-othe-box is pretty cool. What's more the deployment mechanism supports Java apps directly meaning that besides some minor L&F issues here and there, Java applications slide right in amongst native applications.

So, I thought I'd put a "Launcher" GUI on Simian just for fun. Nothing special. Certainly nothing to replace the IDE plugins others have written for. And here's a picture. Makes me want to work on a Swing project even more. Though I believe JavaScript is all the rage now ;-)

One thing I didn't do was specify an application icon but that's as simple as converting an image and dropping it into the Resource folder inside the bundle, something that can be achieved by using the icon parameter on the ant task.

The other thing I need to do is to find an ant task that can create disk images - the standard way Mac applications seem to be distributed.

And finally, just as I was about to post this, I stumbled across a three-part series on making your swing applications play nicely on the Mac.

Not sure if any of this is any better, worse or really just the same as a Jar file. But it's kinda fun in that geeky kinda way.

File system info on the generated application bundle
Bundle Info

November 03, 2004

Mac OS X House Keeping

Listen to this articleListen to this article

Having been a linux weenie for a few years now I had become accustomed to running various house keeping jobs on a regular basis and I wanted to do the same thing on my new PowerBook.

In particular, I use locate for quickly finding files, which to be of any use, requires the the indexer (updatedb) to be run periodically. A quick grep through the man pages and I discovered the OS X version was /usr/libexec/locate.updatedb so the next step was to get it to run as a batch job.

Whilst searching for the appropriate place to put my daily system cron jobs (/etc/daily.local), I ran across this little gem in /etc/daily:

# Clean up NFS turds.  May be useful on NFS servers.