Skip to content

Instantly share code, notes, and snippets.

@fellipebrito
Created February 11, 2015 17:04
Show Gist options
  • Save fellipebrito/40507770464bde86ebab to your computer and use it in GitHub Desktop.
Save fellipebrito/40507770464bde86ebab to your computer and use it in GitHub Desktop.
Example of how to use hashid
class HashMachine
## Source: https://github.com/peterhellberg/hashids.rb
## In this example I'm using 11 as the size of the hash. This is the same size youtube uses
require 'hashids'
@@my_salt = 'this is my salt'
@@my_hash_size = 11
def hashids
hashids = Hashids.new @@my_salt, @@my_hash_size
end
def encode number
hashids.encode number
end
def decode hash
hashids.decode hash
end
end
hash_machine = HashMachine.new
hash = hash_machine.encode 12345
p "My hash is: #{hash}"
p "My number is: #{hash_machine.decode hash}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment