Skip to content

Instantly share code, notes, and snippets.

@bjmc
Last active November 6, 2015 01:06
Show Gist options
  • Save bjmc/8694030 to your computer and use it in GitHub Desktop.
Save bjmc/8694030 to your computer and use it in GitHub Desktop.
import uuid
# based on http://stackoverflow.com/questions/3795554/extract-the-time-from-a-uuid-v1-in-python
def uuid_to_timestamp(uuid_hex_string):
uid = uuid.UUID(hex=uuid_hex_string)
return (u.time - 0x01b21dd213814000L)*100/1e9
def reorder_uuid(uuid_hex_string):
parts = uuid_hex_string.split('-')
return '-'.join((parts[2], parts[1], parts[0], parts[3], parts[4]))
def test_sequentialness(n=10000):
old = reorder_uuid(str(uuid.uuid1()))
for i in xrange(n):
print old
new = reorder_uuid(str(uuid.uuid1()))
assert new > old
old = new
print "passed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment