fixed a broken python implementation; added a ruby implementation