Skip to content

Instantly share code, notes, and snippets.

@scpike
Created September 19, 2012 03:53
Show Gist options
  • Save scpike/3747590 to your computer and use it in GitHub Desktop.
Save scpike/3747590 to your computer and use it in GitHub Desktop.
generate at token
token = SecureRandom.urlsafe_base64
# Naive, but with ~64^16 possibilities conflicts aren't a worry yet
# > 5,000,000.times {x << SecureRandom.urlsafe_base64}; puts x.uniq.count
# 5000000
while Checkin.where(:token => token).any?
token = SecureRandom.urlsafe_base64
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment