a fork of a ruby script by @ttscoff