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 cache | |
from types import UnionType | |
from typing import Annotated, Any, Literal, Union, get_args, get_origin | |
import pydantic | |
from pydantic.fields import PydanticUndefined as MISSING # type: ignore[attr-defined] | |
def normalize(t: Any) -> Any: | |
if get_origin(t) is Annotated: |
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
"""Basically the same as pydifact, but with some changes: | |
- Doesn't magically turn `[value] -> value`, each segment is a `list[list[str]]`. | |
- Public singular `segment_to_raw()` function. | |
- Easier to work out how the `Characters` configuration actually gets passed around. | |
- Simplified and de-OO-ed code. Doesn't handle segment names any differently to other values. | |
- Simpler style should make a rewrite-it-in-Rust (+PyO3) very easy if required. | |
""" | |
from __future__ import annotations |
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 os | |
from typing import TypeVar | |
import pydantic | |
T = TypeVar("T") | |
class _Missing: | |
... |
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
<style> | |
.red { | |
color: red; | |
} | |
</style> | |
<div id="root"></div> | |
<script> |
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
# pip install sqlalchemy testing.postgresql | |
# see also: https://blog.crunchydata.com/blog/message-queuing-using-native-postgresql | |
import threading | |
from contextlib import contextmanager | |
from sqlalchemy import Column, Integer, String, create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
import testing.postgresql |
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
# This is a version of https://gist.github.com/natekupp/1763661 without | |
# using mutation and with some other simplifications. Hopefully it's slightly | |
# easier to follow. Performance wise - from some small benchmarking - it has | |
# the same O(N) characteristics/memory usage, but is about twice as slow. | |
# | |
# Use it like: | |
# | |
# b = Node([], []) | |
# b = add(b, n) | |
# print(pp(b)) |
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
// ___________________________ | |
// _| generic constraint solver |__________________________________________________ | |
type Assignments<V> = {[K: string]: V} | |
type Constraint<V> = (assignments: Assignments<V>) => boolean | |
type KProperties<V> = { | |
domain: V[] | |
constraints: Constraint<V>[] | |
} | |
type Problem<V> = { |
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
// 80 line parser and interpreter for a small language with | |
// integers, assignments, lexical scope, first class functions | |
const source = ` | |
(block | |
(assign x 5) | |
(assign f | |
(function | |
(a b) | |
(block | |
(assign c (+ a b)) |
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
# 105 line parser and interpreter for a small language with | |
# integers, assignments, lexical scope, first class functions | |
from __future__ import annotations | |
from dataclasses import dataclass, replace | |
from typing import Callable, Union | |
source = """ | |
(#{ | |
(#= x 5) | |
(#= f |
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 base64 | |
from functools import lru_cache | |
import logging | |
from time import sleep, time | |
from typing import Dict, TypedDict, Tuple, List, TypeVar | |
import requests | |
from google.auth.transport.requests import AuthorizedSession | |
import google.auth |
NewerOlder