Posts about code (old posts, page 1)

Pretty-printing XML with Emacs' NXML-mode

Did you ever get a stream of XML out of a log file, or in a data stream, and it's all mashed together without line-breaks so that it just appears as gobble-de-gook? If there's a data error (not an XML parsing error) then you have to read it so that you can find where the error is, but you don't have XML-spy and NetBeans is overkill or takes forever to fire up...

Emacs to the rescue! Benjamin Ferrari wrote this increadibly useful (and simple) elisp function to pretty-print a block of XML code:

Read more…

Finding DLLs used by a Cygwin program

I don't know how many other people get this issue, but it comes up at my work a bit: Some co-worker asks me if I know of a tool to do such-and-such, and invariably I think “well, that's easy to do on Unix, but on Windows…”.

Then I remember Cygwin, and quickly find a Cygwin utility that does it, or can be scripted to do it with a small amount of work. So then co-worker asks if they can have a copy of this utility, and of course Cygwin is Free, so I say “sure, go download from www.cygwin.com.” Then they say, “yeah, but I don't want to install all of Cygwin, can't you just give me that one program?”

Well, the Cygwin command-line tools can be run from a Windows CMD.EXE shell, so this is quite possible to do. However, they all require the Cygwin POSIX layer, which at a minimum means I should also give them cygwin1.dll. But what other DLLs might the program use?

MJL2008-09-10T14:37+1000 Update: since this page gets a lot of hits, here's the quick answer: use cygcheck, i.e:

cygcheck grep

Find it under Happy hacker discovery #2. Keep reading if you're bored...

Read more…

Setting up multiple Java VMs under Cygwin

It is useful to have different versions of the JVM installed, for a number of reasons:

  • Different optimisation features from different JVM implementations
  • Different language features from different JVM versions
  • Java classes compiled with “Tiger” won't run in “Mantis”…

It is also useful to be able to quickly switch between installed JREs/JDKs depending on the task at hand.

If I'm hacking in Linux, the JPackage project provides a much nicer solution to this problem, and the Linux distro' I'm using (SUSE 10.0) uses JPackage. It'd be nice if there was an update-alternatives for Cygwin, but since there isn't I've come up with this hack.

Read more…

Monospace fonts

I finally got fed up enough with Courier New to start searching for a legible, monospace font to use in jEdit. In Emacs, I'm particularly fond of the standard X font "misc-fixed" (though it's a little tough to tell appart O and 0 still). But for jEdit, the Java monospace font seems to map to Courier New in Windows, and to some God-awful font on Linux.

Read more…

jEdit macros, vs. Emacs functions

I've been playing with customising jEdit a little bit, and decided to have a go at writing some simple date insertion macros. These perform the same work as some old elisp functions I wrote years ago in Emacs, to insert date/time stamps in various formats. In my .emacs file, I bind these functions to short-cut keys, and then use them for updating Changelogs in code and in offline journal entries.

Read more…

“Get into the habbit of reading source docs”

This post was originally published at sinewalker.blogspot.com.au on 27 October 2005


The great thing about Linux is that all the definitive documentation (including the source code) comes with the OS.

(Slashdot quote)


You know, I'm finding that for a lot of the “beginner” linux distro's, this is not true. Yes, the source is available but it doesn't come with the OS.


Granted, not everyone wants to fill their harddrives with source tarballs or SRPMs on the off chance they might want to read them, but only a few distro's I know come with source, and those are not necessarily for noob's. the main example that comes to mind is Gentoo (since it's a “ports”-like distribution). This is not to wax lyrical on the benefits of Gentoo for learning Linux (Gentoo has many weaknesses in that regard too, among its inappropriateness as a general OS for noob's), just that it's the only one I've found where the source comes with the OS.


Other distro's with source “available” are Debian and Fedora (on extra CDs you have to download, and Fedora locks the source into SRPMs which is another learning hurdle to leap over, especially bad if all you want to do is read the source comments, or documentation not included in the binary RPM). It makes me feel like a 2nd-class citizen, that the source is somehow “open” but you have to know the secret handshake to get at it.


All of this, just to say: while reading source docs is a laudable habbit and I share your wish to encourage it, I can also see how it is difficult for most Linux noob's to form this habbit so long as the source doesn't actually come with the OS, which for a great many distro's it does not. The extra steps to download (and in many cases extract from SRPMs) the source are probably enough of a deterrent to forming this habit.


unfortunately, hacker habbits require hacker motivation :-(