Skip to content

Instantly share code, notes, and snippets.

View jymchng's full-sized avatar
🎯
Focusing

Jim Chng jymchng

🎯
Focusing
  • Singapore
  • 11:48 (UTC +08:00)
View GitHub Profile
@jymchng
jymchng / main.py
Created February 25, 2025 05:50
Python Playground Code
from abc import ABC, abstractmethod
from typing import Optional, Type, Any, Generic, Callable, Self, TypeVar
from weakref import WeakKeyDictionary
_T = TypeVar("_T")
__GLOBAL_INTO_CACHE__: WeakKeyDictionary[Type[Any], Callable[[Self], Any]] = {}
class IntoMixin(ABC):
__slots__ = ()
@jymchng
jymchng / main.py
Created February 24, 2025 13:43
Python Playground Code
from abc import ABC, abstractmethod
from typing import Optional, Type, Any, Generic, Callable, Self, TypeVar, Union
from weakref import WeakKeyDictionary
_T = TypeVar("_T")
__GLOBAL_INTO_CACHE__: WeakKeyDictionary[Type[Any], Callable[[Self], Any]] = (
WeakKeyDictionary()
)
class IntoMixin(ABC):
@jymchng
jymchng / readme.md
Created December 23, 2024 16:48
Python Playground Code

Interview Question: Finding an Element in a Rotated Sorted Array

Question:

You are given a rotated sorted array of unique integers, meaning the array was originally sorted in ascending order, but then some unknown number of elements were moved from the front to the back. Given this array, write a function search_rotated_array(nums: List[int], target: int) -> int that returns the index of the target in the array. If the target is not present, return -1.

You must write an efficient solution with a time complexity of O(log n).

Example 1:

@jymchng
jymchng / readme.md
Created December 22, 2024 17:06
Python Playground Code

Interview Question: Finding an Element in a Rotated Sorted Array

Question:

You are given a rotated sorted array of unique integers, meaning the array was originally sorted in ascending order, but then some unknown number of elements were moved from the front to the back. Given this array, write a function search_rotated_array(nums: List[int], target: int) -> int that returns the index of the target in the array. If the target is not present, return -1.

You must write an efficient solution with a time complexity of O(log n).

Example 1:

@jymchng
jymchng / file1.py
Created December 22, 2024 16:56
Python Playground Code
# This is an empty file
@jymchng
jymchng / main.py
Created December 20, 2024 18:21
Python Playground Code
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names
# delimited by comma of the packages you want to install.
# Click on [Add Package(s)]
# Then import those packages, e.g. import attrs
import logging
from logging import getLogger
logger = getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout)
@jymchng
jymchng / file1.py
Created December 19, 2024 19:25
Python Playground Code
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names
# delimited by comma of the packages you want to install.
# Click on [Add Package(s)]
# Then import those packages, e.g. import attrs
import logging
from logging import getLogger
logger = getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout)
@jymchng
jymchng / file1.py
Created December 19, 2024 19:09
Python Playground Code
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names
# delimited by comma of the packages you want to install.
# Click on [Add Package(s)]
# Then import those packages, e.g. import attrs
import logging
from logging import getLogger
logger = getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout)
@jymchng
jymchng / env_variant.py
Last active December 16, 2024 07:05
How to write `ENVVariant.my_replace(..)`?
import pytest
from enum import Enum
class ENVVariant(str):
__VALID_MEMBERS__ = ["LOCAL", "DEV", "SIT", "UAT", "PREPROD", "PROD"]
def __new__(cls, value: str):
members = ENVVariant.__VALID_MEMBERS__
if isinstance(value, RollYourOwnNewTypeEnum):
@jymchng
jymchng / file1.py
Created December 15, 2024 18:35
Python Playground Code
import os, sys # Possible to import most packages; go to [Installed Packages] tab, type in the names
# delimited by comma of the packages you want to install.
# Click on [Add Package(s)]
# Then import those packages, e.g. import attrs
import logging
from logging import getLogger
logger = getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout)