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
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> |
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 hashlib | |
import untangle | |
def load(filename): | |
with open(filename) as f: | |
return untangle.parse(f.read()) | |
def canonicalize_section(section): |
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
{ | |
"title": "Windows Keys", | |
"rules": [ | |
{ | |
"description": "Windows-style Home/End for non-iTerm applications", | |
"manipulators": [ | |
{ | |
"type": "basic", | |
"from": { | |
"key_code": "end" |
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 bloop.models import unpack_from_dynamodb | |
from bloop.signals import object_loaded | |
from bloop.stream.coordinator import Coordinator | |
class TableStream: | |
def __init__(self, *, stream_arn, engine, model_selector): | |
""" | |
model_selector is a function that takes a record | |
and returns a model class. for example: |
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
""" | |
Support evaluation of a very limited subset of operations and literals. | |
EvalContext supports a subset of operations common across many languages, | |
while PythonEvalContext adds on Sets, Tuples, Slices, and the literals | |
True, False, and None. | |
.. code-block:: pycon | |
>>> from eval_gist import EvalContext |
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 pendulum | |
from cryptography.hazmat.backends import default_backend | |
from cryptography.hazmat.primitives import hashes, serialization | |
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey | |
from bloop import UUID, Binary, Column | |
from bloop.ext.pendulum import DateTime | |