The Ubuntu Inspiron is up and running!

I finally got around to unpacking the boxes and installing the new computer. Pretty much everything worked out of the box, but I had to tinker with screen resolution as only the default set of 640×480, 800×600 and 1024×768 was available initially, and in the end I had to connect the monitor via VGA – DVI was giving me problems I could not resolve at this point. More later.

Got a Dell Inspiron 530n with Ubuntu pre-installed

I finally splurged on a Dell Inspiron 530N with Ubuntu. I need a computer for my music workstation, and with the latest developments in good quality multi-track recording software for Linux I felt it’s time to give it a serious try. I was thinking of building one myself instead of buying a ready made one, but did not feel adventurous enough. I guess I’m getting old :) This is actually my first brand name PC purchase!

I’ve received it very quickly – placed the order last Friday, and yesterday it was here! I’ve ordered the cheapest configuration without the monitor for $379, $410.74 with tax, with free shipping.

As for the monitor, Dell needs to get real: $170 is too much for a Viewsonic VA1703wb – a widescreen 8ms 1440×900 monitor with no DVI, 500:1 contrast and 250 nits brightness, so for just $10 more plus shipping I’ve got a superb 20″ Acer AL2016WBbd with 1680×1050 resolution, 5ms response time, DVI, 800:1 contrast and 300 nits brightness from NewEgg. Dell should consider partnering with Acer on monitors – Viewsonic is a good brand but Acer beats it hands down.

Stay tuned as I get it into production, and post questions if you are considering a Dell computer with Linux but still undecided – I will try to answer them here.

Javascript Object Explorer Updated and Renamed

It is now called Javascript Object Tree Screener, which I think reflects its purpose better. There are still things to work on – the bookmark does not work in Safari and Opera has problems with it. I will address that in the coming days. But it is now better than it was before, and more useful overall. Please do try it out and let me know how it works for you.

Text::Templet 2.8 released

Download it here. This release includes two new features for building web application servers.

JavaScript Object Explorer Updated

A new version of JavaScript Object Explorer is available here: The main new feature is the ability to analyze other sites – the page contains a link which you can save as a bookmark in your browser, then select it while displaying the target page. There are also numerous stability improvements, making it a more useful tool overall.

Text::Templet Use Scenario

If your web site is hosted on Apache server, you can configure it so that you can use Text::Templet and Perl with the ease of PHP. No more CGI/Perl scripts! The reason PHP is easy to use is that in the simplest case it is just an HTML page. You can create as many as you want, you don’t need to worry about setting permissions, and it’s very easy to debug because you get a meaningful response right in the browser instead of a 500 Server Error and digging error details from server logs.

Apache server has a mechanism that allows you to create custom content handlers – you can make Apache launch a specific program or script when a file with a particular extension is requested, and send its output to the browser. Best of all, this feature can be configured from the .htaccess file, and thus is available at many shared web hosting accounts.

To make this work, we need three things: a content handler script, a folder with template files containing your application, and an .htaccess file in the root of that folder.

Let’s start with the handler code:

use Text::Templet;

my $pagetext;
local(*PAGE, $/);
open (PAGE, $ENV{'PATH_TRANSLATED'})     || die "can't open file $_[0]: $!";
my @fstat = stat(PAGE);
read(PAGE,$pagetext,$fstat[7]); # $fstat[7] is the size of the file
close PAGE;
print "Content-type: text/html\r\n\r\n";


if ( $@ )
my $errortext = $@;
print "<body><div>Error:</div><div><pre>$errortext</pre></div><div></body>";

The handler is very simple – it loads the requested file passed to it by Apache in PATH_TRANSLATED environment variable, sends a standard HTTP header and passes the contents of the file to Text::Templet for processing. Any errors in the template will be reported through the $@ variable and displayed in the browser.

.htaccess file looks like this:

AddHandler pa-handler .pa
Action pa-handler /cgi-bin/

The following assumptions are made: the handler code above is saved in /cgi-bin/, with executable permission set, and our template files have .pa extension. In addition, will be called when only directory is requested.

Finally, a simple template to get you started:

use vars qw($hello);
$hello = "Hello, World!";
Perl Application says: $hello

I’ve put all these pieces together to make it easy for you to try it out. Download pa.tar.gz or, extract and Text/ from cgi-bin into cgi-bin folder on your web server, then create a new folder somewhere in your html document tree and extract .htaccess and into it. Verify that has execute permission set and open http://yourserver/folder/ . Click here to see this example code running on my web host.

