This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
(( ${BASH_VERSION%%.*} > 4 )) || echo 'Error: Outdated bash version ' && exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mypy.plugin import Plugin, FunctionContext | |
from typing_extensions import Protocol | |
from typing import TypeVar, Any | |
from types import new_class | |
def handle_function_call(function_ctx: FunctionContext): | |
T = TypeVar('T', bound=Any) | |
attr = function_ctx.args[0][0].value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from asyncio import Lock | |
from collections import defaultdict | |
from functools import wraps | |
from typing import Any | |
from typing import Awaitable | |
from typing import DefaultDict | |
from typing import Dict | |
from typing import TypeVar | |
from typing_extensions import Protocol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Deque, Iterable | |
T = float | |
class RunningSumDeque(Deque[T]): | |
def __init__(self, iterable: Iterable[T], maxlen: int): | |
super().__init__(iterable, maxlen) | |
self.__sum = sum(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Type, Iterator | |
import contextlib | |
@contextlib.contextmanager | |
def assert_raises(expected: Type[Exception]) -> Iterator: | |
try: | |
yield | |
except Exception as e: | |
assert isinstance(e, expected), ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Type, TypeVar | |
from enum import IntEnum | |
import sqlalchemy | |
E = TypeVar('E', bound=IntEnum) | |
class IntegerEnum(sqlalchemy.types.TypeDecorator): | |
impl = sqlalchemy.Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from collections import OrderedDict | |
from typing import Any | |
import weakref | |
class InstanceCache(type): | |
""" | |
Custom metaclass for DegreeAngle that reuses cached objects to optimize | |
memory consumption by storing weak references to them in an ordered dict. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is Git's per-user configuration file. | |
[user] | |
name = Anton Agestam | |
email = git@antonagestam.se | |
[core] | |
excludesfile = ~/.gitignore_global | |
[color] | |
ui = true | |
[diff] | |
wsErrorHighlight = all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Optional, Any | |
from django.db import models | |
from django.core.validators import MinValueValidator, MaxValueValidator | |
from django import forms | |
class BaseBoundedField(models.Field): | |
def __init__( | |
self, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.db import models | |
from django.db.models.functions import Concat | |
class DatabaseStreamHandler(logging.StreamHandler): | |
def __init__(self, instance: models.Model, field: str): | |
super().__init__() | |
self.instance = instance |