Skip to content

Instantly share code, notes, and snippets.

@bobzhen
Forked from DarrenN/shortid.rb
Created July 10, 2019 13:11
Show Gist options
  • Save bobzhen/52464f210b88c066b5f017f4b35c229c to your computer and use it in GitHub Desktop.
Save bobzhen/52464f210b88c066b5f017f4b35c229c to your computer and use it in GitHub Desktop.
Short unique ID (Ruby)
t = DateTime
id = t.now.strftime("%Y%m%d%k%M%S%L") # Get current date to the milliseconds
id = id.to_i.to_s(36) # will generate somthing like "5i0sp1h4tkc"
# Reverse it
id.to_i(36)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment