Useful snippets of code
A bunch of random pieces of code that others may find useful.
"...if you take cranberries and stew them like applesauce they taste much more like prunes than rhubarb does. Now, uh... Now you tell me what you know." -- Groucho Marx

Dimension-Templatized matrix class. This was used on our helicopter for a while and is pretty handy. Uses GSL for matrix multiply and SVD. It provides compile-time checking of many matrix dimensions, which catches a lot of annoying and/or dangerous errors. This is similar to Eigen, but unlike Eigen it will not ^$#!@ up your other template code. (E.g., works with STL and nvcc without any trouble.)
Quaternion class. Also from the helicopter code. Uses TMatrix (above).
Decompressing JPEG images from memory using LibJpeg. This is a mysteriously difficult thing to find on the web. I prefer the IOStream code below.
Compress and Decompress OpenCV images to C++ iostreams using LibJpeg. To compress/decompress from memory, use std::ostringstream and std::istringstream. The dependence on OpenCV is unnecessary---the IplImage is just used as the container and is easily changed.
Download Flickr images using bash. Have fun reverse-engineering this hack of a bash script. It downloads images from Flickr containing the given tags and saves them in the current directory. Images larger than 1024 pixels wide are resized using ImageMagick 'convert', and images smaller than 640 pixels wide are ignored. The number of images actually downloaded varies, since some image names retrieved are dead. NOTE: Be sure to put your Flickr API key into the script. If you don't have a key, you can get one for free from Flickr.