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
Namespace | |
.signal(name) -> Signal | |
Signal | |
.connect(async fn) -> async fn | |
.send(*a, **kw) -> Set[Task] | |
async .join(*a, **kw) -> List[Any] | |
_global = Namespace() | |
signal = _global.Signal |
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 asyncio | |
import functools | |
import json | |
import secrets | |
import aiohttp | |
from concurrent.futures import ALL_COMPLETED | |
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 inspect | |
from typing import Callable, TypeDef | |
T = TypeDef("T") | |
def defer(func: Callable[[], T]) -> T: | |
sig = inspect.signature(func) | |
base = sig.return_type | |
double_entry = False | |
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
def in_base(n: int, alphabet: str) -> str: | |
b = len(alphabet) | |
s = [] | |
while n > 0: | |
d = n % b | |
s.append(alphabet[d]) | |
n //= b | |
return "".join(reversed(s)) | |
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
# fragments from evaluating some toolkit classes to succinctly build common queries in bloop | |
class QueryBuilder: | |
def __init__(self, engine): | |
self.engine = engine | |
self.index_cache = {} | |
def by_key(self, key_condition, *, index=None, **kwargs): | |
if isinstance(key_condition, AndCondition): | |
model = key_condition.values[0].model |
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 | |
# assumes bmi2 arch: "x86 64-bit with pext support" | |
# compiled binary ends in /opt/stockfish/$MAJOR_VERSION/bin/stockfish | |
set -e | |
set -x | |
sudo yum update -y | |
sudo yum install -y git gcc gcc-c++ |
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 functools | |
from typing import Type | |
from bloop.conditions import Condition, iter_columns | |
from bloop.models import BaseModel, Column, IMeta, bind_column | |
def default_hk_query(cls, engine, key=None, **kwargs): | |
key = Condition() | key | |
hk = cls.Meta.hash_key | |
if hk not in set(iter_columns(key)): |
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
# Three-table solution to https://stackoverflow.com/q/35825034 | |
# Generally this is a terrible idea, but it demos transactions (see the `new_user` method) and | |
# provides guaranteed uniqueness over a triplet of attributes. | |
# You could instead use optimistic writes (but be ready to clean up dangling records!), such as: | |
# (1) write Username if pk not exist, else fail | |
# (2) write Email if pk not exist, else roll back (1) and fail | |
# (3) write User if pk not exist, else roll back (1), (2) and fail | |
# (4) update (1), (2), (3) with attributes from each other so they are no longer dangling |
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
tool: rcon-cli https://github.com/itzg/rcon-cli | |
control.lua: | |
function Bench(x) | |
rcon.print(x+3) | |
end | |
commands.txt: | |
/silent-command Bench(2) | |
[9998 more copies] |
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
<!doctype html><meta charset="utf-8"/> | |
<script | |
src="https://cdnjs.cloudflare.com/ajax/libs/msgpack-lite/0.1.26/msgpack.min.js" | |
integrity="sha256-xnDLLYKxKFwLEmQK1SkZ9I7IwmjdeURGtXUk/0WnTRo=" | |
crossorigin="anonymous"></script> | |
<script | |
src="https://cdn.jsdelivr.net/npm/base64-js@1.3.0/base64js.min.js" | |
integrity="sha256-6Nq3ERANZFF5/7q3A7vSDHKttstfHieUf5+eFo9W4I0=" | |
crossorigin="anonymous"></script> | |
<script> |