Kommandorad topp-tio

Posted by Anders Tue, 07 Oct 2008 15:31:00 GMT

Gissa vilket CMS jag jobbar med…

  210    cd
   81    ls
   29    more
   28    ant
   25    bin/polopoly
   15    svn
   11    sudo
    9    pwd
    8    irb
    7    fgrep

Posted in ,  | no comments

Back up

Posted by Anders Sat, 06 Sep 2008 23:06:00 GMT

After a disk failure in my MacBook, here are some observations on bootable backup disks:

1. Verify beforehand that your bootable backup disk actually is bootable.

2. Having a replacement disk ready means less when you don’t have the Torx T8 screwdriver needed to install it.

3. Torx screws are an evil conspiracy.

4. Having a working DVD reader will save you time and money when re-installing the OS.

But I luckily made the last backup just 24h before the crash, so I lost almost nothing.

Posted in  | Tags  | 3 comments

Xinerama and IntelliJ: The two-headed beast

Posted by Anders Wed, 18 Apr 2007 13:54:00 GMT

At work I found myself with a new Dell with some ATI Radeon card, two monitors and Ubuntu Linux installed.

Setup

Setup was simple (once I literally spent hours finding it out):

Got the binary drivers (why can’t ATI Open Source their stuff?) using Envy.

Using “aticonfig” I generated an xorg.conf file:

aticonfig --initial=dual-head --screen-layout=right

This gets a not very usable double-X11-server setup, where you can’t drag an application from one screen to another. To get something better, enable Xinerama in xorg.conf:

Section "ServerFlags" 
  Option "xinerama" "true" 
EndSection

I hacked the screen resolution settings in the xorg.conf to get the right resolutions for the two monitors. I’m using two different resolutions, since my monitors are of different size.

Not so fast

This makes things sort of working, but I still have two major issues:

  • The pointer arrow looks corrupted when I move it to the second screen. Wierd.
  • IntelliJ crashes almost immediately:

IntelliJ puked this X11 error in the logs and died:

'BadMatch (invalid parameter attributes)'.
  (Details: serial 904580 error_code 8 request_code 42 minor_code 0)

I could live with the crazy looking pointer, but I need IntelliJ to work, so I guess I’ll just have to disable the second screen for now. Meh.

Update, April 24: Serge Baranov of JetBrains suggested I should remove the HTMLPreview plugin from IntelliJ, which worked. Still have the corrupted pointer, but it’s good enough to be usable.

Posted in ,  | Tags , , ,  | 4 comments

The ghost of Unix' past

Posted by Anders Sat, 16 Dec 2006 12:49:00 GMT

I wanted to access the e-mail on my server through the standard IMAP protocol. Quoting the UW IMAP daemon documentation :

The IMAP and POP3 servers are plug-and-play on standard UNIX systems. There is no special configuration needed. Please ignore all rumors to the effect that you need to create an IMAP configuration file.

Great, no configuration! This is exactly what I need.

Wait, why are strange things like .bashrc and .bash_history showing as folders in my e-mail client? It’s not exporting my entire Unix home directory to the client, is it?

Consulting the documentation again:

Example 2: suppose you want to change c-client’s idea of the user’s mailbox directory to be the “mail” subdirectory of the user’s home directory instead of the user’s home directory.

Yes, please!

The documentation continues:

You will want to change variable mailsubdir, changing the line that reads:

static char *mailsubdir = NIL;    /* mail subdirectory name */
to be:
static char *mailsubdir = "mail";/* mail subdirectory name */

I will want to do what?

This is a configuration option that is often (always?) unusable in its default setting. It is so common to need to change it that they prominently mention it in the documentation, and the FAQ too, but they still want me to edit the source code and re-compile to change it?

I think they found the loophole in the “no special configuration” promise.

Posted in  | Tags ,  | no comments

Serverflyttad

Posted by Anders Mon, 16 Oct 2006 18:40:00 GMT

Eftersom BBB ändrade min IP-adress varje gång jag fick en smula trafik till min site (konspiration?) och jag lessnat på att ha en bullrande server igång i köket, så köpte jag mig virtuell hosting hos eapps.com. Rätt så billigt och verkar funka bra. Eftersom den är virtuell så bullrar den inte och drar heller ingen ström…

