Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
jdtsmith / audio_sync_rti.org
Last active June 30, 2023 22:06
WLED AudioSync Realtime Smoothing with Interpolation Proposal

Background

WLED supports a variety of network control protocols, including “realtime UDP” and (for audio-reactive ports) “Sound Sync”. UDP data “frames” comprising one or more packets are typically sent to WLED devices at fixed intervals, e.g. 20ms for the default 50Hz SoundSync update. Unfortunately, consumer-grade WiFi suffers from jitter of 20-80ms. Packets can occasionally arrive in rapid “floods” (several packets in <10ms), followed by long “droughts” of 75ms or more.

The solution? Buffer a fixed number of “frames” from the sporadically arriving packet data, playing back the oldest at smooth intervals, using the buffer to weather the droughts and floods. This dramatically smooths the intervals for playback. This approach effectively trades latency for smoothness of playback interval. This buffering approach is referred to as Realtime Smoothing (RTS).

@jdtsmith
jdtsmith / highlight-indentation-current-column-timer.el
Created May 2, 2023 15:49
Custom code with a timer delay for current-column marking in highlight indentation mode
(use-package highlight-indentation
:ensure highlight-indentation
:init
;; Add a timer delay to the current column highlight for efficiency,
;; and to avoid flashing when scrolling or moving by line
(defvar my/highlight-indentation-current-column-timer nil)
(defun my/highlight-indentation-current-column ()
(highlight-indentation-redraw-window (selected-window)
'highlight-indentation-current-column-overlay
'highlight-indentation-current-column-put-overlays-region))
@jdtsmith
jdtsmith / vundo-stress-test.el
Last active March 16, 2023 16:35
undo/redo + vundo stress test
;; Stress tests of the undo/vundo system
(require 'vundo)
(require 'lorem-ipsum)
(eval-when-compile
(require 'cl-lib))
(require 'memory-report)
(add-hook 'vundo-mode-hook (lambda () (setq jit-lock-mode nil)))
@jdtsmith
jdtsmith / rect-mark-modal.el
Last active March 8, 2023 07:19
Supercharge emacs rectangle-mark-mode with modal keys
(use-package rect
:init
(defun my/rect-transient-map-info ()
(interactive)
(with-help-window "Rectangle Mark Command Help"
(dolist
(l '("Rectangle Mark Mode Modal Commands\n"
"==================================\n\n"
"Insertion:\n\n"
" [o] open fill rectangle with spaces, moving adjacent text right\n"
@jdtsmith
jdtsmith / glitch.md
Created February 10, 2023 02:14
org smooth scrolling image glitch

Image glitch while mac-mouse-wheel-smooth-scroll=t (emacs-mac)

While smooth(=pixel) scrolling up past images displayed by org-display-inline-images (org 9.6.1), point loops back below the image, preventing you to scroll past it. See below for a video.

@jdtsmith
jdtsmith / toggle-debug-on-hidden-error.el
Last active August 25, 2023 02:31
Elisp: get stack trace for functions with suppressed errors (filter functions, post command hooks, etc.)
;;;; Power debugging
(defun my/reraise-error (func &rest args)
"Call function FUNC with ARGS and re-raise any error which occurs.
Useful for debugging post-command hooks and filter functions, which
normally have their errors suppressed."
(condition-case err
(apply func args)
((debug error) (signal (car err) (cdr err)))))
(defun toggle-debug-on-hidden-errors (func)
@jdtsmith
jdtsmith / emacs_async_yield_points.el
Last active December 28, 2022 19:23
Where precisely can Emacs take control of execution to deliver async process output to your filter-function?
(defvar-local still-waiting nil
"Whether we are still waiting for a chunk of process output to complete.")
(defun my-worker-1 (process)
"Do some work and yield to PROCESS output."
(do-some-sensitive-calculation)
(sit-for 1) ; A) output can interrupt me here
(another-sensitive-buffer-manipulation) ; B) what about here?
(my-worker-2 process))
@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))
@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 / 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))