Mathieu Fenniak's Weblog

2002/10/30

Colourful Website

Filed under: programming — admin @ 9:48 pm

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.

2002/10/29

expatbuilder

Filed under: programming — admin @ 6:36 pm

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

Filed under: programming, python — admin @ 6:35 pm

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

Filed under: programming, python — admin @ 2:55 am

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.

2002/10/27

Recursiveness

Filed under: java, programming — admin @ 4:52 am

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? :)

2002/10/25

I Love Python

Filed under: programming, python — admin @ 2:08 am

I really love Python. I mean, it’s as slick and clean as programming languages come, and both easy to learn and powerful.

Pythons libraries are often rather pathetic next to the language itself. For example, I ran into a problem when working on this weblog which it seems should have come up earlier: reading an XML file using xml.dom.pulldom does not create DOM CDATA sections, but rather text sections which happen to have the right data in them. This is great until you go to write the XML file, and it writes it as text and doesn’t include it as a CDATA section, thereby loosing the original content. Oops.

Well, I worked around this by using my own SAX handler to create a DOM tree, which kind or randomly guesses at whether the text should be CDATA or just plain text, because that’s the best the SAX interface seems to let me do. … well, damn, ye olde deprecated xmllib let me do this right…

2002/10/22

zeroconf MOO

Filed under: moo, programming — admin @ 6:00 am

Continuing yesterday’s zeroconf work, I began coding a browse function for the MOO server. So in addition to being able to advertise its open TCP ports with zeroconf service names, the MOO server is now capable of browsing for zeroconf services. The implementation from inside the MOO is similar to how listen() functions.

The zeroconf_browse() builtin function takes two arguments: an object representing what object will be ‘listening’ for browse finds, and an string which will be the name of the service. The given object has a verb zeroconf_browse_add called on it when a new service is located, with the arguments {server's name, server's address, TCP port}. zeroconf_browse_remove is called whenever a service drops off the network, but I haven’t yet hammered out details of what arguments will be given to it.

And finally, the zeroconf_unbrowse() function takes a service name and stops browsing for that service.

The browsing is all done asynchronously in the current implementation, and a hook has been put in the main server loop to allow this to occur. The current implementation of zeroconf is highly MacOS X specific, but it can be re-written or extended to support multiple operating systems, especially by embedding Apple’s mDNSResponder daemon inside the MOO server. I haven’t even touched this yet, though.

I started looking into a Mozilla bug, bug #63895, but after some smashing at it with a hammer, I decided that a more informed and subtle approach is needed. It may indeed be a significant amount of work to fix even. The code in nsCSSFrameConstructor is a bit too complex for me to sink into it enough to find out what the problem is, so I think I’ll just ignore it…

I’m considering adding a locking system of some kind to Growlmurrdurr so I could write selectively private entries… but I don’t know what the point of a weblog that people can’t read is. :P

Powered by WordPress