I wrote this after seeing the question on Stackoverflow.