Alastair’s Place

Software development, Cocoa, Objective-C, life. Stuff like that.

License "Cards"

What a neat idea! The authors of the 1Passwd password storage tool have come up with an ingenious and attractive way to present customers with a software license key… “License Cards”.

Here’s a sample (reproduced from their blog post):

SampleUserLicense.jpg

Now I can’t say we’ll be running to support this new style of license key, given that we’ve put a fair bit of effort into our existing set-up. I also take issue with some of the remarks about software activation (especially the one about how programs using it “essentially spy on [their] users”, which, frankly, is both untrue and needlessly inflammatory).

That said, I like the idea of drag & drop license keys. I also like the idea that it’s possible to make them look pretty (in fact, why not offer them with a variety of attractive backdrops?). And whilst it will cause a small amount of pain for users who keep their keys organised in a text file, it will also cause a large amount of pain for software pirates (e.g. the “serialbox” will have to change significantly if it is to cope with these files).

I do wonder whether their technique is based on steganography or simply on public key encryption with data stored in their own JPEG chunks (or in the EXIF information). The former has advantages (e.g. it would be possible, with a good implementation, to print the card out and then recover a usable card by scanning the print-out), and would also be robust against poor storage techniques on the part of the customer (such as filing it in a Word document file). However, it is considerably harder to do, so my guess is that it’s some variation on the latter.

Daft, That's What It Is. Just Daft.

Apparently the Mayor of London, Ken Livingstone, has apologised for “London’s role in the slave trade”.

This is every bit as daft as those people who persist in demanding an apology from the United Kingdom for the slave trade. Why do I say that? Well:

  • The current population of the country have had nothing to do with slavery.
  • The U.K. was instrumental in abolishing slavery in the first place, and indeed the Royal Navy was for some time patrolling the coasts of Africa to stop various other countries’ vessels carrying slaves back to their homelands.
  • The African nations supplying slaves were complicit in the trade themselves.
  • Many (certainly not all, but many) slaves were well treated and in some cases married and had families with their masters. There are plenty of examples of mis-treatment, to be sure, but ignoring those slaves who (or whose families) benefited overall whilst emphasising those who didn’t is at best iniquitous.

Only the stupid would demand an apology, and only the stupid would give one. My estimation of Ken Livingstone has gone down substantially today.

Oh, and if you still can’t see why it’s so silly, let’s ask the Italians to apologise for the Roman Empire (which, incidentally, had lots of slaves). Or how about we ask the Muslim world for an apology for whatever unpleasant acts were committed by their kin during the 7th or 8th centuries in Spain? No?

It actually makes me cross that we have public figures apologising for things like this, because it lends credence to the idea that they should be doing so, and legitimises the demands of some of the groups of people calling for apologies for this, that and the other.

Getting Network Addresses From Python

It’s been irritating me for ages that it isn’t possible to straightforwardly get the network address(es) of the machine you’re running on from a Python program.

Well, if you’re running Mac OS X, or probably some of the various other UNIX-like systems, now you can (here’s the source code).

Here’s a quick example of how to use it:

>>> import netifaces
>>> netifaces.interfaces()
['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']
>>> netifaces.ifaddresses('en0')
{18: [{'addr': '00:12:34:56:78:9a'}], 2: [{'broadcast':
 '10.255.255.255', 'netmask': '255.0.0.0', 'addr': '10.16.1.4'}],
 30: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr':
 'fe80::123:4567:89ab:cdef%en0'}]}

Note that presently this has only been tested on Mac OS X (the SIOCGIFxxx ioctl()s have been tested, apart from SIOCGIFHWADDR, which doesn’t exist on OS X).

Note also that it won’t work on Windows. You’d need to use the Windows Sockets functions to get similar functionality on Windows, I think.

Update (2007/03/18)

It works on Windows now too! There are also pre-built binary versions for Windows (Python 2.4, Python 2.5), and also Mac OS X. But do yourself a favour and use easy_install:

easy_install netifaces

(You can get easy_install from the PEAK Developers’ Center if you don’t have it already.)

The Windows code can currently only return IPv4 addresses and MAC addresses; also, since Windows doesn’t define AF_LINK, I’ve defined it in netifaces for compatibility.

Update (2007/03/20)

I’ve updated the code so that it builds on Windows with MSVC as well as with GCC. Also, I’ve added support for Linux (which lacks the sa_len member in struct sockaddr, making getifaddrs() somewhat harder to use sensibly).

I’ve also build some more binaries:

