« January 2007 | Main | March 2007 »

February 17, 2007

Chaucery gets shinier

The .php pages on chaucery.com are now processed by PHP5 instead of PHP4. This is a beta service offered by my host, but I don't expect that'll lead to any problems. The first PHP5 beta came out in June 2003, but it's good to let software settle down with a few bugfix releases before switching.

My main incentive to update was to be able to use SQLite 3, which offers smaller, faster databases than SQLite 2. My Crossword Tools database has indeed shrunk from 8MB to 5MB, but it seems a trifle slower. I had to rewrite some of the database access code to use PDO instead of SQLite specific calls, and I hope that further tweaking may bring the speed back. (PDO lets you use SQLite 2 as well as SQLite 3. Thus I can use identical code to compare the databases, and I find the SQLite 2 is 3 times faster than SQLite 3. This is certainly not expected, and I shall have to explore further.)

The only other problem with the upgrade was that my Asciifier page went blank. This was relating to the page compression, which was necessary on such a potentially large page. To fix it I replaced:

header('Content-Encoding: gzip'); with ob_start("ob_gzhandler");

It seems to work okay now.

Update 18 Feb: After some tweaking of the order and composition of the statements in the WHERE clause of my crossword tools SQL code I have got the speed of the SQLite3 database to within cooee of the SQLite2 database. It's now faster than it used to be, so that's a good result.

February 10, 2007

Australian Weather Chart now live

Charting your way to successI have put my Weather Chart page live, amongst the assorted other online knick-knacks in the fun section of this site. It displays the last 72 hours of temperature and rainfall data for the weather station of your choice in Australia.

The data is made freely available by the Australian Bureau of Meteorology, but as their XML feeds are not expected until after the middle of 2007 I had to screen-scrape HTML for the particular aspects I required. I cache this data for 15 minutes, so the charts won't refresh faster than that.

Currently only the capital city weather is easily selectable. For other locations you have to wander through the BOM site and find the URL for the station you want. For example, to find all the stations in Western Australia, you could go via:

  • WA in the top-right navigation bar, then
  • Western Australian Weather and Warnings
  • Western Australian Observations
  • Latest Weather Observations for Western Australia
From here you can click the station of your choice, and that URL is what you should enter into Weather Chart.

Weather Chart was designed with manual entry of URLs because I'm not sure how permanent the URLs are, and because there is no good long list of them for the program to grab. When the XML feeds come into effect I'll look at making this more user-friendly.

Update 16 Feb: Moved programming description to earlier post.

February 9, 2007

Set Windows theme on logon

In Windows it is possible to set the theme from the command line, instead of using the Themes tab of the Display Properties control panel applet. This makes it amenable to scripting, which can be useful when your theme settings are not saved after you log out, for whatever reason.

If a shortcut to the following WSH script was placed in your startup folder, then the given theme would automatically be loaded when Windows started. Note that you must have previously saved your desired theme, and that you must edit the script to point to this saved theme.

//===================================================================
// FILE: theme.js
// DESCRIPTION: automatically set the Windows theme
//===================================================================

// create shell object
objShell = new ActiveXObject("WScript.Shell");

// start themes applet, load desired theme, and activate this window
objShell.Run('rundll32.exe Shell32.dll,Control_RunDLL desk.cpl desk,@Themes /Action:OpenTheme /File:"C:\\temp\\Happy.theme"',1);

// wait for themes window
WScript.Sleep(1600);

// send the 'enter' key to accept this theme
objShell.Sendkeys("{ENTER}");

As themes encompass Window appearance, this method will also set 'Windows and buttons' in the Appearance tab to 'Windows XP style' or 'Windows Classic style'. There may be an easier method to do just this change without loading a whole theme, but I could not find any official documentation for the Shell32.dll options.

Update 12 Feb 2007: The obvious way of just changing the 'Windows and buttons' from Windows Classic to Windows XP style is by emulating keypresses. XpStyle.js does that, and also changes from Default (blue) to Olive Green. If this is the only outcome you are after, then this method is preferable to changing the theme because that requires the use of a saved theme, and because themes store much more than just the Windows and buttons style.

February 4, 2007

PHP Graphing

In the past I've used the GD library in PHP to manually create graphs. For example, the bar charts that regularly appear in this blog are formed on the fly by a specially created program. However, it's often quicker and easier to use graphing libraries that other people have made available, especially if your graphing requirements are relatively standard.

The most full-featured for graphing library for PHP appears to be JpGraph, which is free for non-commercial use. Oddly, its excellent html-formatted manual is not provided officially online, but only as part of the JpGraph download. This would probably put off a number of people who like to see proper documentation before they go to the trouble of downloading and installing a package. If you do a Google search for "jpgraph manual 2005" you may find a copy hosted elsewhere.

Another potential disincentive to using JpGraph is its size. It's a 5MB download, which uncompresses to 9MB. However, much of that won't be necessary to install onto your live site, as it includes documentation, images and library code. To work out what you do need, just upload your script that references JpGraph, but don't upload JpGraph itself. Then, when you run it, an error message stating the files which are missing will be displayed. Just install those files, and try again. For my project, that whittled it down to a very reasonable amount of just over 300 kB.

As for JpGraph itself, it is an excellent product. It's easy to use, highly configurable, and has the best documentation that I've seen in a long time.

Update 16 Feb: I have used JpGraph to produce my new Australian Weather Chart tool. Although I could have built the charts from scratch, to create something as complex as the Weather Chart, I'd be tweaking it for weeks, and even then I'd just have to start from scratch again for the next one. Another point to note is the extreme customisability of JpGraph. It let me overlay the rainfall bar chart on top of the temperature line chart with no fuss, and happily provided two y-axes for these measurements. In addition, the plethora of formatting options ensured that any ugliness in the graph was entirely my fault. Finally, the extremely simple method of using caching ensured that no programmer would have an excuse not to use it.