October 2002 archive

Colourful Website

Heh heh heh. I got an idea yesterday that it would be cool to make websites recolour themselves based upon domain names. So, say, ‘pink.stompstompstomp.com’ would be all pink, and red would be all red, and so on.

So I wrote a python script to recolour images on the fly, and implemented it on stompstompstomp.com. It works on jpg, tif, and png images, but not palette images (gif, some pngs, I suppose some tiff too..). Anyways, very nifty. Try visiting the normal pics page, and then add a colour in front of stompstompstomp.com. Here’s a link to the pink page, for example.

Beige, blue, brown, crimson, cyan, gold, goldenrod, gray, green, maroon, navy, orange, orangered, pink, purple, red, silver, teal, white, and yellow all work. Very fun.

This has been turned off and normal website operations restored. But that was niftyrific.

expatbuilder

Heh heh. How surprised was I that in the process of posting that last technical comment, I ran into problems which made it apparent that I’m not using the 4DOM implementation. I’m still using minidom, but I’m using the expatbuilder class rather than my own SAX based DOM builder. That’s enough to fix my problems.

PyXML

Ah ha! I grabbed PyXML 0.8.1 from pyxml.sf.net, and tried using 4DOM’s DOM implementation rather than the builtin minidom. It works beautifully. The downside is that PyXML is needed to use Growlmurrdurr, but whatever. Much cleaner implementation of my XML file reading function now.

Comments

I’ve added threaded commenting support to Growlmurrdurr. Oooh, so pretty. I know, I know, you just can’t stand how pretty it is. What can I say?

XML is beautiful. Python is beautiful. The two do not make beautiful children. Grmp. I’ve built enough small tools into Growlmurrdurr to make the code look alright despite some XML weirdness, but I’d like to develop my own implementation of xml.dom, and add a hyper Pythonized interface to it.

As well, I’m finding problems with the SAX interface to the XML parser… some of these problems I can’t believe are really problems with SAX, since it’s so widely implemented, but they must be Python specific implementation problems. I don’t understand why a SAX content handler never seems to be told when it is reading a CDATA section rather than a text node. There are differences in handling… especially when building a DOM tree out of the XML file. The DOM tree must be constructed with the right node types, or else writting the tree out later on will yield a wildly different document… perhaps I just need to use a lower level API when building my DOM tree.

Recursiveness

En route from Ottawa to Montreal, I spent about 20 minutes working on a Java assignment. Usually these assignments are quite boring, and this one was no exception. The basic assignment is to create a class that represents a single variable polynomial of given degree. Anyways, the polynomial needed a function to evaluate it for a given value, and eventually I coded up this:

    private double evalCoeff(int deg, double x)
    {
        if (deg == this.getDegree())
            return this.coefficients[deg];

        return evalCoeff(deg + 1, x) * x + this.coefficients[deg];
    }

    /**
     * Evaluate the polynomial for a given x value.
     *
     * @param x         The value.
     * @returns         The evaulated value.
     */
    public double evaluate(double x)
    {
        // Very, very slick.
        return evalCoeff(0, x);
    }

Isn’t that beautiful recursiveness? :)

1 2