Python 2.4/Mac OS X 10.4


Python 2.4/Win32

Python 2.5/Win32


Python 2.4/x86 Linux


Python 2.5/x86 Linux

Update (2008/02/24)

Christian Kauhaus pointed out that the PPP interface on Linux sometimes results in a getifaddrs() record with no address, which causes a crash. Also, Python’s egg selection mechanism meant that the Linux binaries were a nuisance for those with older versions of Linux, so I’ve removed them.

Update (2009/03/09)

Olivier Bourdon very kindly contributed some changes to make netifaces work better on Solaris. I have now merged these in, so Solaris users should no longer need to use the separate patches listed in the links below.

I have also build new binaries for Windows users using Python 2.5 and Python 2.6. If you are still running Python 2.4, please use the older links above (the old version works just fine).


Update 2011-10-14

I’ve moved netifaces to its own page. Please go there to download it.

Lunar Eclipse

Last night there was a lunar eclipse, which I was lucky enough to be able to photograph through my telescope. I was a bit concerned that the weather wouldn’t hold, but the only problem I had was significant dewing in the run up to midnight.

Anyway, I combined the images into a single montage, showing the Moon before the eclipse, then in two stages of partial eclipse, and finally in total eclipse. The orange-red colour of the Moon in the latter two stages was really striking, I think you’ll agree.

Lunar Eclipse Montage

Why "Road Pricing" Is a Bad Idea

Here in the U.K., our government has been making noises about “road pricing”, by which they mean a new tax based on the number of miles of road (and the types of road) that you travel using your car.

They claim that this will reduce congestion, however in order to appreciate the real effect of such a scheme you must keep in mind that:

  • Most Britons live away from where they work. This a result of industry consolidation, and of government policies such as the promotion of out-of-town shopping and industrial estates.
  • Congestion happens primarily during “peak periods”, i.e. the times at which people travel to and from work.
  • There is often little or no public transport provision to get people from residential areas to company premises. Even where there is public transport, it often takes a tortuous route, meaning that it takes much longer than travelling by car.

In other words, most of the people affected by road pricing will have little choice other than to pay the tax.

Not only that, but here in the U.K. we already have a pay-by-the-mile road taxing scheme, in the shape of one of the most extreme fuel taxing regimes of any country in the world. Not only does the government take around 50 pence per litre for unleaded petrol, but we actually pay VAT on the fuel tax!. So, of the typical 95 pence per litre we get charged for unleaded petrol today, around 14 pence is VAT, then there’s another 50 pence of fuel duty on top of that, so our government takes 64 pence of the money we pay for every litre of fuel. That’s a whopping 67.5% of the cost of petrol here.

Let’s consider for a moment what that means; say your car does 30 miles per gallon. There are 4.546 litres in an Imperial gallon (not a U.S. gallon, so please don’t try to correct me :-)), so that works out at an effective tax rate of about 10 pence per mile (more for a gas-guzzler). And all this without complicated vehicle tracking systems, extra paperwork, extra loopholes, or indeed any new laws from government.

So, if we effectively already have a by-the-mile charging scheme, why does the government think its new “road pricing” idea is the way to go? Put simply, because the public has already protested at the exorbitant taxes placed on fuel. Our government knows it would never get away with hiking the rate to the kinds of levels that it would like.

And in any case, raising fuel duty or imposing road charging schemes is unlikely to do very much to prevent congestion. Most of the people creating the congestion are simply trying to get to work, and they will continue to try to get to work under almost any conceivable tax regime. Public transport is not fit for purpose; from an employer’s perspective, it cannot deliver employees to the company’s offices reliably and on-time. From an employee’s perspective, it is dirty, unreliable, slow and often late; try to use such a service to get to many jobs in the U.K. and you would be sacked. Indeed, the situation is so bad that in Newbury, Vodafone runs its own bus services!

Increasing fuel duty or creating an expensive-to-operate road pricing scheme in the U.K. can therefore have only one result: inflationary pressure on the pound. The idea that it will have any significant effect on congestion is laughable.

PDFs and NSToolbar

One of the nicest new features in OS X 10.5 (Leopard) is resolution independence. Not only does this pave the way for a zoom feature that doesn’t pixellate as you zoom in, providing a better user experience for partially sighted users, but it also means that as display panel resolutions climb, the Mac OS X UI will stay a usable size and will just start to look much nicer.

