Kjell’s Software
 
 
Use it, abuse it...
 
... but don’t pretend you wrote it.
 
Here is a collection of code I’ve written over the years.  Some of the stuff might suffer from software rot.
This program uses the first-fit decreasing size strategy to try to pack the argument files into as few directories as possible. You can set the capacity of each bin, run it without actually packing (for statistical purposes) and handle directories as well as regular files.
 
   $ python binpack.py -p *.jpg
 # cd0 : 699M full, 19K remaining
 # cd1 : 699M full, 47K remaining
 # cd2 : 699M full, 65K remaining
 # cd3 : 205M full, 494M remaining
 
To learn more, read the documentation in the code or simply run python binpack.py -h
cf.py
I use this Python program to quickly copy the images over from my Compact Flash card (hence the name) to a directory on my hard drive. It will of course work with other types of memory cards. Before you use it, you need to change a few constants in the program: where your card is mounted, where you store your digital negatives, and the type of files you want copied. After that it is as simple as typing
 
   $ cf “Summer Holiday”
 
binpack.py rank.py
This code is useful if you need to generate all permutations, need the previous or following permutation in the list of all permutations, generate a random permutation, etc. More information can be found in the source code.
 
  $ python rank.py
  [1, 2, 3, 4]
  [1, 2, 4, 3]
  [1, 3, 2, 4]
  [1, 3, 4, 2]
  [1, 4, 2, 3]
  [1, 4, 3, 2]
  [2, 1, 3, 4]
  [2, 1, 4, 3]
  [2, 3, 1, 4]
  [2, 3, 4, 1]
  [2, 4, 1, 3]
  [2, 4, 3, 1]
  [3, 1, 2, 4]
  [3, 1, 4, 2]
  [3, 2, 1, 4]
  [3, 2, 4, 1]
  [3, 4, 1, 2]
  [3, 4, 2, 1]
  [4, 1, 2, 3]
  [4, 1, 3, 2]
  [4, 2, 1, 3]
  [4, 2, 3, 1]
  [4, 3, 1, 2]
  [4, 3, 2, 1]
 
You know those photo stores that advertise having your own pictures printed on next year’s calendar? Well, now you can do it yourself! All you have to do is come up with 12 JPEG images and let the computer do the rest. The output is a LaTeX-file which you run through PDFLaTeX before you print it out and nail it to the wall.
This program features Swedish name days, flag days, holidays and week numbers.
Thanks to Kent Engström for providing the necessary Python code to manage all possible calculation of dates.
 
calendar ddgen
This software is further described in my article on deterministic parsing of languages with dynamic operators, which you will find under my Research page.
 
fp
This is a toy interpreter for John Backus’ ultra-functional language FP as described in his Turing Award-article.  This was joint work with Mikael Pettersson.
6502
Computes pi to an arbitrary number of places. Written in Scheme. Call with e.g. (compute-pi 100) to get 100 decimals.
A 6502 assembler (written in AWK) and emulator (in C).  Joint work with Krister Joas.
lithp
A very small LISP interpreter written in C++. In case you are wondering about my sanity, let me just say that it was a mandatory programming assignment in grad school. The task to write a data structure for LISP’s S-expressions, but it somehow went out of control and eventually became an interpreter as well.  
barlog
A one-page Prolog interpreter, written in SML.  Comes with a report.
LightsOut
Tcl/Tk source for the hand-held game “Lights Out!”.
The object is to remove all the red lights, you’ll soon figure out the rules.
sort32.c
Ever felt the urge to sort exactly 32 numbers?  I thought so!  And you are in luck, because this program does that in a very efficient way.
cordic.c
How can those little calculators compute sin and cos? Check out this program that computes them both with just adds and shifts.
pi.scm