Skip to content

Instantly share code, notes, and snippets.

@borwickatuw
borwickatuw / wrapfunc.lisp
Last active March 24, 2025 22:51
Common Lisp/sbcl: map a function's return values
(defun multiple-value-plist (properties func &rest args)
"Wrap a function call, binding each return value to properties specified in `properties. Returns a plist.
For example:
(multiple-value-plist '(:return-arg1 :return-arg2) #'func args)
would return a plist with properties `return-arg1` and `return-arg2` bound to the first and second values returned from `#'func`."
(let ((return-vals (multiple-value-list (apply func args))))
; thanks to copilot for this:
@borwickatuw
borwickatuw / _header_value_parser.py.patch
Last active October 26, 2023 23:00
workaround for Python offlineimap error "obs_local_part[0].token_type == 'dot'"
--- /old/_header_value_parser.py 2023-10-26 15:58:17.000000000 -0700
+++ /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/email/_header_value_parser.py 2023-10-26 15:58:29.000000000 -0700
@@ -1513,6 +1513,9 @@
raise
token, value = get_cfws(value)
obs_local_part.append(token)
+ if not obs_local_part:
+ return obs_local_part, value
+
if (obs_local_part[0].token_type == 'dot' or
@borwickatuw
borwickatuw / gist:3f5c905f3902bb7bc55574f236178681
Created October 23, 2023 16:41
URLs that need escaping - perl one-liner
# This finds org-mode links that have slashes in them. I used this to find URLs that needed
# org-mode "escaping" with ='s around them (e.g. example.com/this/that/ --> =example.com/this/that/= )
# close ARGV if eof resets $. (the line number)
perl -lne 'print "$ARGV $.: $1" if m|(\[https:[^\]]+\]\[[^\]]+/.*?\])|; close ARGV if eof;' *
@borwickatuw
borwickatuw / qr_code.sh
Created August 29, 2023 22:32
generate qr codes
#!/bin/bash
URL=$1
if [ "x$URL" == "x" ]
then
echo "Run as: $0 url"
exit 1
fi
@borwickatuw
borwickatuw / gist:17d4ca34dffe14c2d807aa91ffcb5339
Created July 22, 2023 00:06
PyMySQL yeet database connection
"""
The below code will connect to a very old and insecure MySQL database. Do not use this for anything important!
No warranty is expressed or implied.
You must use Python ≤3.9 to be able to connect with OpenSSL 1.0
"""
ctx = ssl.create_default_context()
# https://stackoverflow.com/a/69457639/14068848
ctx.set_ciphers('ALL:@SECLEVEL=0')
# https://stackoverflow.com/a/33770290/14068848
@borwickatuw
borwickatuw / header_value_parser.patch
Created January 5, 2023 19:09
Workaround for _header_value_parser.py when the message ID has brackets in it
--- unpatched.py 2023-01-05 11:07:46.000000000 -0800
+++ email/_header_value_parser.py 2023-01-05 11:07:06.000000000 -0800
@@ -1485,6 +1485,8 @@
"""
obs_local_part = ObsLocalPart()
last_non_ws_was_dot = False
+ if len(value) >= 3 and value[0]=='[' and value[-2]==']':
+ value = value[1:-2] + value[-1]
while value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):
if value[0] == '.':
import logging
import os
if os.environ.get('DEBUG', False):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
@borwickatuw
borwickatuw / recent-google-drive-files.el
Created February 12, 2022 00:02
Emacs function to any Google Drive files modified in the last 14 days
(browse-url (concat "https://drive.google.com/drive/search?q=type:document%20after:"
(format-time-string "%Y-%m-%d"
(time-subtract (current-time) (days-to-time 14)))))
# per https://linuxhint.com/extend-xfs-filesystem-linux-without-lvm/
# this assumes there's only one partition, which is true for me with Vagrant+CentOS 7
sudo yum install cloud-utils-growpart gdisk
growpart /dev/sda 1
xfs_growfs /
@borwickatuw
borwickatuw / venv.sh
Created July 20, 2021 18:35
bash_profile for venv_cd
# from https://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/:
#
# Automatically activate Git projects' virtual environments based on the
# directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd {
# Check that this is a Git repo
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`
if [ $? == 0 ]; then
# Find the repo root and check for virtualenv name override