So, Apple are trying to encourage developers to make their apps resolution independent. The problem with that, of course, is that it means everything must scale nicely (even to non-integer scale factors), and bitmaps just don’t do that easily. As a result, they’re suggesting that we draw several sizes of bitmap and stick them together into a multi-resolution TIFF.

That’s one way to go, certainly, but it does multiply the effort somewhat; drawing icons is hard enough without having to draw them several times at different scales and detail levels.

Anyway, some of us would rather use vector graphics where possible. (There have been some remarks about this already from the “you should use bitmaps” camp, which was later clarified after some criticism; it isn’t my intention to go into the pros and cons here).

So, away you go, changing your icons for vector graphics (probably PDF, on Mac OS X). For me, this was all working wonderfully, until I hit a stubborn problem. One of my toolbar icons, which looks like this

Go

was being rendered with a white square behind it whenever it was disabled or highlighted; i.e. like this

Go (Disabled) with a nasty white square behind it

This, of course, looks really bad, and I couldn’t work out why it only affected some icons and not others. Anyway, if you’re struggling with the same problem, a workaround is to call -setAlpha: on your NSPDFImageRep, giving the argument YES. The result in my case is that the problem went away:

Go (Disabled)

For people inside Apple, I’ve filed a bug report: rdar://4996913.

Inspector Designs

I’m currently pondering the merits of the two common designs of inspector window, i.e. these two:

Finder’s Get Info panel   Pages’ Inspector

Finder-style “segmented” inspectors use disclosure buttons to show or hide individual segments, whereas the iWork-style inspectors use a toolbar or a strip of buttons to control which page is visible. There are some applications (such as OmniGraffle, which used to use a fancier version of the Finder-style approach) that use a combination of the two techniques.

I’ve started a new page on Cocoadev if anyone would like to express their views on the matter.

How Childish

This made me laugh. The people at info-pull.com (probably LMH) have apparently tried to use their firewall to block me from seeing their site (see the last post on that thread; it’s a firewall rule from their server).

The only reason I can think of for doing this is that they don’t want me to see the bug reports they’re publishing on MoAB, perhaps because they’re worried that some of them might not be accurate and I might pick them up on it.

Of course, I can still see the entire info-pull site, no problem at all, so the only effect of their attempt to block me is that they look childish. Without any proof, LMH will probably claim that I’m lying and can’t really see his site, so here’s a screenshot from today (this hasn’t been edited at all, and came from behind the connection that they’d tried to block):

Incidentally, whilst we’re looking at this page, has anyone else noticed how LMH/info-pull/MoAB are asking for “donations”?

Dumb Programming From Aspyr

When I bought Quake 4 for the Mac, I found that it didn’t work from my normal user account. Why? Well…

If, after you first try to run the game, you look in ~/Library/Application Support/Quake4, you’ll see a folder called q4base. Inside this folder is a bundle, game.so.bundle. The trouble is that Aspyr, who put it there, clearly think that a bundle should contain a folder called contents. It shouldn’t. The folder should be called Contents (note the capital letter ‘C’). And inside it should be a folder called MacOS, not a folder called macos.

Before you say “well you shouldn’t be using a case-sensitive filesystem”, which is exactly what Aspyr said when I reported it to them, my Mac is not using case-sensitive HFS+. My home area is on a server, however, and that server is using a case-sensitive filesystem. Aspyr tried to claim that this wasn’t supported by Apple, but of course it is… Apple make a big song and dance about how good Mac OS X is at integrating with other systems, and most Unix-like server systems use case-sensitive filesystems.

Anyway, you’d hope that they’d fix this problem, as it’s only a case of renaming a couple of files, right? But no, it’s still not fixed in the just released Prey Demo. So, if you want to get Quake 4, or Prey, or either of the demo versions working and your home area is case sensitive, here’s what to do:

  • Run the game once. It will display its splash screen and then terminate (because it can’t load the bundle, because the bundle is invalid, because the names of the internal folders are wrong).
  • Go to ~/Library/Application Support/name of game/q4base.
  • Right-click game.so.bundle.
  • Choose “Show Package Contents”.
  • Rename “contents” to “Contents”.
  • Open the “Contents” folder.
  • Rename “macos” to “MacOS”.
  • Run the game.

The most stupid thing about this entire business is that the one case-sensitivity bug in these games was added by Aspyr! The Windows programmers involved with them got it right, but the Mac programmers, whose operating system does support case-sensitive filesystems, got it wrong.

(By the way, if you use this technique, you’ll need to re-apply it if you download an update for either game.)