Archive for the ‘Programming’ Category
Good Introduction to Emacs
I stumbled upon a short but useful introduction to emacs on the web. It has lots of screenshots to demonstrate the different commands. It even touches upon development tools like gdb and diff.
Algebraic Geometry: “Ideals, Varieties, and Algorithms” C++ Code
I did an REU (Research Experience for Undergraduates) this summer and we used the textbook “Ideals, Varieties, and Algorithms” (isbn 978-0-387-35650-1) by David Cox, John Little, and Donal O’Shea. As the title mentions, algorithms are an important tool in the study of varieties via their corresponding algebraic ideals. One of the main tools used in algebraic geometry is what is known as a Groebner basis, which is somewhat akin to a basis set in Linear Algebra. Anyway, I wrote some C++ code which implements a few of the algorithms in the book, but stops short of implementing Buchberger’s algorithm for computing a Groebner basis. The code should be useful as a starting point because it implements a Monomial class and a Polynomial class both with lots of useful methods thus eliminating the drudgery of implementing the book’s algorithms in C++.
The code can be found at: my web site as a gzipped tarball. Please let me know if you find it useful. I developed the code on an Ubuntu Linux machine, but it is generic enough that it should compile on any platform. You will need to read the README to understand the simple input, output format.
Run any GNU/Linux app on Windows without any virtualization
Free Software Magazine has an excellent article on how to Run any GNU/Linux app on Windows without any virtualization.
It explains how to install, setup and use the free Xming X Window server for Windows and also how to use SSH from the command line. It also includes information on how to enable SSH access into an Ubuntu machine.
Iterated Function Systems and Fractals
This code generates fractals based upon an iterated function system (IFS). Several input files and a Makefile are included. The code is written in C++, and distributed as a tarball. I did this for a class at the University of Utah, but it is based upon a homework assignment for a computer graphics class at MIT (6.837).
Below is the famous Barnsley fern which was generated by an IFS with just four transforms!

New and Improved Sierpinski Triangle C++ Code
I modified my Sierpinski triangle code so that it now allows you to adjust the contraction mapping constant. Normally one uses a contraction mapping constant of 1/2 but if you invert that and instead use an expansion mapping constant of 2, then you get the following pretty picture.

Strategy Letter VI – Joel on Software
Joel Spolsky has an excellent essay on his blog about AJAX web apps and where they’re headed. The essay is entitled Strategy Letter VI – Joel on Software and I highly recommend it!
I used to be very enthusiastic about a startup that originated at MIT called Curl Corporation that did much of what Joel talks about with one major exception, instead of targeting JavaScript, they targeted their own runtime. Now that has the major disadvantage that users must download the runtime in order to run client-side Curl code, but the widespread adoption of Flash (which sucks in comparison because it was designed for visual effects) leads me to believe that if they had decided to freely distribute their runtime (for commercial as well as non-commercial use), then they would be rulers of the web by now. Their language is fairly Lispy like Joel talks about in his essay, and was a joy to use, but alas, they decided to take the short-term route and market their technology to large corporations for intranet applications. I tend to think that if they had taken the long-term strategy of targeting the entire web, then we would all be using Curl now and enjoying very rich client-side web apps instead of bickering about how to best AJAXify your web-site/application.
At this point in time, I think Joel is spot-on about the need to target JavaScript, instead of creating a new runtime, because that avoids the chicken and egg dilemma. But the devil is in the details. It may be a considerable challenge to seamlessly target Microsoft’s, Apple’s and Mozilla’s JavaScript engines.
General Public License Version 3: A Legal View
If you would like a great summary of differences between versions 2 and 3 of the GPL check out Mark Radcliffe’s blog post: General Public License Version 3: A Legal View on his blog entitled Law & Life: Silicon Valley.
Sierpinski Tetrahedron (Tetrix) C++ Code
I modified my Sierpinski triangle code from a previous posting to work in three dimensions instead of two. The result is a short C++ program which will generate all the points of the Sierpinski tetrahedron and write them to stdout (you can redirect to a file).
Below is the obligatory image. This doesn’t look great but if you plot it yourself in gnuplot or some other package, you can probably get a prettier looking picture.
Sierpinski Triangle C++ Code
If you like pretty pictures, and I know you do, below is a plot of Sierpinski’s Triangle which you can generate with the short C++ program I wrote. This is an example of a fractal–an object that is self similar at all levels of magnification.
On a Linux/UNIX system, to compile and run the code type:
$ g++ sierpinski.cc -o sierpinski $ ./sierpinski >out Enter depth (integer > 0, usually 10 is good): 10 Enter contraction mapping constant (for example 0.5): 0.5 $
Now the points are stored in a file called ‘out’. To plot them you can use gnuplot like so:
$ gnuplot gnuplot> plot 'out' with points pointtype 0
Kaliope Now Includes Gravitational Potentials
I’ve added a C++ class that handles gravitational potentials to my Kaliope project. Below is a picture of a binary cluster orbiting around a logarithmic potential well. A logarithmic potential is the simplest kind of potential well. It corresponds to an inverse distance radial force field.
Here is a slightly different simulation, with each body given its own color, so it is easier to see individual paths:

Counting Lines of Code
I recently found myself frequently using the wc -l command line utility to count lines of code in my current project. But this got old quickly so I wrote a simple Bash script to do everything for me. Here it is:
#!/bin/bash
# This script determines the number of lines of code in
# all source and header files excluding the GPL banner
# at the beginning of each file. It doesn't count code
# in C files generated via gengetopt.
HEADERS=`ls -l ./include/*.h | wc -l`
CODE=`ls -l ./src/*.cc | wc -l`
# The GPL banner is 17 lines long
GPL_LINES=$[17*($HEADERS + $CODE)]
COUNT=0
for i in $( ls ./include/*.h ./src/*.ggo ./src/*.cc ); do
OUTPUT=`wc -l $i`
NUM=`expr match "$OUTPUT" '\([0-9]*\)'`
COUNT=$[$COUNT + $NUM]
done
COUNT=$[COUNT - $GPL_LINES]
echo "Total lines of code (minus GPL lines) = $COUNT"
This is my current output for my Kaliope project (gravitational N-body simulator/integrator).
$ ./code_diagnostics.sh Total lines of code (minus GPL lines) = 2322
XKCD
I’ve been a big fan of Dilbert for years now, but I recently found a great webcomic that I’ve started reading daily called XKCD. The tagline is: A webcomic of romance, sarcasm, math, and language. The drawings are simple stick figures, but it is the situations and ideas that are interesting and funny.
Write Yourself a Scheme Interpreter in Haskell
I found an interesting link on Phil Windley’s blog to a tutorial on programming in Haskell. This tutorial is different from most because instead of showing you small examples related to various language constructs, this one takes you step by step through the entire process of creating a Scheme interpreter. Seems well done.
JavaScript: Most Important Language Today
According to Steve Yegge’s latest blog post, JavaScript is the most important language in the world today. After some arguments to convince you that his outrageous claim has real merit, he then goes on a rant about how much JavaScript sucks, and how he wishes it was more like Ruby on rails. Here is a great quote from his post:
Well, if you happen to be doing web programming, Ruby on Rails defies classical language mechanics by actually being a lower energy state. That’s right; it’s more lazy to learn Rails than it is to try to get your web framework to be that productive, so people are just tunneling over to it like so many electrons.
Excellent stuff!



