jump to navigation

Design genius March 23, 2010

Posted by Peter Hornby in tech.
add a comment

From the Why Didn’t I Think Of That category, noted by John Naughton from a report in The Guardian.  The young man presenting this video, Min-Kyu Choi, graduated from the Royal College of Art last year, and was awarded Britain’s most prestigious design prize last week.  A company has already been set up to market the device.

A quadrillion dollars in debt July 15, 2009

Posted by Peter Hornby in software, tech.
3 comments

After an unconscionable period of quiet, the blog bursts into life with a post which will probably only be of interest to a small subset of my vast reader audience.

The BBC reported today that some poor guy in New Hampshire discovered that his bank had debited his account by $23 quadrillion dollars after he bought a packet of cigarettes at a local gas station.

The story concludes:

But no-one has yet explained to Mr Muszynski how such a astonishing error could have been made.

I’m here to help.

The amount quoted in the story is $23,148,855,308,184,500.00

Type eight space characters into a text editor.  It’ll look like  ”        ” on screen (minus the quotes, of course).  What has the computer stored in memory?  If your text editor uses the ASCII character-encoding scheme, you’ll get 3264 bits which look like this when represented hexadecimally – “2020202020202020”.  Each “20” is the ASCII representation of a space character.

Here’s where it gets interesting.  Suppose you tell the computer that this memory location doesn’t contain a string, but a decimal value, what do you get?  The answer is 2314885530818453536.  I’m not sure how the bug manifested itself, but it seems likely that some memory location which was supposed to contain the number of cents in the debit amount was actually overwritten with a text string which was all, or almost all, spaces.

Oh well, geek credentials established.  Now back to hummingbirds and choral music.

Updated: Peter points out in comments that eight spaces take 64 bits, not 32.  Indeed they do (slaps forehead in annoyance).  He also points out that “2020202020201250” converts exactly to the correct decimal value, and wonders whether the pack of  cigarettes cost $12.50.  Maybe.  Thanks for the notes, Peter.

IIS7, PHP and WordPress on Vista May 12, 2008

Posted by Peter Hornby in tech.
2 comments

I spent a substantial part of the weekend getting WordPress running on my laptop. There was actually a good reason for this, other than my strange attraction to hitting myself over the head with a brick. Actually, I’m planning to set up a blog for the Saddleback Master Chorale in the next couple of weeks, and I thought that it would be useful to develop some experience with the non-hosted version of WordPress. What made the effort somewhat more challenging was that my laptop runs Vista, so I decided to use IIS7 to host the WordPress installation.

Many people have blogged aspects of this challenge, and I wouldn’t pretend that this is the canonical story. But there were some pieces of the puzzle which caused me more trouble than I expected, so I’ll try to concentrate on those.

Installing IIS7

IIS is not installed by default on Vista, so you have to go to the “Turn Windows Features on and off” selection in the “Programs and Features” control panel. The key thing to remember is to make sure that you’ve enabled the CGI feature while you’re checking IIS options.

Finding and installing FastCGI

Many people recommend using Microsoft’s FastCGI if the application framework you’re using supports it,as PHP does. Reusing Windows processes is a big performance win, and there are reliability benefits too, especially since FastCGI is thread-safe. So how do you get FastCGI? If you’re running Windows Server 2008, you’re in good shape, since FastCGI is bundled, but Vista is another story. Microsoft released a technical preview version of FastCGI last year, but that’s now gone, and it’s now only available as part of Vista SP1. And that was my first problem – how to get hold of Vista SP1.

Finding Vista SP1

Windows Update, you’d think. Not so fast, sparky. Microsoft says that they’re rolling out Vista SP1 gradually through Automatic Updates, but if you want to jump the line, you can manually scan for updates. I did that. No sign of SP1. Luckily, there’s a KB article which addresses the problem, offering seven possible reasons why SP1 is not offered by Windows Update even after a manual scan. Actually, it’s really six, since Cause 1 is “You’re already running SP1”. The two possibilities which seemed pertinent were Cause 5 – “SP1 won’t be offered if Windows detects that you have device drivers which might cause problems with SP1” – and Cause 7 – “SP1 won’t be offered if other Windows updates are offered – it needs to be installed as a single update operation”.

So I spent a couple of hours addressing these points, with no success. More scrabbling around in Google turned up another KB article which, while describing the ways SP1 can be obtained, referred to the need to update the Kernel Streaming driver (ks.sys) before updating to SP1, since the older driver version can cause a crash during the update process. This driver comes into play, I think, with the Logitech webcam on my Dell XPS M1530 laptop. The ks.sys update was made available in early April as a Microsoft download. I updated this driver, and suddenly SP1 appeared in the Windows Update list.

So let’s move on to the real work.

Downloading and installing MySQL

I Installed MySQL 5.0, and used the command-line configuration tool to create a user and a database, as described in the WordPress installation instructions. That at least was simple enough.

Downloading and installing PHP

I downloaded PHP 5.2.6, and installed it in C:\inetpub, as recommended by Scott Hanselman in his essential screencast on getting PHP working with IIS7 and FastCGI. The next step is to use IIS Manager to create a handler mapping to have IIS route .php files to the FastCGI module. This stuff is all covered by Scott Hanselman and also by Ryan Dunn’s screencast on Channel 9. Note that if you’re out for performance, there’s significant benefit to be had from using the non-threadsafe version of PHP, since FastCGI ensures that requests are single-threaded through service processes. The PHP core is threadsafe, as are most PHP extensions, but there are third-party extensions which aren’t, and there can be instabilities if you use a non-threadsafe PHP with the ISAPI interface. See the relevant entry in Mike Volodarsky’s blog for more.

Configuring PHP

There are a number of steps you need to take here, and you’ll be editing the php.ini file. The main work is to wire PHP up to MySQL. You need to tell PHP where its extensions directory is (the extension_dir option) and you need to make sure that the reference to the MySQL extension (extension=php_mysql.dll) is uncommented. One final thing, which caused me substantial headscratching, is to tell PHP where to look for this php.ini file. You’ll need to create a registry key (HKLM/Software/PHP/IniFilePath) to hold this location, and then restart IIS to have PHP read it. The PHP documentation for this is here. Check that PHP is loading the correct .ini file (and that PHP is wired up properly) by browsing to http://localhost/phpinfo.php.

Installing WordPress

I installed WordPress 2.5.1 into C:\inetpub\wwwroot\blog. The wiring between WordPress and the MySQL database you created earlier is done in wp_config.php. Here’s how the relevant piece of the file should look.

// ** MySQL settings ** //
define('DB_NAME', 'putyourdbnamehere');    
define('DB_USER', 'usernamehere');     
define('DB_PASSWORD', 'yourpasswordhere'); 
define('DB_HOST', 'localhost');

And, then, browse to http://localhost/blog/wp-admin/install.php, and after a couple of install forms, you should have a running blog.

I wish you luck!