Home Articles Code Programs Photos
Created: 2008-11-29 ~ Updated: 2009-01-15

Software Monkey's Code

This section provides code extracts, from individual methods to classes and full packages. The intention is to provide examples of some specific code I have written which I think is note-worthy in some way, and to comment on the relative merits of the approach I took.

All code is published in this section considered to be licensed for any use without restriction - I ask only that you retain my copyright notice as credit. And all code is provided as is, without warranty of any kind. The author accepts no liability for any loss of any kind which results from the use of this code.

I do have to caveat that I belong (at least currently) to the unchecked exceptions camp; what this means is that my exceptions subclass RuntimeException, and none of my methods have throws clauses. Sorry if that rankles you, or makes me less of a programmer in your eyes. Let it be known that I do wrestle with this decision on a theoretical level (in fact I had the discussion with a coworker today, with my questioning whether we should cross over), however, with over 1,500 java classes behind me and several significant systems in production, I find unchecked exceptions actually work in practice on large projects. But in honesty, I have not tried checked exceptions on any large scale. Since all my exceptions subclass Escape, which in turn subclass RuntimeException; you may just alter the superclass to RuntimeException for the most painless change; or Exception if you want to add throws clauses all over the place.

Code follows in the order posted; the right side index lists the code by basic category and in alphabetical order.

Math Evaluator (Java)

This math expression evaluator was born out of a need to have a small-footprint and efficient solution which could evaluate arbitrary expressions reasonably efficiently without requiring pre-compilation. I needed something which would do basic math with variables, expressions like: "Top+2", "Bottom-2" and "(Right+1-Left)/2".

Table Oriented Layout Manager (Java)

A long time ago, in a land far, far away... (from New Zealand) I was writing a GUI in Java. After about 7 levels of nesting I began to think that I was missing something critical - that there had to be an easier way. Don't get me wrong, I love Java's concept of resizeable flowing layouts (I cannot count the number of times I have had to deal with a Windows O/S dialog on my 1920x1200 screen utilizing about 10% of my available real estate with a little teeny tiny listbox in the middle showing 9 of the 2700 files I am sifting through). But there just has to be a better way!

Linked-list / Binary-tree Combination (Java)

This class set is a combined linked-list and binary-tree map implementation. It was originally designed around about 2000 or 2001. Since then it has gone through several refactorings to arrive in the final form, each time with the desire to obtain added function while adhering to the DRY principle.

Most-Recently-Used Cache (Java)

This class is a very simple MRU cache based on my LinkedTree implementation. It serves as a working example of the use of the linked tree. However, do note that it does not leverage one of the most powerful attributes of the tree, which is the ability to position to and navigate from specific nodes by exact and closest-match keys.

Callback Method Support for Java 2+ (Java)

One of the things I really miss when programming in Java is function callbacks. One situation where the need for these kept presenting itself was in recursively processing hierarchies where you want to perform some specific action for each item. Like walking a directory tree, or processing a data structure. The minimalist inside me hated to have to define an interface and then an implementation for each specific case.

A Compact Pull Parser for JSON (Java)

This is another situation where I needed something leaner than what I could find on the Internet, and I found myself lying awake one early morning wondering, "how hard could it be?". Written from about 3 am to 10 am, this parser is efficient, lean and functional.

16 bit CRC for C

This is an C module from ages ago for calculating a 16 bit CRC. As far as I can recall it is compatible with the ancient X-Modem file transfer protocol... but I wouldn't want to bet my life, my wife and my wallet on it. I used it for years as a checksum for a modem communications protocol and it worked really well in that context.

32 bit CRC for C

This is an C module from ages ago for calculating a 32 bit CRC. As far as I can recall it is compatible with the ancient Z-Modem file transfer protocol... but I wouldn't want to bet my life, my wife and my wallet on it. I used it for years as a checksum for a modem communications protocol and it worked really well in that context.