This is old code that I wrote for various purposes which I occasionally still refer to.