Articles Tagged with “Programming”
29/03/2008: 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 geo (yet).
- Support for hAtom, WebSlices.
- In addition to hAtom 0.1, rel-enclosure is supported within hEntries.
- Improve include-pattern support to prevent some infinite loops.
- Add option (disabled by default) to require
- GRDDL:
- Add option (disabled by default) to require for GRDDL.
- Add option to check profile URLs for…
22/01/2008: 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 web-based e-mail client; when adding content to limited content-management system; or in an eBay auction description. In such a situation, you can’t (validly) include a <link rel="stylesheet"> element, nor a block (if you do include such a construct it may just about work, but the document will not be valid), so instead you are reduced to using HTML style attributes all over the place.
However, it is slow work using style attributes as you can’t take advantage of CSS selectors. Instead…
06/01/2008: 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 FFMPEG
- Code straightened out to use functions — it used to be one big long mess.
- Added a help function — just run the program with the —help paramater.
Requirements
- Perl Getopt::ArgvFile
- Perl Getopt::Long ≥ 2.33
- Perl Pod::Usage;
- mplayer
- ImageMagick
Optional
- Perl File::chdir
- Perl File::Spec
- Perl Cwd
- FFMPEG
All of the Perl modules can be found in CPAN, here is the FFMPEG site and here is mplayer. And don’t forget ImageMagick.
Download
18/11/2007: 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.
19/08/2007: 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 QFrameCatcher. The QFrameCatcher website was inaccessible yesterday; today I managed to download the source code, but couldn’t get it to build.
Anyway, I decided it probably wouldn’t be very difficult to build my own so…
dhyana.pl
dhyana.pl is a small Perl script that co-ordinates mplayer and ImageMagick to create a lovely montage of thumbnails. (Dyhana — roughly pronounced as “jahna” — is the Sanskrit word for a deep meditation.)
12/08/2007: PHP Debugging with Style -OR- How I Learned to Stop Worrying and Love the Bug
PHP lets you define your own error handler, so I decided to get a bit fancy. MegaErrorHandler (MEH) outputs its errors as specially-formatted HTML comments, with the details of the error encoded using JSON.
A small client-side script, with an associated stylesheet then pulls this data out of the comments and formats it as a nice little interactive bug-viewing console, allowing you to view a stack trace for each bug, inspect superglobals, view the syntax-highlighted source code for the file where the error occurred, check the list of defined constants and other useful things…
20/07/2007: Parsing an HTML Table with PEAR’s XML_HTMLSax3
Here’s an example of how to parse an HTML table into an array using the PEAR module XML_HTMLSax3. It supports the <tr>, <td> and <th> elements and the rowspan and colspan attributes…
19/07/2007: 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, leaving only the last two components. But then someone will chime in pointing out that groups.google.co.uk would be left as just co.uk that way, when what is really wanted is google.co.uk. And the eventual resolution of the argument will be “it just can’t be done”.
The problem is that there’s technically no difference between a domain and a subdomain: it’s simply a matter of convention. Fortunately, this issue is actually quite important to browser programmers, as it’s a key issue in cookie security: browsers must allow subdomains within a domain to share cookie data, but not allow cookies…
17/07/2007: 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…
17/07/2007: Pretty Printing for PHP
Here’s a PHP function for reformatting the whitespace in PHP code…
19/04/2007: 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, say, secure shell) and reversing the change. In some extreme cases, the problem is so severe though, that it can’t be fixed remotely — for example, you’ve managed to accidentally halt the machine, so you can’t log into it remotely and it needs a restart. In such a situation, you’ll need to physically go over to the server (or phone someone and have them do so) and fix the problem.
NASA’s Mars Global Surveyor (MGS) was launched in November 1996. Fast forward almost a decade and a couple of bugs in a firmware update end up swivelling the antena further than the antenna was built to go. This led to the craft reorienting itself and exposing one of its batteries…
16/04/2007: Create Your Own Dan Brown Novel
I put this together back in January 2006, but never mentioned it on my website — I just posted it on a couple of newsgroups. It’s pretty good fun and rather realistic.
08/04/2007: 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 that I’ve used/examined make the same flaw again and again…
08/04/2007: 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 pain. I took a look at installing an off-the-shelf blogging engine to help me run the site, and after much research decided that Wordpress was the best of breed. After two days playing with it, I abandoned it — it didn’t do everything I wanted out of a blogging engine, and the mess of PHP code would have made modifications to Wordpress painful.
And so in early 2006, I decided to embark upon my own blogging engine. I posted my initial ideas to Usenet in February 2006 and asked for feedback. I got a few useful suggestions and started development later that month, calling the project…
04/04/2007: 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 call, say, “plugin_register”. When a plugin is loaded, it will call your plugin_register function and tell your site at least the following information:
- How to use the plugin — i.e. provide a function name or a class name that the site can use to access the functionality of the plugin;
- When to use the plugin — this is normally done via a named hook…
27/02/2007: PHP4 vs PHP5 [was Re: Extending the mysqli class]
Michael Fesser wrote:
My scripts make use of many of the new OOP features in PHP 5, so they won’t run at all on PHP 4.
Ditto.
My current big pet project is http://demiblog.org/. This is PHP 5+ only and supports MySQL 5+ and PostgreSQL 8+. Although I do realise that earlier versions of these packages are still quite widely used out there, this project probably won’t hit the big 1.0 for another year or two, by which time, the hosting world will have probably moved on a lot. Supporting older versions of PHP and the database engines will cost development time and push back the project release date even later, by which time PHP 4 support will be even less relevant.
So although PHP 4 may still be alive right now, it’s counting down the days to his retirement when it can hand over the family business to his son PHP 5. He’s heard the happy news that his dranddaughter PHP 6 is planning on following in their footsteps too as soon as she graduates. Because of PHP 4’s impending retirements, he’s not taking on…
15/02/2007: 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…
10/02/2007: 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 fall into a lot of traps, and your interpreter would behave oddly in many cases.
A full parser is a much better option: it will behave far more reliably and would be a lot easier to extend, should you feel the need to add extra features to the language at a later date.
Although it’s a lot of work, there are some fairly well established methods on writing them. What you basically need to write is three fairly independent components: a tokeniser, a parser and an interpreter. None of these share any code in common, except for the definitions of a few constants and classes.
Firstly, a tokeniser, which reads the user input and splits it into a long list of tokens. Each token should have the…