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
| class CaseMatched(Exception): | |
| pass | |
| class Switch: | |
| def __init__(self, expression, *, no_match_raise=True): | |
| self.expression = expression | |
| self._no_match_raise = no_match_raise | |
| self._any_case_called = False |
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 math | |
| from noise import snoise4 | |
| from PIL import Image, ImageShow | |
| import colorsys | |
| def quint(x: float) -> float: | |
| # https://easings.net/#easeInOutQuint | |
| return 16 * x * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 5) / 2 |
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 math | |
| from perlin_noise import PerlinNoise | |
| class Easings: | |
| # https://easings.net/ | |
| @staticmethod | |
| def ease_in_cubic(x: float) -> float: | |
| return x * x * x |
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 | |
| import asyncio | |
| import re | |
| from typing import NamedTuple, AsyncGenerator, Callable, TypedDict | |
| class Command(TypedDict): | |
| name: str | |
| aliases: list[str] | |
| callback: Callable |
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 random | |
| from typing import NamedTuple | |
| from pathlib import Path | |
| import pygame | |
| HERE = Path(__file__).absolute().parent | |
| FONT = HERE / 'Quicksand/static/Quicksand-SemiBold.ttf' | |
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 threading | |
| import time | |
| from queue import Queue | |
| def producer(q: Queue): | |
| number = 0 | |
| while True: | |
| q.put(number) | |
| number += 1 |
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 ast | |
| import json | |
| class NameTransformer(ast.NodeTransformer): | |
| def __init__(self, player): | |
| self.player = player | |
| def visit_Name(self, node: ast.Name): | |
| condition = node.id.split('__') |
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 json | |
| import ast | |
| class ValidateExpression(ast.NodeVisitor): | |
| allowed = { | |
| ast.Expression, | |
| ast.BoolOp, ast.UnaryOp, | |
| ast.And, ast.Not, ast.Or, | |
| ast.Call, |
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 math | |
| import pygame | |
| def bezier(points: list[pygame.Vector2], t: float): | |
| """calculate a point on a bezier curve with any number of points""" | |
| if len(points) == 1: | |
| return points[0] | |
| else: | |
| return (1 - t) * bezier(points[:-1], t) + t * bezier(points[1:], t) |
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 collections import Counter | |
| strs = ["eat", "tea", "tan", "ate", "nat", "bat"] | |
| d = {} | |
| for s in strs: | |
| c = frozenset(Counter(s).items()) | |
| d.setdefault(c, []).append(s) |