Skip to content

Instantly share code, notes, and snippets.

View koi8-r's full-sized avatar
🐧

Valentin Nagornyy koi8-r

🐧
View GitHub Profile
import weakref
class A: ...
def test_() -> None:
o = A()
ref = weakref.ref(o)
assert ref() is not None
del o
assert ref() is None
def fake() -> None:
print("fake")
@lambda this: fake
def x() -> None:
pass
from typing import TypeAlias, TypeVar
T = TypeVar("T")
Tuple6: TypeAlias = tuple[T, T, T, T, T, T]
OCTET_MAX = 0xFF
def parse(octets: Tuple6[str]) -> int: # like: int(str, 16)
---
x-logging: &logging
driver: json-file
options:
max-size: 1m
max-file: 3
compress: 'true'
services:
linux:
@koi8-r
koi8-r / stm3241g_eval.cfg
Created May 31, 2025 11:39
stm32f411 openocd config
# STM32F411CEU6: 100MHz Arm Cortex-M4 core with DSP and FPU, 512KB Flash, 128KB SRAM, ART Accelerator
# https://stm32-base.org/boards/STM32F411CEU6-WeAct-Black-Pill-V2.0.html
# increase working area to 128KB
set WORKAREASIZE 0x20000
set CHIPNAME STM32F411CEU6
source [find interface/stlink.cfg]
# source [find interface/stlink-dap.cfg]
# source [find interface/stlink-v2-1.cfg]
Add
scrub on bridge100 all min-ttl 65
to
'/etc/pf.conf'
Reload with
sudo pfctl -f /etc/pf.conf
Check with
sudo pfctl -sa
task = asyncio.create_task(read_output())
handler = event_loop().call_later(2, cancel_asyncio_task, task)
task.add_done_callback(lambda _: handler.cancel())
await task
@koi8-r
koi8-r / shelly_plug_s.py
Created January 30, 2023 11:59
Shelly-Plug-S API Example: The Squid game
import logging
from base64 import b64encode
from json import loads as jsdecode
from urllib.parse import urlencode
from enum import Enum
from http.client import HTTPConnection
from time import sleep
from random import uniform
from typing import Union
from inspect import Parameter, signature
from typing import Any, Optional
def fn(i: int, z: Optional[str] = None, *a, v: int = -1, **kw: Any):
pass
if __name__ == '__main__':
p = signature(fn).parameters
def lock(res):
pass
def free(res):
pass
class MyCtx(object):
__slots__ = ('res',)