Multiple instances of the iiNet Usage Widget

There is a very handy usage widget for iiNet available at LemonJar. However, the way it stores its preferences for iiNet account and password means that you can’t run multiple instances of the widget to monitor multiple iiNet accounts.

This patch fixes it so you can:

--- MAIN.js.ORIG    2007-11-08 11:35:07.000000000 +1100
+++ MAIN.js 2007-11-08 11:33:59.000000000 +1100
@@ -144,14 +144,18 @@
 
 }
 
+function keyForUsername() { return widget.identifier + "-" + "userName"; }
+function keyForPassword() { return widget.identifier + "-" + "psword"; }
+function keyForAlertCol() { return widget.identifier + "-" + "alertColorOn"; }
+
 //Read in Username & Password Stored in OS .plist. Updates Global Variables.
 function readPrefs(){
    debug("Function: readPrefs() run.");
 
    if(window.widget) { 
-       var TMPuserName = widget.preferenceForKey("userName"); 
-       var TMPpsword = widget.preferenceForKey("psword"); 
-       var TMPalertColorOn = widget.preferenceForKey("alertColorOn"); 
+        var TMPuserName = widget.preferenceForKey(keyForUsername()); 
+       var TMPpsword = widget.preferenceForKey(keyForPassword()); 
+       var TMPalertColorOn = widget.preferenceForKey(keyForAlertCol()); 
 
        if ( TMPuserName && TMPuserName.length > 0) { 
            userName = TMPuserName;
@@ -199,10 +203,10 @@
    alertColorOn = document.getElementById("alertColorPref").checked;
 
    if(window.widget){  
-       widget.setPreferenceForKey(document.getElementById("userNamePref").value, "userName");
-       widget.setPreferenceForKey(rot13(document.getElementById("pswordPref").value), "psword");
-       widget.setPreferenceForKey(document.getElementById("alertColorPref").checked, "alertColorOn");
-   }   
+      widget.setPreferenceForKey(document.getElementById("userNamePref").value, keyForUsername());
+      widget.setPreferenceForKey(rot13(document.getElementById("pswordPref").value), keyForPassword());
+      widget.setPreferenceForKey(document.getElementById("alertColorPref").checked, keyForAlertCol());
+   }
 }

LemonJar also make widgets for other Australian ISPs. I suspect this patch would also work for those widgets (on the assumption that the code in MAIN.js is common), but I haven’t tested it.

For what it’s worth, I filed a bug in their issue tracker.

Another patch for pyblosxom entrycache - normalised keys

The entrycache plugin uses the absolute path of a file as the key for caching its date. This is problematic if the file is moved (e.g. your data dir is different locally to on your web server).

This patch normalises the key to remove the “datadir” component. It also cleans up how the cache is written to disk:

diff --git a/entrycache.py b/entrycache.py
index 0cc3196..b46f89d 100644
--- a/entrycache.py
+++ b/entrycache.py
@@ -52,19 +52,18 @@ def cb_filestat(args):
    request = args["request"]
    data = request.getData()
    cache = data["cache"]
-   if cache.has_key(args['filename']):
+   config = request.getConfiguration()
+   key = args['filename'].replace(config['datadir'], '')
+   if cache.has_key(key):
        mtime = []
        for i in args['mtime']:
            mtime.append(i)
-       mtime[8] = cache[args['filename']]
+       mtime[8] = cache[key]
        args['mtime'] = tuple(mtime)
    else:
-       cache[args['filename']] = args['mtime'][8]
+       cache[key] = args['mtime'][8]
        f = open(data['cachefile'],'w')
-       f.write("{\n")
-       f.write("\t'%s' : %i,\n" % (args['filename'], \
    args['mtime'][8]))
-       for i in cache:
-           f.write("\t'%s' : %i,\n" % (i, cache[i]))
-       f.write("}")
+       import pprint
+       pprint.pprint(cache, f)
        f.close()
    return args

I’ll get around to publishing my git repo of this soon.

Leopard breaking MacPorts git over ssh

As I have been twitting recently, git over ssh stopped working for me after the upgrade to Leopard:

$ git pull
percent_expand: NULL replacement
fatal: The remote end hung up unexpectedly
Cannot get the repository state from ssh://git.mojain.com/...

A quick google search quickly turned up the answer. The problem was not with git, but with ssh. Spefically, ssh from MacPorts. It’s worth noting that ssh in OS X 10.5 is not broken (which made my intial trouble-shooting harder, as ssh-ing from the command line worked just fine). But git in MacPorts is:

$ which ssh
/usr/bin/ssh
$ ssh git.mojain.com
Last login: Mon Oct 29 20:17:47 2007 from ...
$ ^D

$ /opt/local/bin/ssh git.mojain.com
percent_expand: NULL replacement

You can follow the google results above for the details, but essentially it seems that two things cause the git problem:

  1. Leopard changed some environment variables that caused the MacPorts version of git to get a NULL when it tried to determine what “identity” to use.

  2. git looks for ssh in the same directory as the git binary, causing it to find the MacPorts version before the “native” OS X version.

There are a number of ways to work around this problem (all found in the aforemetioned google results):

  1. Set GIT_SSH to the OS X version (/usr/bin/ssh). This works for git only of course.

  2. Rename your ssh key files so MacPorts ssh can find them (I didn’t try this).

  3. Tell ssh which key file to use by adding the following line to $HOME/.ssh/config (creating that file if it doesn’t exist):

    IdentityFile ~/.ssh/id_dsa

This last option is the one I chose, as it has the advantage of working for all versions and invocations of ssh, and is probably a good idea anyway. Presumably the MacPorts ssh package will be fixed at some point, but this is working for me now.

Patch for pyblosxom entrycache plugin to make cache location configurable

The entrycache plugin for pyblosxom is really cool. I only wish I could configure the location of the file it uses to store its cached dates.

So here’s patch:

--- a/entrycache.py
+++ b/entrycache.py
@@ -21,24 +21,31 @@ __url__ = "http://joe.terrarum.net"
 
 import os.path
 
+def _get_cache_filename(args):
+   request = args["request"]
+   config = request.getConfiguration()
+        if config.has_key('entrycache_cachefile'):
+                return config['entrycache_cachefile']
+        else:
+                return os.path.join(config['datadir'],'.entrycache')
+
 def cb_start(args):
    t = { }
    request = args["request"]
-   config = request.getConfiguration()
    data = request.getData()
-   if os.path.isfile(os.path.join(config['datadir'],'.entrycache')):
-       data['cachefile'] = os.path.join(config['datadir'],'.entrycache')
-       f = file(os.path.join(config['datadir'],'.entrycache'))
+   if os.path.isfile(_get_cache_filename(args)):
+       data['cachefile'] = _get_cache_filename(args)
+       f = file(_get_cache_filename(args))
        t = eval(f.read())
        f.close()
         data['cache'] = t
    request.addData(data)
 
    if not data.has_key('cachefile'):
-       f = file(os.path.join(config['datadir'],'.entrycache'),'w')
+       f = file(_get_cache_filename(args),'w')
        f.write("{ }")
        f.close()
-       data['cachefile'] = os.path.join(config['datadir'],'.entrycache')
+       data['cachefile'] = _get_cache_filename(args)
        request.addData(data)
 
 def cb_filestat(args):

Then add a line like this to your pyblosxom config:

py["entrycache_cachefile"] = \
    "/Users/mrowe/Sites/blog/data/.entrycache"

Making PHP work after Leopard upgrade

Sure enough, PHP didn’t work after upgrading my mac to Leopard. Easy to fix though:

$ diff -u /private/etc/apache2/httpd.conf.ORIG /private/etc/apache2/httpd.conf
--- /private/etc/apache2/httpd.conf.ORIG	2007-10-29 20:25:54.000000000 +1100
+++ /private/etc/apache2/httpd.conf	2007-10-29 20:26:08.000000000 +1100
@@ -111,7 +111,7 @@
 LoadModule alias_module libexec/apache2/mod_alias.so
 LoadModule rewrite_module libexec/apache2/mod_rewrite.so
 LoadModule bonjour_module     libexec/apache2/mod_bonjour.so
-#LoadModule php5_module        libexec/apache2/libphp5.so
+LoadModule php5_module        libexec/apache2/libphp5.so
 #LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so

and then

apachectl graceful

Perhaps surprisingly, MySQL (installed from the “official” package) continued to work without a hitch.

Making "personal web sharing" work after Leopard upgrade

My upgrade to Leopard has gone mostly well (if you don’t mind waiting half a day for spotlight to index everything, then another half a day for time machine to do its first back up). But tonight I tried to access my “personal website” via the local Apache server, and got a “Forbidden” message.

It turns out Leopard includes Apache 2.2 (up from the 1.3 in Tiger) and its configuration now lives in

/private/etc/apache2 

(not /private/etc/httpd as in Tiger and earlier). However, the upgrade did not bring across my user configuration file (/private/etc/httpd/users/mrowe.conf).

The following commands fixed this for me:

cp /private/etc/httpd/users/mrowe.conf /private/etc/apache2/users/
echo 'Include /private/etc/apache2/users/*.conf' >> /private/etc/apache2/httpd.conf
apachectl graceful

(Obviously you would use your short username where I have “mrowe”.)

I haven’t tried PHP yet…

Update: it turns out adding that Include /private/etc/apache2/users/*.conf line to httpd.conf is not necessary. It is taken care of by the line:

Include /private/etc/apache2/extra/httpd-userdir.conf

earlier in httpd.conf that I hadn’t noticed. You still need to copy your user.conf from /private/etc/httpd/users to /private/etc/apache2/users.

Job search update

My job search experiment is sitting at about one and a half for four at the moment.

Of the four recruiters who received my letter, two were small independents and two were larger national companies.

The person I spoke to at one of the larger companies completely failed to get it, and asked the usual “so how many years of websphere experience do you have?” questions. *plonk*

I had a bit more luck with the other large shop, ending up speaking to their national manager, presumably because I was “too hard” for the front line folks. :) We had a promising conversation, but nothing concrete yet.

Of the two independents, one said he would “keep his eyes out”, which is actually a satisfactory result–a lot better than “no worries, I’ll try and push you in to whatever crap I have on the books right now”.

The other has come through with an interview for a reasonable-sounding job. The company appears to be a combination of in-house and customer-facing work. I don’t know much yet, but current employees rave about the place in their blogs.

More news as it happens!

Playing the job search game

I want a new job. And I want one that doesn’t suck. So doing the regular browse-the-job-boards-and-ring-recruiters dance didn’t appeal.

Instead, I sent this letter (lightly personalised) to a small number of the less sucky recruiters I know:

Dear [Recruiter],

I’d like to ask for your help in my search for the “perfect” development job.

As you can see from my resume at http://www.mojain.com/michael/resume, I’m currently employed as a Java developer (on a rolling contract), but am I looking for something better.

By better, I mean some fairly specific things:

I will be working at a product company. That is, a company that produces software as (one of) its primary activities. I am not interested in jobs in corporate IT shops or consulting companies.

I will be working with other enthusiastic developers who have a similar attention to detail and a commitment to doing things the right way. The organisation’s management will realise that a tightly constrained development environment is not usually the way to get the best out of skilled developers. And they’ll care about doing things the right way too.

I would prefer to work on back-end, infrastructure or framework software, but I have experience in front end web development too.

My perfect job would offer flexible work arrangements, ideally including the option of working at home at least some of the time. I’m not interested in a company that thinks the most important thing is that I’m sitting at a desk looking busy during “office hours”.

I know I haven’t said much about myself and what I offer here. I want to narrow down my search to jobs I’d actually consider taking before wasting everyone’s time talking about myself.

Thanks for listening, and I look forward to working with you on my search!

I’ll let you know what happens next… :)

Why EJBs are like lobsters

I should probably have included a link to this article with my email to recruiters…

Twitter and blogging

I was never exactly a blogging over-achiever, but I can’t help noticing that I’ve been even quieter here than usual, since discovering twitter. I guess being able to blast out anything I’m thinking in a sentence or two acts as a sort of pressure release, and the “head of steam” necessary to actually blog (that’s a verb now, right?) something is never able to build.

Must Try Harder. Thanks for the nudge, Daniel.

Oh, what am I doing right now? Consolidating dozens of email folders I thought I used to “organise” my email (i.e. spend too much time deciding where to file it and never look at it again) into a small number of actually-useful folders. Well, maybe-useful… we’ll see how it goes.