Skip to content

Instantly share code, notes, and snippets.

@HeshamMeneisi
Created November 4, 2025 04:03
Show Gist options
  • Select an option

  • Save HeshamMeneisi/a67d08e796c03bd5da5f7fe787b22a1a to your computer and use it in GitHub Desktop.

Select an option

Save HeshamMeneisi/a67d08e796c03bd5da5f7fe787b22a1a to your computer and use it in GitHub Desktop.
short_id_from_str (Python)
import base64
import hashlib
BASE32_EXPANSION_FACTOR = 8 / 5
def short_id_from_str(s: str, max_len: int = 8) -> str:
h = hashlib.blake2s(
s.encode(), digest_size=int(max_len / BASE32_EXPANSION_FACTOR)
).digest()
return base64.b32encode(h).decode().rstrip("=")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment