Skip to content

Instantly share code, notes, and snippets.

View MtkN1's full-sized avatar

MtkN1 MtkN1

View GitHub Profile
@MtkN1
MtkN1 / pydantic_vs_cattrs.ipynb
Created February 26, 2025 06:18
Pydantic vs cattrs Deserialization Benchmark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MtkN1
MtkN1 / checkout.py
Created February 8, 2025 14:25
Retrieve GitHub repository archive and extract it to the expected directory.
# /// script
# requires-python = ">=3"
# dependencies = []
# ///
from __future__ import annotations
import shutil
import tarfile
import urllib.request
@MtkN1
MtkN1 / dataclass_alias.py
Created January 1, 2025 16:34
Dataclass with alias field
from __future__ import annotations
import json
from collections.abc import Mapping
from dataclasses import dataclass, field, fields
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from _typeshed import DataclassInstance
@MtkN1
MtkN1 / bybit_ticker_ts.py
Created October 9, 2024 09:48
Add โ€œtsโ€ to the Bybit Ticker store
import asyncio
import pybotters
class CustomTicker(pybotters.DataStore):
_KEYS = ["symbol"]
def _onmessage(self, msg, topic_ext: list[str]) -> None:
item = msg["data"]
@MtkN1
MtkN1 / discord_notify.py
Last active October 8, 2024 03:11
Discord notify sample
import json
import os
import requests
# Discord ใฎ ใƒใƒฃใƒณใƒใƒซใฎ็ทจ้›† -> ้€ฃๆบใ‚ตใƒผใƒ“ใ‚น -> ใ‚ฆใ‚งใƒ–ใƒ•ใƒƒใ‚ฏใ‚’ไฝœๆˆ -> ใ‚ฆใ‚งใƒ–ใƒ•ใƒƒใ‚ฏ URL ใ‚’ใ‚ณใƒ”ใƒผ ใงๅ–ๅพ—ใงใใ‚‹
WEBHOOK_URL = os.getenv("WEBHOOK_URL", "https://discordapp.com/api/webhooks/...")
# bitFlyer REST API ใง ticker ใ‚’ๅ–ๅพ—ใ™ใ‚‹ (ใ‚ตใƒณใƒ—ใƒซ)
r = requests.get("https://api.bitflyer.com/v1/ticker")
@MtkN1
MtkN1 / bittrade_http.py
Last active September 6, 2024 18:30
pybotters 1.5 Sample code
# /// script
# requires-python = ">=3.8"
# dependencies = [
# "pybotters>=1.5",
# "rich>=9.1",
# ]
# ///
import asyncio
import os
@MtkN1
MtkN1 / pydantic_cattrs_timeit.ipynb
Created July 28, 2024 16:00
pydantic vs. cattrs performance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MtkN1
MtkN1 / README.md
Created June 6, 2024 07:54 — forked from florimondmanca/httpx-urllib3.md
URLLib3 transport implementation (Extracted from HTTPX)

urllib3-transport

An HTTPCore transport that uses urllib3 as the HTTP networking backend. (This was initially shipped with HTTPX.)

When used with HTTPX, this transport makes it easier to transition from Requests to HTTPX by keeping the same underlying HTTP networking layer.

Compatible with: HTTPX 0.15.x, 0.16.x (i.e. HTTPCore 0.11.x and HTTPCore 0.12.x).

Note: not all urllib3 pool manager options are supported here โ€” feel free to adapt this gist to your specific needs.

@MtkN1
MtkN1 / pyproject.toml
Created May 10, 2024 08:54
pyproject.toml differences between Hatch v1.9 and v1.10
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "hatch-demo"
dynamic = ["version"]
description = ''
readme = "README.md"
requires-python = ">=3.8"
@MtkN1
MtkN1 / noxfile.py
Created April 4, 2024 14:06
nox for Rye (it works, sort of)
import nox
import os
from pathlib import Path
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
VENV_BACKEND = "uv"
def ensurepath():
rye_home = os.getenv("RYE_HOME")