Skip to content

Instantly share code, notes, and snippets.

View ShawnMilo's full-sized avatar

Shawn Milochik ShawnMilo

View GitHub Profile
@ShawnMilo
ShawnMilo / ksuid_to_timestamp.sql
Created May 2, 2023 18:38
Convert a ksuid to a datetime/timestamp with time zone in PostgreSQL (plpgsql)
CREATE OR REPLACE FUNCTION ksuid_to_datetime(ksuid_base62 TEXT)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
DECLARE
v_alphabet CHAR ARRAY[62] := ARRAY[
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
#!/usr/bin/env python
import os
import sys
from time import sleep
from random import randrange
import re
fkey = re.compile(r'^F\d$')
@ShawnMilo
ShawnMilo / validate_uuid4.py
Created December 3, 2013 20:55
Validating a uuid4 with Python.
from uuid import UUID
def validate_uuid4(uuid_string):
"""
Validate that a UUID string is in
fact a valid uuid4.
Happily, the uuid module does the actual
checking for us.