Skip to content

Instantly share code, notes, and snippets.

View koi8-r's full-sized avatar
🐧

Valentin Nagornyy koi8-r

🐧
View GitHub Profile
@koi8-r
koi8-r / coro.py
Last active November 4, 2026 10:16
import asyncio
def reader() -> None:
for _ in range(3):
print("next", end=" ")
try:
r = yield None
except ValueError:
pass
given = "abcdef"
it = iter(given)
res = [(a + b) for a,b in zip(it, it)]
assert ['ab', 'cd', 'ef'] == "".join(res)
@koi8-r
koi8-r / nested_list_comprehension.py
Last active March 30, 2026 16:29
Python netsed list comprehension
m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
ll = [i for l in m for i in l]
assert list(range(1, 10)) == ll
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