Yggdrasil https://github.com/leonardvandriel/Yggdrasil does reverse geocoding from coordinate to country code. Included is a .ygg file that gives accuracy down to ca 10km.
A rougher (40 km accuracy) variation is in the ruby gist is here: https://gist.github.com/leonardvandriel/4579113