Skip to content

Instantly share code, notes, and snippets.

@datavudeja
datavudeja / convert_enums.py
Created February 4, 2026 15:59 — forked from eugeneko/convert_enums.py
Script for enum modernization in Urho
import sys
import os
import re
re_enum = re.compile(r'\s*enum\s*(\w+)\s*(:.*)?\s*')
re_enum_value = re.compile(r'\s*(\w+)(?:\s*=\s*(.+))?,?(?:\s*\/\/.*)?\s*')
folders_blacklist = [
# 'Urho3D/Audio',
# 'Urho3D/Container',
# 'Urho3D/Core',
@datavudeja
datavudeja / enumWithUnknownOrMissing.py
Created February 4, 2026 15:57 — forked from thanakijwanavit/enumWithUnknownOrMissing.py
enum with unknown or missing value
from enum import Enum
class Foo(Enum):
A = 1
B = 2
C = 3
def __str__(self):
return self.name
"""TypedEnum : type preserving enumeration metaclass."""
class TypedEnum(type):
"""This metaclass creates an enumeration that preserves isinstance(element, type)."""
def __new__(mcs, cls, bases, classdict):
"""Discover the enum members by removing all intrinsics and specials."""
object_attrs = set(dir(type(cls, (object,), {})))
member_names = set(classdict.keys()) - object_attrs
member_names = member_names - set(name for name in member_names if name.startswith("_") and name.endswith("_"))
@datavudeja
datavudeja / typed_enum.py
Created February 4, 2026 15:56 — forked from sseg/typed_enum.py
Typed enum with case matching on types.
# coding: utf-8
import abc
from types import new_class
from typeguard import check_type
from contextlib import contextmanager
def make_type_class(name, parent, type_declaration):
def init(self, value):
@datavudeja
datavudeja / enum_with_label.py
Created February 4, 2026 15:53 — forked from jonashaag/enum_with_label.py
Python Enum with label / verbose name / description
import enum
class EnumWithDisplayName(enum.Enum):
def __new__(cls, value, name=None):
if not hasattr(cls, "_value_to_display_name"):
cls._value_to_display_name = {}
cls._display_name_to_value = {}
if name is not None:
if value in cls._value_to_display_name:
@datavudeja
datavudeja / findquote.py
Created February 4, 2026 15:44 — forked from andreasots/findquote.py
New !findquote syntax parser
from psycopg2.extensions import QuotedString
import enum
# Usage: `cursor.execute("SELECT * FROM quotes WHERE " + Parser(query).parse().to_sql())`
# Hopefully there won't be any SQL injection bugs...
class Column(enum.Enum):
ord = 1
pattern = 2
fts = 3
@datavudeja
datavudeja / classtest.py
Created February 4, 2026 15:43 — forked from JacobCallahan/classtest.py
Written during a quick class on python classes
import random
class MyBase:
"""This is a base class"""
def __init__(self, **kwargs):
"""Assign each key, value pair to our class instance"""
for arg, val in kwargs.items():
self.__dict__[arg] = val
@datavudeja
datavudeja / dynamic-properties.py
Created February 4, 2026 15:42 — forked from subhashb/dynamic-properties.py
Add properties dynamically to class
from collections import defaultdict
from enum import Enum
class ElementTypes(Enum):
PHONE = "PHONE"
CAR = "CAR"
class Registry:
@datavudeja
datavudeja / explore_enum.py
Created February 4, 2026 15:41 — forked from schwehr/explore_enum.py
exploring enums in python
#!/usr/bin/env python3
"""Exploring python enum."""
import enum
# from typing import Sequence
class Simple(enum.Enum):
A = 'a'
B = 'b'
@datavudeja
datavudeja / graceful_key_formatter.py
Created February 3, 2026 17:51 — forked from RyanJulyan/graceful_key_formatter.py
A class to check and validate pandas DataFrame based on custom and default functions.
import string
import re
from typing import Any, List, Dict
class GracefulKeyFormatter(string.Formatter):
def get_value(self, key: str, args: List[Any], kwargs: Dict[str, Any]) -> Any:
"""
Retrieve the value of the given key from the provided keyword arguments.