This file contains hidden or 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
| # OLD | |
| from collections import deque | |
| queue = deque(starting_values) | |
| while queue: | |
| item = queue.popleft() | |
| queue.extend(item.children) | |
| # ... do things with item ... | |
| # Less alloc |
This file contains hidden or 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 gc | |
| from operator import call | |
| from weakref import ref, ReferenceType, WeakKeyDictionary | |
| from typing import TypeVar, Generic, Set, List, Dict | |
| T = TypeVar("T") | |
| class WeakChildRelationship(Generic[T]): | |
| __slots__ = ("_dict",) |
This file contains hidden or 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 __future__ import annotations | |
| from collections import deque | |
| from dataclasses import dataclass | |
| from contextlib import contextmanager | |
| from concurrent.futures import Future | |
| from threading import Lock, Event, local | |
| from weakref import ref, ReferenceType | |
| from enum import Enum | |
| import gc |
This file contains hidden or 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 functools import partial, reduce | |
| class M: | |
| def __init__(self, val): | |
| self.val=val | |
| def map(self, func): | |
| return M(func(self.val)) | |
| def bind(self, func): | |
| return M(func(self.val).val) | |
| def __repr__(self): |
This file contains hidden or 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 overload, Any | |
| # <gen_get_overloads codegen> | |
| # Anything in here is replaced with the result of gen_get_overloads() | |
| # </gen_get_overloads> | |
| def get(val: Any) -> Any: | |
| return val | |
| if __name__ == "__main__": |
This file contains hidden or 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
| # Make cards out of exported lists | |
| # https://5e.tools/makecards.html | |
| # Export then pass to tool to add background images | |
| import json | |
| import argparse | |
| import unicodedata | |
| import urllib.parse | |
| import urllib.request |
This file contains hidden or 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 time | |
| import sys | |
| anim = ( | |
| "\r| |", | |
| "\r| |", | |
| "\r| |", | |
| "\r| |", | |
| "\r| |", | |
| "\r} |", |
This file contains hidden or 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 dataclasses | |
| class DataFactory(type): | |
| def from_number(cls, num: int) -> "Data": | |
| return cls(str(num)) | |
| @dataclasses.dataclass | |
| class Data(metaclass=DataFactory): | |
| value: str |
This file contains hidden or 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
| " Install vim-plug with following command | |
| " curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
| " Then ':PlugInstall' to install them | |
| " Set leader to space. This is set up before plugins are loaded. | |
| let mapleader = " " " map leader to Space | |
| " Declare plugins | |
| call plug#begin() |
This file contains hidden or 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 functools import partial | |
| import builtins | |
| class Emoji: | |
| """ Execute functions with style """ | |
| __empty = object() | |
| def __init__(self, left=__empty, right=__empty): | |
| self.__left = left | |
| self.__right = right |
NewerOlder