Archive for the 'JavaScript' Category

In search of an Adobe Reader alternative on Mac

Wednesday, July 2nd, 2008

I’m looking for an alternative to Adobe Reader on OS X after discovering its “Find” function can’t find jack.

As I’m still running Tiger (OS X 10.4) I find Preview to be a tad lacking in usability - if only the ‘Maximize’ button maximized height and width, I’d be happy. But no, it’s a typical Mac-spastic application - maximize makes the application full-height, but doesn’t change the width. If you’re viewing a PDF using “Fit to Width”, this means the text-size stays exactly the same… which is never what I want.

If only Foxit Reader worked on Mac, I’d be using that (it’s a damn nippy and reliable piece of software on Windows.) But sadly it doesn’t - I even downloaded the Linux version, you know, just in case it worked on OS X (being a *nix ‘n all.)

So, I’m currently taking a look at PDF-XChange Viewer which comes in a couple of different versions. They provide a wee comparison chart to help you choose which version of their PDF viewer to download - but guess what format the chart’s provided in. You guessed it: PDF.

That doesn’t give me much confidence…

Amazon’s bizarre “Free HDMI cable” deal

Friday, February 29th, 2008

Sony don’t include an HDMI cable with the UK’s PlayStation 3 console (40GB version). But, if you buy it from Amazon, they’ll give you an HDMI cable free - if you ask for it.

As Jacob Nielsen (usability expert) said: Amazon is no longer the role model for e-commerce design. I totally agree. I completely missed the opportunity to get a free HDMI cable, and I blame their UI.

It’s my own fault. I’ve become a bit lazy, and trust Amazon to do the right thing. I buy stuff from them quite regularly, and the only thing I really check is (a) the price, and (b) is it really being sold by Amazon (or one of their market-place sellers.)

I missed seeing the offer completely! As I write, Amazon are flogging the PS3 for £279. Right below it they show an HDMI cable as a “perfect partner” - to buy with the PS3 for £299.98 - i.e. it looks like the cable costs £19.99.

I may be a cheap-skate, but I wouldn’t spend £20 on a random cable - I’d either buy as cheap a no-name brand as possible (£5 or £10), or double-up and spend £40 on a brand I trust (QED or Ixos.)

Anyhow. It turns out that if you go for the £299.98 deal, Amazon take the £20 off at checkout time… you don’t even have to mail-in a rebate form. I find that a little misleading… on the one hand it’s great that they’re giving away a free HDMI cable - and on the other, they’re pretending it’s not.

I guess I’m just miffed because I didn’t read the small-print and completely missed the deal. I’m said to say I lost a little faith in Amazon today.

If they’d surprised me with the cable I’d be delighted, and shout their praises. As it is, I’m a little saddened, and feel I have to pore over every product page in future. My casual shopping days are over.

Upgrade your new Macbook Pro’s memory yourself, and earn a free iPod (or two)

Friday, June 29th, 2007

Apple are marking the launch of the iPhone by keeping all their US stores open from 6pm till midnight. I suspect the sales-process will be slow (since contracts need to be signed) and the stores will be full of people picking up random goods just to pass the time.

Not that this has anything to do with the iPhone, but if you’re going to buy a MacBook Pro with the full 4GB memory you have to make a decision:
1) MacBook Pro with 4GB memory installed by Apple
2) MacBook Pro with 4GB memory you installed, PLUS an 80GB iPod Video, PLUS an iPod Shuffle

It’s your choice. Installing memory is a piece of cake: pop the battery out and take off the memory cover (4 screws), replace old memory with new memory, then put the cover and battery back on. All in, it’s a couple of minutes.

So, the Maths: (with an ‘S’, because I’m English.)

UK Price US Price
Apple Upgrade Charge (2GB to 4GB) £480 $750
4GB memory (from Crucial) £180 $279
Saving £300 $471

That’s some juicy saving… Let’s buy some iPods:

UK Price US Price
Apple iPod Video 80GB £239 $350
Apple iPod Shuffle £49 $79
Total £288 $429
Remaining Savings £12 $42

Even after buying two iPods, you still have money left from your savings to buy drinks to celebrate.

