Skip to content

Instantly share code, notes, and snippets.

View SeanSyue's full-sized avatar
🏔️
Nature Lover

Yuchen Xue SeanSyue

🏔️
Nature Lover
View GitHub Profile
@SeanSyue
SeanSyue / nested_mapping_serializer.py
Created December 9, 2023 09:55
A generator function that flattens a nested `Mapping` object.
from typing import Any, TypeAlias, TypeVar, Union
from collections.abc import MutableSequence, Iterable, Mapping, Iterator
import copy
MS = TypeVar("MS", bound=MutableSequence)
Nested: TypeAlias = Mapping[Any, Union[Iterable, "Nested"]]
def nested_mapping_serializer(
@SeanSyue
SeanSyue / IndexableNamespace.py
Last active January 31, 2024 18:25
An extension of the SimpleNamespace type, where the members of whose IndexableNamespace instance can also be accessed and modified by indexing.
from types import SimpleNamespace
from typing import Any
from collections.abc import MutableSequence
class IndexableNamespace(SimpleNamespace, MutableSequence):
"""
An extension of the SimpleNamespace type.
The members of an IndexableNamespace instance can also be
accessed and modified by indexing.
''' comparing speed of new dataclass
with standard class attributes and slots,
running in 3.7.0b1'''
# subscribe to me: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1
# I recommend reading PEP557: https://www.python.org/dev/peps/pep-0557/
# this code at gist: http://bit.ly/slotsVdatclass
from dataclasses import dataclass
from timeit import timeit
@huklee
huklee / MyLogger.py
Last active January 6, 2024 18:06
python Logger using example with Singleton Pattern
# -*- coding: utf-8 -*-
import logging
import os
import datetime
import time
class SingletonType(type):
_instances = {}