Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View friendly_guid.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class FriendlyGuid
attr_reader :mask
 
def initialize(mask)
@mask = mask
end
 
def guid(id)
(id.to_i ^ mask).to_s(36)
end
 
def id(guid)
guid.to_i(36) ^ mask
end
end
 
if __FILE__ == $0
mask = Random.new.rand(2**64)
id = Random.new.rand(2**64)
f = FriendlyGuid.new(mask)
puts "mask = #{mask}"
puts "id = #{id}"
g = f.guid(id)
puts "guid = #{g}"
puts "id = #{f.id(g)}"
end
View friendly_guid.rb
1 2 3 4
mask = 1000723141368662252
id = 2465229093246480629
guid = q6parhf03kt5
id = 2465229093246480629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.