Now I’m not going to moan about the rubbish exchange rate being used - I think we’re accustomed to being stiffed in Britain; but I will say something in Apple’s defence: they’re not alone. Dell also charge similarly extortionate prices for memory upgrades on their laptops. I’m not been writing about Dell for two reasons: (1) I’ve no idea if their laptop memory’s as easy to replace, and (2) they don’t make iPods.

And finally. Back to the iPhone. Instead of blowing your $470 savings on iPods, you could always use it for the majority payment of your iPhone (whether it be the $499 or $599 version.)

Good luck to those of you trying to get your grubby mitts on an iPhone tonight.

UK Petition: Ban the Bog Troll

Thursday, May 31st, 2007

Officially known as bathroom attendants, the bog troll lurks in bars and clubs, interrupting customers’ casual hygiene routine by obstructing sinks and hand-dryers and extorting money for performing such mundane tasks as turning on taps and distributing paper towels.

The bog troll is a menace. The bog troll does not encourage hygiene, it prevents it. Once the third-pint breaks the seal, regular users have no wish to pay an extra pound to offload their processed beer. With typical British manners, bathroom visitors are put in an uncomfortable position: wash their hands tax-free and risk offending the troll; or leave the bathroom unclean, hygiene-be-damned.

Many customers choose the latter. Damn you Bog Troll! Damn you for hoarding the paper towels. Damn you for covering three sinks with CK One. Damn you and your tray of Chupa Chups.

Please help us regulate this scourge, sign the Ban The Bog Troll petition at Downing Street.

This has been a public service announcement. Thank you.

Official Site: Ban The Bog Troll

sprintf for JavaScript

Wednesday, March 14th, 2007

Avoid writing formatting functions in JavaScript by grabbing yourself a decent sprintf implementation - handling padding, truncation, floating-point numbers, left/right alignment and re-ordered arguments.

You can download sprintf for JavaScript, available under the Create Commons Attribution License. Now license free (use it where/when/how you like.)

The version I’ve written is based strongly on Perl’s sprintf implementation, allowing argument reordering to help with internationalisation (i18n). Some overly simplistic examples follow, leaving room for obvious improvements like:

  1. letting the user specify their locale as a preference
  2. set default locale based on visitor demographics
  3. use locale-specific message-bundles with a fall-back to the default locale

On with the examples:

var locale = 'es';
var messages = {
    'en': 'I am %d years and %d months old.',
    'es': 'Tengo %2$d meses y %1$d años.'
};
var message = sprintf(messages[locale], 31, 7);

You could also use it for

var date = new Date;
var dateFormats = [
    /* ISO-8601: */ '%04d-%02d-%02d %02d:%02d:%02d',
    /* British:  */ '%3$02d/%2$02d/%1$02d',
    /* U.S.:     */ '%2$02d/%3$02d/%1$02d'
];

// for example only: choose random date format
var dateFormat = dateFormats[3 * Math.random() >>> 0];

var formatted = sprintf(dateFormat,
    date.getFullYear(), date.getMonth() + 1, date.getDate(),
    date.getHours(), date.getMinutes(), date.getSeconds());
alert(formatted);

The Perl documentation has more examples in the “order of arguments section“.
Note: this implementation allows the precision of a number to be set from a specific argument (using e.g. “%.*3$f”), which the perldocs (perldoc -f sprintf) say hasn’t been implemented yet.


I haven’t (re)written any documentation for it, but you should be able to use Firebug (or the javascript: protocol) to try out sprintf on this page, and you can also check out the test page for sprintf for more input/output samples.

As usual, writing test-cases uncovered a couple of browser-dependent issues. Safari has some bizarre behaviour with Maths.abs(0).toFixed(6) resulting in "0.0000-0" instead of "0.000000". Another issue I came across is that 0.5 rounds to 0 or 1 depending on browser (worded differently: numbers are rounded off inconsistently across browsers.)

Dependencies

On modern browsers, there are no dependencies. But to run sprintf on older browsers you’ll need to patch the Number and String objects. Number needs toFixed, toExponential and toPrecision methods, while String needs a replace method capable of using functions in the replacement parameter.