Categories
Software and Programming

Type to Search

For some reason, text search dialog boxes (“Find in this page”) in browsers have gotten slower and slower. It takes them ages to show up, and you get this not only in Mozilla (which uses skinnable XUL(eXtensible User interface Language)), but also in Internet Explorer (where the Find box isn’t the usual Windows one, but some weird localized, HTML-ish creature).

Anyway, I’ve noticed that in Mozilla, when I click Ctrl-F and then start typing, it starts searching for the text I’m typing in the links on the page, before the “Find” box had a chance to show up.

This feature, called incremental search, is something cool Mozilla programmers have borrowed from Emacs (it also shows up in Microsoft’s Visual Studio). So I wondered, would it be possible to make it do an incremental search of all the text in the page, not just the links?

Well, sure. Here’s the preference to set (in Mozilla 1.3):

moznav.jpg

Categories
Software and Programming

The Busy XML hack

I wanted to list the news feeds I subscribe to in Syndirella to my reading page (still under construction). The program can export this list to me as an OPML file.

OPML is a simple (if inconsistent) XML format, so I tried to use a Perl module called XML::Simple to parse it. For some reason it didn’t work, so I messed around with it and then decided to simply write a script that parses the OPML file with regular expressions:


#an opml subscriptions parser.
while(<>) {
m/title\="([^"]+)"/i and my $title = $1;
m/htmlurl\="([^"]+)"/i and my $html = $1;
m/xmlurl\="([^"]+)"/i and my $rss = $1;
if ($html ne "" && $rss ne "" && $title ne "") {
	print qq{ <p><a href="$html">$title</a> 
                      [ <a href="$rss">RSS</a> ] </p>\n };
	}
}

Then I figured out what the problem with the original script was (I was handing it the script itself as input, instead of the OPML file. Doh!). So I wrote the proper XML-parser using program:


use strict;
use warnings;
use XML::Simple;

my $subfile = shift;
my $subs = XMLin($subfile);
for my $item (@{$subs->{'body'}->{'outline'}})
{
	my $html = $item->{'htmlUrl'}; 
	my $rss = $item->{'xmlUrl'}; 
	my $title = $item->{'title'}; 
	print qq{ <p><a href="$html">$title</a> 
                     [ <a href="$rss">RSS</a> ] </p>\n };
}


Not only is the regular expression based program simpler, it also works with OPML files that use different case for the attributes (htmlurl instead of htmlUrl – I told you it was inconsistent).

When I say “simpler”, above, I mean to write. The second program certainly looks clearer, especially if you’re used to the syntax of more rigorous languages. The quick regular expression hack looks a bit messier than usual because of the escapes in the regular expression (the backslashes before the quotes) and because it uses Perl’s backwards condition syntax (putting the if after the statement saves putting the statement in a { … } block).

Added spaces before the square brackets to stop them from breaking my RSS feed.

Categories
short Software and Programming

Developing Movable Type Plugins

O’Reilly Network: Developing Movable Type Plugins [Mar. 19, 2003]

Categories
Software and Programming

Reference Like It Oughta Be

Grrr. “Python”:http://www.python.org seems to have lots of useful libraries and services, for example codecs for translating between character sets / encodings, or an “HTML parser”:http://www.python.org/doc/current/lib/module-htmllib.html (well, actually there are “two”:http://www.python.org/doc/current/lib/module-HTMLParser.html – probably because the first one was too complicated).

And while this is all throughly documented, the documentation is mostly pretty confusing, because examples are thin on the ground.

So let me use this moment of frustration to point out why I think “Netscape’s Javascript Documentation”:http://devedge.netscape.com/central/javascript/ is simply *world-class*: it gives examples for everything. Practically every method of every object mentioned in it’s “client-side reference guide”:http://devedge.netscape.com/library/manuals/2000/javascript/1.3/guide/, for example, has sample code showing how the object or method can be created and used, and what the expected behaviour would be.

Which is probably why I’ll happily consider doing somthing in Javascript, but haven’t gotten deeper into Python than the simplest three-line script.

Categories
Software and Programming

In brief (nanotech, XML)

Two quick links before running off home:

* LA Times speculation about Five New techologies that may help Silicon Valley rise again.

* “Tim Bray: XML Is Too Hard For Programmers”:http://www.tbray.org/ongoing/When/200x/2003/03/16/XML-Prog