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/python3.10 | |
# -*- coding: utf-8 -*- | |
import asyncio | |
import sys | |
import importlib | |
from functools import reduce | |
from typing import Any | |
def import_from_string(import_str: str) -> Any: |
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
addEventListener("fetch", (event) => { | |
event.respondWith( | |
handleRequest(event.request).catch( | |
(err) => new Response(err.stack, { status: 500 }) | |
) | |
); | |
}); | |
async function handleRequest(request) { | |
const url = getUrl(request) |
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
addEventListener("fetch", (event) => { | |
event.respondWith( | |
handleRequest(event.request).catch( | |
(err) => new Response(err.stack, { status: 500 }) | |
) | |
); | |
}); | |
async function handleRequest(request) { | |
const { host, pathname } = new URL(request.url) |
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
#!/bin/bash | |
sudo apt-get update | |
sudo apt-get install -y \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg \ | |
lsb-release |
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 Any, Dict, List | |
from django.core.exceptions import FieldDoesNotExist | |
from django.db import models | |
def serialize_model(model: models.Model) -> Dict[str, Any]: | |
result = { | |
name: serialize_model(foreign_key) | |
for name, foreign_key in model.__dict__["_state"].__dict__.get("fields_cache", {}).items() |
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
Y = lambda g: (lambda f: g(lambda arg: f(f)(arg))) (lambda f: g(lambda arg: f(f)(arg))) | |
if __name__ == "__main__": | |
fib = Y(lambda f: lambda n: (1 if n < 3 else f(n-1) + f(n-2))) | |
print(fib(10)) |
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
""" | |
https://peps.python.org/pep-3333/ | |
""" | |
from types import TracebackType | |
from typing import ( | |
Any, | |
Callable, | |
Iterable, | |
List, | |
Optional, |
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 pathlib import Path | |
def ensure_pep563(dirpath: Path) -> None: | |
self_path = Path(__file__).absolute() | |
future_import = "from __future__ import annotations" | |
for pypath in dirpath.glob("**/*.py"): | |
if pypath.absolute() == self_path: | |
continue |
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
FOR /F "tokens=11 delims=\" %p IN ('REG QUERY "HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Mappings"') DO CheckNetIsolation.exe LoopbackExempt -a -p=%p |
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 math | |
from hashlib import blake2b | |
class BloomFilter: | |
def __init__(self, elements_count: int, *, error_rate: float = 0.0001) -> None: | |
byte_count = 1 + int( | |
-(math.log(error_rate) / math.log(2) ** 2) * elements_count // 8 | |
) | |
digest_size = int(math.log2(elements_count)) + (elements_count % 2) |