Skip to content

Instantly share code, notes, and snippets.

@Cyan101
Created May 27, 2017 13:17
Show Gist options
  • Save Cyan101/ea91638e8f0a9d76bd6fac764c724d42 to your computer and use it in GitHub Desktop.
Save Cyan101/ea91638e8f0a9d76bd6fac764c724d42 to your computer and use it in GitHub Desktop.
Creates a 8-character unique ID based off the current time
def unique_id
DateTime.now.strftime('%Q').to_i.to_s52
end
class Numeric
Alpha52 = ('a'..'z').to_a + ('A'..'Z').to_a
def to_s52
return '' if self < 1
s = ''
q = self
loop do
q, r = (q - 1).divmod(52)
s.prepend(Alpha52[r])
break if q.zero?
end
s
end
end
# puts unique_id
#=> awHwanat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment