Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
jdtsmith / hammerspoon-shell.el
Last active May 4, 2019 16:14
Simple Emacs shell for Hammerspoon, using the /usr/local/bin/hs -C shell process
;;===> hammerspoon-shell
;; Quick and dirty shell with interactive history search and persistence
;; Just drop into your ~/.emacs file.
;;
;; A hammerspoon buffer is any lua buffer visiting a pathname like
;; **/*hammerspoon**/*.lua
;; Usage: M-x hammerspoon-shell, or Hyper-s in a hammerspoon buffer.
;; In any hammerspoon buffer, Hyper-c runs dofile(file) on the visited file.
;;
;; Tip: to reload a Spoon "MySpoon" without hs.reload:
@jdtsmith
jdtsmith / coro_searchPath.lua
Last active October 29, 2020 01:47
Simple example of coroutine based recursive searchPath
ax=hs.axuielement
dockAX = ax.applicationElement(hs.application("Dock"))
ids={"mc","mc.display","mc.spaces"}
scf={}
for i,id in ipairs(ids) do
table.insert(scf,ax.searchCriteriaFunction(
{{attribute="AXRole", value="AXGroup"},
{attribute="AXIdentifier",value=id}}))
@jdtsmith
jdtsmith / lvgl_util.py
Last active October 19, 2021 00:14
LVGL MicroPython custom set_attribute
import lvgl as lv
import display
fontBase = 'font_montserrat'
# Colors (+ BLACK and WHITE, NONE = black)
# AMBER BLUE BLUE_GREY BROWN
# CYAN DEEP_ORANGE DEEP_PURPLE GREEN
# GREY INDIGO LIGHT_BLUE LIGHT_GREEN
# LIME NONE ORANGE PINK
# PURPLE RED TEAL YELLOW
@jdtsmith
jdtsmith / test_bv.py
Created May 10, 2022 21:23
BoundedPar
import numpy as np
from astropy.table import Table
from astropy.table.pprint import TableFormatter
def fmt_func(fmt):
return lambda val: (f'{val["par"]:{fmt}} '
f'({val["pmn"]:{fmt}}, {val["pmx"]:{fmt}})')
PAR_DTYPE = np.dtype([('par', 'f8'), ('pmn', 'f8'), ('pmx', 'f8')])
@jdtsmith
jdtsmith / chain.py
Last active February 21, 2023 07:38
IPython chained exception debugging
""" %chain - IPython magic to inspect and move along exception chains.
JD Smith (2022)
Chained exceptions are associated with the messages:
"During handling of the above exception, another exception occurred"
"The above exception was the direct cause of the following exception"
and post-mortem debugging (%debug) by default can only examine the
@jdtsmith
jdtsmith / ot.el
Last active October 26, 2022 17:50
org transpose: transpose shared level 1 and level 2 org headlines (i.e. grouping by level 2), and display in a new (read-only) buffer.
(defun my/org-transpose-view ()
(interactive)
(let* ((tree (org-element-parse-buffer 'headline))
(buf (current-buffer))
(tbuf (concat "*" (buffer-name buf) "-transpose*"))
tp)
(org-element-map tree 'headline
(lambda (hl)
(if (eq (org-element-property :level hl) 2) ;only level 2
(let* ((l2 (org-element-property :raw-value hl))
@jdtsmith
jdtsmith / consult-org-heading-store-link.el
Last active February 24, 2024 01:49
Insert link from consult-org-headings with embark
@jdtsmith
jdtsmith / convenient-struct-handles.el
Last active November 5, 2022 00:49
Using `cl-defstruct` structure with `cl-macrolet-symbol` for very convenient read/write access to structure slots by name.
(defmacro with-convenient-slots (slots obj &rest body)
"Convenience wrapper for read/write access to struct data.
Bind slot names SLOTS (a list) within the `my-struct'
record OBJ, and execute BODY."
`(cl-symbol-macrolet
,(cl-loop for slot in slots
collect `(,slot (,(intern (concat "my-struct-"
(symbol-name slot)))
,obj)))
,@body))
@jdtsmith
jdtsmith / embark-bindings.org
Last active November 3, 2022 14:43
embark-bindings.org

Using embark-bindings, together with vertico, orderless, and marginalia, you can easily search through available bindings.

@jdtsmith
jdtsmith / eglot_didchange.el
Last active December 6, 2022 02:29
Testing framework for Eglot's textDocument/didChange events
(defvar-local eglot-report-didChange-marker nil)
(defvar-local eglot-report-didChange-buffer nil)
(defun eglot-report-didChange (change-beg change-end prev-len)
"Scan eglot events buffer and report textDocument/didChange events compactly.
Invoke this command in a given eglot events buffer."
(save-excursion
(goto-char eglot-report-didChange-marker)
(while (re-search-forward
"(:jsonrpc \"2.0\" :method \"textDocument/didChange\"" nil t)
(goto-char (match-beginning 0))