Skip to content

Instantly share code, notes, and snippets.

@borwickatuw
borwickatuw / hyku_sword.py
Last active December 5, 2025 14:32
Initial Python wrapper for Hyku's SWORD endpoint. No warranty
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Wrapper around the SWORD API, targeting Hyku's SWORD API specifically.
"""
import io
import logging
import mimetypes
;; org-roam-copy.el --- Copy `:COPY:` property from an org-roam node
;; Author: John Borwick <borwick@uw.edu>
;; This file is NOT part of GNU Emacs.
;; Copyright (c) 2025 University of Washington
;; All rights reserved.
;; Redistribution and use in source and binary forms, with or without
@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)))))