General

XSLT and the wonders thereof

It’s always interesting for me to dig into XSLT. I don’t use it a whole lot, so when I do it’s all fun and new. This time around, I’m using 2.0, which wasn’t really implemented the last time I was doing anything much with the language. Loving the new features; so far I’ve used several to good effect.

It occurred to me today that document conversion is an interesting niche wherein a ‘pure functional’ paradigm is useful. I still can’t see myself using a pure functional approach in many other areas, but I do have to deal with document conversion often enough that I’m glad XSLT exists.

I find the tree-transformation model of computation is an interesting mind-bender, though when I think about it, it’s really only mind-bending in combination with the functional approach. And thinking further, I’d suppose that a functional program of any size would tend toward the nature of a tree transformation… Hmmm, something to ponder some more.

General

Dumb ways to lose files, part 18

Here’s a bizarre way to lose some files:
rm foo.x `
(didn’t notice I’d accidentally hit backtick)
ls
(always do this after file operations, it’s a weird little habit)
(oops, didn’t work. Oh, there’s a backtick in operation.)
`
(a bunch of errors about some files and directories that can’t be removed.)
(CRAP!)

Running a Bacula restore job as I type this…

General

Lost clicks in Flash Player, Eclipse

I’ve been having some weirdness in Flash Player and Eclipse, where mouse clicks seem to get lost and so I can’t click certain buttons. Turns out it has something to do with the new GTK client-side windows. It can be fixed with GDK_NATIVE_WINDOWS=1. If you need more info, ask; I’m mainly posting this as a reminder to myself, but maybe it’ll catch a few web searches…

General

Dirt/hardwood/carpet

Hmmm, one difference between hardwood floors (which I have now) and carpeted floors (which I’ve lived with most of my life) that I didn’t really anticipate: I tend to perceive hardwood floors as ‘dirtier’, in the sense that they’re more likely to give up their dirt to my sticky clothing and skin surfaces when I touch them.

That, of course, is the flip side of the ‘easier to clean’ thing, because they’ll give up their dirt to the sweeper, vacuum and dry mop more easily, too. I guess you could say it’s a more open relationship between me and housedirt. Weirder analogies are sitting in my brain, but aren’t going to get out.

General

asc-gzip/.xfd compression

If you should ever find yourself in the position of having to figure out how to compress XFDL files with the asc-gzip encoding, and I don’t wish it on you, here’s Python code to do it. Obviously, you’ll need some imports and error handling and optimization.

This thread gave me pointers to figure this out; Bryan was just a little off because he was using a gzip library rather than a zlib one.

# compress according to wacky XFDL compression scheme
def compress(fc):
    CHUNK_SIZE = 60000
    out = ''
    for i in range(0, len(fc), CHUNK_SIZE):
        chunk = fc[i:i + CHUNK_SIZE]
        chunklen = len(chunk)
        compressedchunk = zlib.compress(chunk)
        compressedchunklen = len(compressedchunk)
        out += chr(compressedchunklen / 256)
        out += chr(compressedchunklen % 256)
        out += chr(chunklen / 256)
        out += chr(chunklen % 256)
        out += compressedchunk
        
    f = StringIO.StringIO()
    f.write('application/x-xfdl;content-encoding="asc-gzip"n')
    b64 = base64.standard_b64encode(out)
    
    for i in range(0, len(b64), 76):
        f.write(b64[i:i+76])
        f.write('rn')
    ret = f.getvalue()
    f.close()
    return ret
General

‘Parented to’

Language morphs in interesting ways. Fields of endeavor adopt various words from the general language as terms of art. But of course, the metaphors break down around the edges and the terms morph to reflect that.

In computer science, the terms ‘tree’, ‘parent’ and ‘child’ were taken to talk about a certain way of structuring data, presumably because when you draw diagrams of this structure, it looks similar to a diagram of a family tree you might draw in genealogy. But often, when implementing this, it’s sensible for the node to have a ‘parent’ property rather than just the parent having a ‘children’ property. In those cases, it’s more natural, then, to English a line of code like “A.parent = B;” as “node A is parented to node B”, rather than “node A is made a child of node B”. They mean the same thing in the computer science nomenclature, but you’d probably never hear someone saying “Joe is parented to Jane” in genealogical terms.

General

urllib2

It’s been quite a while since I’ve looked at the HTTP client libraries in Python. urllib2 has a pretty cool pluggable-pipeline architecture, with a bunch of standard handlers for things like cookies, redirects, basic auth, etc. Nice.

General

Little bitty soft synth

I remember this wavetable synthesizer with a tiny sample set (I believe it was 128kB for a GM set). Crystal developed the algorithms and sample set for a tiny (at the time, at least) one-chip MIDI synth, and I worked on implementing a software synth that used the same sample set. It was a bit of a stretch on a 90Mhz Pentium, since the whole scheme was optimized for sample size and originally implemented on a chip with bunches of hardwired MAC units. But, it worked. I listened to Chopin’s Fantaisie Impromptu an awful lot during the development of that one, since it stressed the system pretty well (lots of polyphony, lots of note-on/note-offs, and using the piano, which had the most parallel SRCs in flight for each note.

General

Text Layout Framework

I like a good API. I’m not quite ready to commit to the assertion that Adobe’s Text Layout Framework API is a ‘good API’, but it’s not bad. The fact that they made it open-source is pretty cool.

I can see the potential for a lot of new experiments springing up from this foundation; I mean, who hasn’t had an idea for some groundbreaking new text editor or word processor? This API takes care of a lot of the little garbage associated with such a project, and so should help get some of those ideas into the wild.

(It doesn’t do spellchecking, though. You’d have to come up with your own solution for that, maybe basing it on the pretty-good Spelling Plus Library (which, we hear, will eventually have TLF integration).)

General

Unnecessary upgrades

Occasionally I subject myself to unnecessary software upgrades. I guess mainly to see some of the challenges and learn from them, at a non-critical time. I switched my desktop machine to Ubuntu 9.10 alpha (or is it beta) a few days ago. I’m still adjusting, but I’m learning a few things. Today was the pitfalls of IPv6 in a network with old devices. Apparently, 9.10 enables IPv6 by default and my old DSL modem is confused by and unresponsive to the new-style DNS request. Disabling IPv6 (by the kernel parameter method) cleared up my problems with very poor DNS resolution.