Skip to content

Instantly share code, notes, and snippets.

@AndrewIngram
Created January 20, 2022 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewIngram/b59fa2321e6b0d53556f12f0f0f13ded to your computer and use it in GitHub Desktop.
Save AndrewIngram/b59fa2321e6b0d53556f12f0f0f13ded to your computer and use it in GitHub Desktop.
Stable UUID hack
import { v5 as uuidv5, NIL } from 'uuid';
function stableUuid(namespace, name) {
return uuidv5(name, uuidv5(namespace, NIL))
}
// > stableUuid('Some namespace', 'some name')
// '019761ac-2321-5ae0-9086-70c9557bcc58'
// > stableUuid('Some namespace', 'some name')
// '019761ac-2321-5ae0-9086-70c9557bcc58'
// > stableUuid('Some namespace', 'some other name')
// '68944cf9-ebbf-58c6-8e4a-fd1390ad95bc'
from uuid import UUID, uuid5
def stable_uuid(namespace: str, name: str):
return uuid5(
uuid5(
UUID("00000000-0000-0000-0000-000000000000"),
namespace
),
name
)
# >>> stable_uuid('Some namespace', 'some name')
# UUID('019761ac-2321-5ae0-9086-70c9557bcc58')
# >>> stable_uuid('Some namespace', 'some name')
# UUID('019761ac-2321-5ae0-9086-70c9557bcc58')
# >>> stable_uuid('Some namespace', 'some other name')
# UUID('68944cf9-ebbf-58c6-8e4a-fd1390ad95bc')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment