Skip to content

Instantly share code, notes, and snippets.

@jams2
jams2 / blocks.py
Created June 30, 2026 15:09
WIP wagtail block strategies for hypothesis
from functools import singledispatch, wraps
from typing import Callable, TypeVar
from hypothesis import assume, event
from hypothesis import strategies as st
from hypothesis.extra import django as dj
from wagtail import blocks
B = TypeVar("B", bound=blocks.Block)
@jams2
jams2 / generate_svg_report.py
Last active June 20, 2023 16:05
Script for generating cropped SVGs and HTML report for Willow
import glob
import io
import os
import sys
from pathlib import Path
from willow import Image
from willow.svg import SvgImage
@jams2
jams2 / .dir-locals.el
Last active April 4, 2022 08:55
Example directory local eglot-workspace-configuration for pylsp
;; Contains all the default values from:
;; https://github.com/python-lsp/python-lsp-server/blob/develop/pylsp/config/schema.json
;; Works on GNU Emacs 27.1
;; (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0) of 2021-01-18, modified by Debian
;; From looking at the server output, some plugins support additional options.
;; `jsonrpc--json-encode' calls `json-serialize' with (:false-object :json-false) and (:null-object nil).
((python-mode
. ((eglot-workspace-configuration
. ((pylsp
@jams2
jams2 / st.el
Last active August 28, 2020 19:08
Getting terminal Emacs to play nice with suckless st
; Emacs terminal frames and st aren't great friends at the moment.
; No support for 256 colours.
; Setting TERM=xterm-256color before invoking emacs (or emacsclient) causes a startup delay.
; It looks like there's a fix in the works for Emacs 28:
; https://lists.gnu.org/archive/html/emacs-devel/2020-08/msg00236.html
; But for now, you can handle it by putting something like the following in your init file.
(setq term-file-aliases (cons (cons "st-256color" "rxvt") term-file-aliases))
diff --git a/config.def.h b/config.def.h
index 1c0b587..38d2f6c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,7 @@
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
+static const unsigned int gappx = 5; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */
@jams2
jams2 / libgeos.py
Created December 2, 2019 14:53
Fixing Django/GEOS compatibility
"""The version regex in django/contrib/gis/geos/libgeos.py fails on
the latest homebrew geos install at time of writing, with message:
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.8.0-CAPI-1.13.1 "
The trailing whitespace is the culprit. Add a r'\s?$' to the end of the pattern.
"""
version_regex = re.compile(
@jams2
jams2 / cycleParen.vim
Created May 9, 2019 16:15
vimscript function for replacing pairs of parens
""""""""""""""""""""""""""""""""""""""""""
" Change matching pair of parens
nnoremap <leader>cp :call CycleParens()<CR>
function! CycleParens() abort
let parens = ['[', '{', '(', ']', '}', ')']
call CyclePairs(parens)
endfunction