Really rough, but easy to drop in and get working with something else, either as an external script or by integrating directly into a larger code base.
The code:
PHP: Gist 214887
Ruby: Gist 222662
(I confirmed embedded gist breakage in Fx3/Lnx & IE8 after @clintziegler tipped me off. Swapped with boring ol’ links for now!)