Enda strulet just nu är att min blogg får för sig att den lever på amerikansk tid, så mina inlägg dateras en halv dag in i framtiden. Jag har inte hunnit flytta över min mail än, så tyvärr har jag fortfarande en bullrande maskin i köket, men det kanske ordnar sig i veckan.

För övrigt satte jag in en egen bild längst upp i sidan. En liten bit av den här:

Trekanten

Även om jag retar mig lite på kompositionen så är den en av mina favoritbilder från senaste tiden.

Posted in ,  | no comments

Validating against a specific DTD with SAX

Posted by Anders Sun, 27 Aug 2006 04:52:00 GMT

I was using a SAX parser in Java to parse some XML documents into objects. Since one of the benefits of XML is validation, I set the parser to be validating. I also had to add lots code of my own to make sure that numeric fields contained numbers etc, but I imagined that I was now reasonably sure that any document passing the parser was correct.

Later I had a different kind of XML document, which I accidentally fed to the parser. To my surprise it did a complete parse without complaining, spitting out a defective object.

What I had overlooked was that the SAX parser only validates that the document is valid against the DTD that the document itself claims to follow. Sure, the document is valid, but if it’s a valid fantasy novel instead of the valid product data I expect, it’s of little use.

Looking around

So, how to make sure that the document is valid against a specific DTD? You would have thought that someone would have a nice solution for this by now. It turns out that there is an obscure SAX2 property that you can set. But only if you’re using XML Schema, not DTD.

Most people seem to solve it by pre-processing the XML document, forcing it to declare the Doctype, before feeding it to the parser. Some do it by ad-hoc string manipulation and there’s even a SourceForge project for this very purpose. Not a very pretty solution—I figured I could do better.

Solution

I thought that it would be easy to just use one of the SAX events to check that the DTD was right. I will get a SAX event when it parses the DOCTYPE, right? No. There wasn’t an event that would give me the information I needed. Instead I had to go through the EntityResolver, which is the thing that finds the DTD. I subclassed it to intercept the resolveEntity() method, where I added a check. I also had to ensure that resolveEntity() was actually called during the parse, so that a DTD-less document couldn’t sneak through.

So far I was only verifying that it was the right DTD. But you can have several kinds of documents defined in one DTD. For the document to be correct it needs to have the right top-level element1.

<!DOCTYPE TheTopLevelElement PUBLIC "foo" "foo.dtd">

So I added a second check, on the startElement() event, to make sure that the first tag it comes across is the top-level tag I want.

Conclusion

Maybe I should have just gone with the string-manipulation. My solution wasn’t very clean either, despite the good intentions. Or maybe I should just accept that XML validation is mostly useless, since I still have to add lots of more checks in my code. (XML Schema does this slightly better that DTD, but at the cost of more complexity).

1 Not available through SAX events either.

Update, August 31th:

Jörn Horstmann pointed out the LexicalHandler interface. This enabled me to remove the checks in the startElement and the EntityResolver, leaving only this:

LexicalHandler lexicalHandler = new DefaultHandler2() {
    public void startDTD(String name, String publicId, String systemId) {
        // Check name, publicId and systemId here
        // Throw exception if they're wrong
    }
};
parser.setProperty("http://xml.org/sax/properties/lexical-handler", lexicalHandler);

This should solve it all, in one place. The identifier ending in “2” and the wierd URL-as-property-name aren’t very pretty, but that goes for a lot of things in the strange world of XML.

Posted in , ,  | 2 comments

Mac-ook turned MaçBook

Posted by Anders Wed, 21 Jun 2006 23:55:00 GMT

I’m typing this on my new white MacBook, which will soon be returned for a second attempt at repairing it. When I first got it, the “B” key was broken. So I leave it for repairs in central Stockholm. A week and a half later I get it back, only to realize that the service people managed to replace the original Swedish keyboard with a Turkish keyboard.

Someone in Istanbul is probably typing on a Swedish keyboard right now, equally annoyed.

Posted in  | no comments