Skip to content

Instantly share code, notes, and snippets.

View gwerbin's full-sized avatar
💭
I might be slow to respond.

Greg Werbin gwerbin

💭
I might be slow to respond.
View GitHub Profile
@gwerbin
gwerbin / build.sh
Created April 3, 2024 20:23
Optimized builds with Pyenv
brew install openssl@3 readline tcl-tk
export PYENV_CCACHE_DISABLE=1
export PYTHON_CFLAGS='-mcpu=native'
export PYTHON_CONFIGURE_OPTS='--enable-optimizations'
MAKE_OPTS='-j4' pyenv install -f 3.8
export PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto'
MAKE_OPTS='-j4' pyenv install -f 3.9 3.10 3.11 3.12
module Interval
import Data.So
-- [TODO] Can we use a "parameters" block to avoid writing `Ord t =>` everywhere?
public export
rangeValid : Ord t => (closed : Bool) -> (lower: t) -> (upper: t) -> Bool
rangeValid closed lower upper = (ifThenElse closed (<=) (<)) lower upper
@gwerbin
gwerbin / comprehensions.py
Created August 9, 2023 15:13
Python "comprehension" expressions
## Lists
result_list_1 = []
for x in xs:
for y in ys:
for z in zs:
if condition(x, y, z):
result_list_1.append((x, y, z))
result_list_2 = [
@gwerbin
gwerbin / _builtin.sh
Created July 19, 2023 16:11
Quoting "dotenv" files.
dotenv list --format=shell
@gwerbin
gwerbin / pyproject.toml
Last active December 8, 2022 21:13
Flakeheaven config for using flake8-rst-docstrings (https://github.com/peterjc/flake8-rst-docstrings/) with Sphinx
[tool.flakeheaven]
max-line-length = 88
format = 'grouped'
# Options for flake8-rst-docstrings
# https://github.com/peterjc/flake8-rst-docstrings#configuration
rst-roles = [
# Built-in roles
@gwerbin
gwerbin / collect-alist.lisp
Last active December 8, 2022 03:39
Collect a list into a list of pairs (an "alist")
; https://stackoverflow.com/a/40028542/2954547
(defun collect-alist-loop (items)
(unless (evenp (length items))
(error "Items must have an even number of pairs!"))
(loop
:for (a b)
:on items
:by #'cddr
:collect (cons a b)))
@gwerbin
gwerbin / extractdep.py
Created November 16, 2022 06:49
Extract deps from pyproject 'project' section, PEP 621 (https://peps.python.org/pep-0621/)
#!/usr/bin/env python
r"""Extract dependencies from Pyproject PEP 621 "project" section.
Specificiation: https://peps.python.org/pep-0621/
"""
import sys
from argparse import ArgumentParser
from enum import IntEnum
@gwerbin
gwerbin / export.py
Created November 7, 2022 21:17
Helper to "export" names in a module
from collections import UserString
from collections.abc import Callable, Mapping
from typing import Any, MutableSequence, ParamSpec, Protocol, TypeVar, overload
from typing_extensions import Self, Unpack
class _HasName(Protocol):
__name__: str
@gwerbin
gwerbin / indent_lines.py
Created November 7, 2022 21:14
Indent lines of text in a string
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
@gwerbin
gwerbin / easylog.py
Created November 7, 2022 21:09
Easy logging setup
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