You can use this example as a starting point and add features such as authentication and security. You can also put your Perl code in modules and reference them from your templates.

Performance of Perl Regular Expressions

Perl owes much of its power to regular expressions, making programming easier and more intuitive. But this power often comes at a cost – parsing and processing regular expressions is a non-trivial task that uses quite a few CPU cycles.

In some situations it is possible to significantly reduce the amount of time necessary for a particular processing routine by avoiding regular expressions altogether and using other techniques. Consider, for example, a task of extracting file name from a string containing a full path. Presented below are three functions that accomplish this using three different methods, along with their performance analysis.

Function filename1 splits the path into parts using path separator and returns the last part as the file name:

sub filename1
    my @tok = split /\//,$_[0];
    return $tok[-1];

The same result can be achieved using a slightly different approach – write a regexp that takes the part between the last path separator and the end of string:

sub filename2
   $_[0] =~ /\/([^\/]+)$/;   
   return $1;

Both functions are elegant and neat, but when it comes to performance, the following code is the best:

sub filename3
   return substr($_[0],rindex($_[0],'/')+1);

rindex() finds the index of the rightmost separator character in the string and then the file name is extracted using substr().

Here’s how long it takes all three functions to parse ‘/abc/def/geg-geg/’ 30000 times:

function1: 0.580 seconds
function2: 0.541 seconds
function3: 0.260 seconds

With a longer path ‘/abc/def/geg-geg/ abc/def/geg-geg/’ the difference is more dramatic:

function1: 1.191 seconds
function2: 1.101 seconds
function3: 0.271 seconds

These are typical performance figures produced by the Perl profiler (Devel::DProf.) In this particular example, replacing a regular expression with search and substring extraction has reduced execution time by 50 to 75%.

Formatting 720K Floppies

The secret to formatting a diskette to 720K under Windows 2000/XP is simple: you have to convert an HD diskette to a DD diskette. To do this, cover the hole that specifies that the disk is HD with a piece of scotch tape:
Converting a diskette from HD to DD

Linux Hardware Question

Here’s the situation. I’ve installed Ubuntu 7.04 on my Fujitsu laptop, and it works well for the most part. The two buttons on the touchpad that serve as a scroll wheel do not work as expected – one is dead and the other works as the middle button. But that’s probably because the pointing device is recognized as a 3-button mouse without a scroll wheel.

Now, I plugged in an external mouse, and I expected for it to get recognized and start working seamlessly but alas! there seems to be no plug-n-play capability installed by default. Can anyone lend me a hand with this? What do I need to do in order to get functionality similar to Windows XP which automatically recognizes any hardware plugged in and if it does not already have a driver for it, at least I can go to the manufacturer’s web site to download the driver and then install it either through New Device wizard or through Device Manager. At least when it comes to simple devices like mice and keyboards I would expect the drivers to be present – it is not uncommon especially for laptop users to use either embedded pointing device or an external mouse depending on the circumstances.

The WPA-PSK issue I mentioned earlier got resolved once I installed the system onto the hard disk. But another problem that I’m now having is that it constantly tries to access the CDROM drive, every second.

Linux Market Share Jump

Linux market share as measured by Net Applications has been growing fast this year. From 0.35% in January it increased to 0.42% in February (20% growth) and then jumped to 0.57% in March (35.7% growth) and 0.80% in April (22.8%). Unless it’s a fluke, it seems like Linux is finally starting to gain some momentum.

At the same time, Windows Vista has been gaining about 1% per month since February: 0.18% in January, 0.93% in February, 2.04% in March and 3.02% in April, or roughly 12% per year. Windows XP was released on October 25, 2001, and by the end of 2004 it commanded 65.07% of the market. Even assuming that the adoption was linear, that translates into over 20% per year. In reality, early adoption rates are probably higher, translating into possibly 30% market share for Windows XP by the end of 2002.

I do wish success to Microsoft’s competitors. If more people begin to use software that conforms to open standards and not Microsoft’s proprietary protocols and features, Microsoft-only standards will become marginalized and Microsoft will be forced to use open standards itself in order to inter-operate with others’ products. This will bring more competition and choice to the market, leading to improved quality of software, lower prices and real innovation such as BumpTop, for one small example.