Connected Numbers

I was recently shown this puzzle: There are some things I found a little unclear about it. For example, should the following two circles count as being connected? There is a line between them, even if it’s interrupted by a circle. And what about these two circles? Are they connected? Again, there’s a diagonal line … Continued

Horizontal Reuse: An Alternative to Inheritance

In class-based object-oriented programming, when there are classes that appear to share some functionality, this is often a time when people will refactor them into two subclasses of a common base class, avoiding repetition.

For example, in my farm model the Horse class and the Tractor class each implement a pull_plough method. (American readers might prefer pull_plow.) So this method is a candidate to split out into a Hitchable class for Horse and Tractor to each inherit from.

This would have nice benefits for polymorphism. I’ll be able to pass an object to my Farmer which will only need to check that the object inherits from Hitchable rather than having a hard-coded list of classes like Horse and Tractor that it knows are acceptable.

Cognition 0.1 Alpha 6

Tonight I've released another alpha version of Cognition, my semantic web parser. Changelog includes: Microformats: Add option (disabled by default) to require <head profile> for microformat support. Microformat profiles are treated as opaque strings! Supports the following profiles: http://purl.org/uF/2008/03/ http://www.w3.org/2006/03/hcard or http://purl.org/uF/hCard/1.0/ http://dannyayers.com/microformats/hcalendar-profile or http://purl.org/uF/hCalendar/1.0/ http://purl.org/uF/hAtom/0.1/ http://purl.org/uF/rel-tag/1.0/ http://purl.org/uF/rel-license/1.0/ No profiles required for rel-enclosure, adr or … Continued

CSS to HTML Compiler

I’ve searched around the ‘Net for something like this before, but without success, so decided to write my own. The basic idea is this: there are certain circumstances in which you need to write some styled HTML without access to the document’s header. For example, when composing HTML-formatted e-mails, which may be displayed in a … Continued

dhyana.pl/0.3

Here’s my latest update to dhyana.pl… Change Log Added a title to the output image, which can be in a different font and colour from the rest of the text. Use Getopt to parse command line, and accept more options. Improved handling of certain dodgy WMV files, mostly thanks to Matt Pinkham. Improved use of … Continued

Dhyana.pl Updated

This release works around errors in capturing screen shots from certain WMV files. It also changes the default geometry from 240×180+0+0 to “auto” which is an automatically calculated, hopefully appropriate, geometry. Download dhyana.pl Highlighted source code

Sequential Video Thumbnails on Linux

So, I was looking for a way to create sequential video thumbnails (like this one) from a video file on Linux. I found that my options were severely limited. On Windows there are a plethora of tools capable of this fairly simple task, including Media Player Classic, but on Linux all I could find was … Continued

PHP Domain Class

On Usenet an often-asked question is how to programmatically determine the “domain” of a particular hostname. That is, excluding the components traditionally thought of as subdomains. As an example, groups.google.com and www.google.com both have a domain of google.com. Invariably, one answer comes back stating that you just need to chop off everything from the front, … Continued

PHP vs Perl

Here's a simple program which calculates, to eight decimal places, the value of the Golden Ratio φ implemented in both PHP and Perl, to demonstrate their similarities. Perl #!/usr/bin/perl $a = 1; $b = 1; $c = undef; $psi_old = undef; print “Approximating psi…\n”; while (1) { $psi = sprintf(‘%.08f’, $b/$a); last if ($psi_old eq … Continued

The Importance of Software Testing

Most programmers, especially those who work on server software, will have been in a situation when we’ve been reconfiguring, upgrading, modifying or otherwise replacing some piece of vital software on a physically remote server, and things haven’t gone quite as expected. Often, fixing it is a simple matter of logging into the server remotely (via, … Continued

How PHP programmers get things wrong

Firstly, three disclaimers: PHP is a great programming language, one of my favourites — this website is written in PHP; there are many great PHP programmers out there, some of whom probably never get things wrong; I probably get things wrong a lot of the time. The majority of the database-backed Open Source PHP projects … Continued

Hurrah! A Blog for Toby!

At last, my new CMS is at a stage when I’m able to actually start publishing with it. Now that I have an easy-ish tool to publish with, you can expect that this website will be updated more frequently and with more and better content. Updating this website in the past has been a major … Continued

Re: Building a “modular” PHP site

Tyno Gendo wrote: I have been pondering over building a “modular” site which accepts add-ons built by other people. I was wondering if anyone has any links to any reading material on how you build this kind of facility into your site? The basic technique is this: Firstly, provide a plugin registration function, which we’ll … Continued

Re: Random Map Generation

skulkrinbait@googlemail.com wrote: My first prototype for doing this doesn’t give good results, the map being far too random, can someone help me out or point me to a good resource please? Real geography is not random. First, take a grid, say 1001×1001 is size. Now find the middle square of it and set it to … Continued

Re: Parsing Question…

cjl wrote: Short of writing a parser, which is clearly beyond me, what are some reasonable approaches to handling user input that will be executed? Writing a parser is the best option in the long-run. If you were to attempt to interpret the user input some other way, like pure regular expressions, then you would … Continued