Skip to content

Instantly share code, notes, and snippets.

@indera-shsp
Created April 1, 2019 01:23
Show Gist options
  • Select an option

  • Save indera-shsp/d07db94b9f5fd2dcc80bd34724ae2f44 to your computer and use it in GitHub Desktop.

Select an option

Save indera-shsp/d07db94b9f5fd2dcc80bd34724ae2f44 to your computer and use it in GitHub Desktop.
def hexlify(val):
"""
Note:
- Without the decode() the builtin `hexlify` return the bytes for
hexadecimal representation of the binary data.
- The returned string is twice as long as the length of data.
:param val: binary
:rtype: string
"""
return binascii.hexlify(val).decode()
def get_uuid_bin():
"""
Note: the returned value needs to be hexlified to be human readable
"""
uuid_text = uuid.uuid1()
return binascii.unhexlify(str(uuid_text).replace('-', '').lower().encode())
def get_uuid():
""" Generate a PK-friendly uuid"""
val = str(uuid.uuid1())
return sort_uuid(val)
def sort_uuid(val):
return val[14:18] + val[9:13] + val[0:8] + val[19:23] + val[24:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment