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 indent_lines(text: str, spaces: int | str = 4) -> str: | |
r"""Indent lines of text by some fixed amount. | |
:param text: The text to indent. | |
:param spaces: The amount of spaces to indent by, or an arbitrary string to use as a | |
line prefix. | |
:returns: The indented text. | |
""" | |
if isinstance(spaces, int): | |
spaces = " " * spaces |
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
# TODO: Thread & async safety | |
import sys | |
import time | |
from collections.abc import Callable | |
if sys.version_info >= (3, 11): | |
from typing import Self | |
else: | |
from typing_extensions import Self |
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 sys | |
from collections import UserString | |
from collections.abc import Callable, Mapping | |
from typing import Any, ParamSpec, TypeVar, overload | |
if sys.version_info >= (3, 11): | |
from typing import Self, Unpack | |
else: | |
from typing_extensions import Self, Unpack |
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
r"""Quickly configure a single logger. | |
Based on: https://docs.python.org/3/library/logging.html#logging.basicConfig | |
Adapted from my rejected PR: | |
https://github.com/python/cpython/compare/main...gwerbin:cpython:gwerbin/basicconfig-any-logger | |
""" | |
import logging | |
from collections.abc import Callable, Sequence |
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
# -*- coding: utf-8 -*- | |
# Copyright © 2022 by Gregory Werbin | |
# | |
# Permission to use, copy, modify, and/or distribute this software for any | |
# purpose with or without fee is hereby granted, provided that the above | |
# copyright notice and this permission notice appear in all copies. | |
# | |
# THE SOFTWARE IS PROVIDED “AS IS” AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD | |
# TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
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 unicodedata | |
def is_whitespace(c: str) -> bool: | |
"""Detect if a character is "whitespace". | |
As of 3.10, this is how CPython defines "whitespace" for string operations like `str.split`. | |
Sources: | |
* https://github.com/python/cpython/blob/v3.10.4/Objects/unicodeobject.c#L311-L340 | |
* https://github.com/python/cpython/blob/v3.10.4/Tools/unicode/makeunicodedata.py#L420-L422= |
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 zsh | |
setopt \ | |
err_exit \ | |
pipe_fail \ | |
warn_create_global \ | |
warn_nested_var \ | |
no_unset | |
version='1.0.0' |
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
module DoubleStuff | |
%foreignImport "scheme,chez:(double-stuff utils)" | |
"python:double_stuff" | |
-- "python:double_stuff,*" | |
namespace Exact | |
%foreign "scheme,chez:idris-fl=-2" | |
"python:double_stuff.idris_fleq2" | |
-- "python:idris_fleq2" |
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
#!/bin/sh | |
### Bootstrap build from an existing Idris 2 compiler. | |
set -eux | |
cd idris2 | |
## Build and install to final location, using whatever `idris2` is already in PATH. | |
install_prefix="${XDG_MISC_HOME:-$HOME/.local/opt}/idris2" |
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 zsh | |
emulate zsh | |
setopt err_exit pipe_fail warn_create_global warn_nested_var no_unset | |
if (( ${#@} == 0 )); then | |
data="$(cat)" | |
elif (( ${#@} == 1)); then | |
case $1 in | |
-) data="$(cat)" ;; |