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
@gwerbin
gwerbin / conda_env_export.py
Last active March 6, 2024 06:23
Export a Conda environment with --from-history, but also append Pip-installed dependencies
"""
Export a Conda environment with --from-history, but also append
Pip-installed dependencies
Exports only manually-installed dependencies, excluding build versions, but
including Pip-installed dependencies.
Lots of issues requesting this functionality in the Conda issue tracker,
e.g. https://github.com/conda/conda/issues/9628
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 / uninstall-ghostscript.sh
Last active August 18, 2023 07:52
Uninstall Ghostscript that comes with MacTex.
#!/usr/bin/env bash
# Copyright (c) 2015, 2020, and 2021 by Greg 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 FITNESS. IN NO EVENT
@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