Skip to content

Instantly share code, notes, and snippets.

@nullbath
nullbath / drug-log.el
Last active April 2, 2025 01:20
Simple elisp function for tracking medication, leveraging Org-roam dailies.
(defun drug-log ()
"Log medication in org-roam daily with timestamp, amount, and type."
(interactive)
(org-roam-dailies-goto-today)
(let ((amount (read-string "Amount: "))
(medicine (read-string "Medicine: ")))
(org-insert-heading)
(insert (format-time-string "%H:%M"))
(newline)
(insert (format "Amount: %s\nMedicine: %s" amount medicine))))
@nullbath
nullbath / lispy-meow-keymap.el
Last active April 2, 2025 01:19
Keymap for the Meow modal editor that implements Lispy for efficient sexp editing. Handles escaping to lispy-mode from Meow's insert state.
(setq meow-paren-keymap (make-keymap))
(meow-define-state paren
"meow state for interacting with smartparens"
:lighter " [P]"
:keymap meow-paren-keymap)
(setq meow-cursor-type-paren 'hollow)
(meow-define-keys 'paren
'("<escape>" . meow-normal-mode)
@nullbath
nullbath / nbquickrepoclone.el
Created April 2, 2025 01:18
Clone a Github repository /tmp/ and move to that directory.
(defun nb/quick-repo-clone (repo)
"Clone a GitHub repo to /tmp/ and open it in a buffer."
(interactive "sEnter GitHub repo URL: ")
(let* ((url (url-generic-parse-url repo))
(path (url-path-and-query url))
(dir-name (file-name-nondirectory (car path)))
(dir (expand-file-name dir-name "/tmp/")))
(message "Cloning %s to %s..." repo dir)
(shell-command (format "git clone %s %s" repo dir))
(when (file-directory-p dir)
(defun my-context-aware-help-at-point ()
"Call sly-describe-symbol in sly buffers, otherwise helpful-at-point."
(interactive)
(if (or (derived-mode-p 'lisp-mode)
(bound-and-true-p sly-mode)
(member major-mode '(sly-mrepl-mode
sly-inspector-mode
sly-db-mode
sly-xref-mode
sly-stickers-mode
@nullbath
nullbath / nbstitchimages.el
Created April 3, 2025 14:51
Stitch images in either vertical or horizontal orientation
(defun nb/stitch-images ()
"Stitch images together horizontally or vertically using ImageMagick."
(interactive)
(let* ((files (completing-read-multiple "Select images (comma-separated): "
(directory-files default-directory t "\\.\\(jpg\\|png\\|gif\\)$")))
(direction (completing-read "Direction (h/v): " '("h" "v")))
(output-file (expand-file-name (read-file-name "Save as: ")))
(append-type (if (string= direction "h") "+append" "-append"))
(status (apply #'call-process "magick" nil "*magick-output*" nil
(append files (list append-type output-file)))))
@nullbath
nullbath / gptel-fn-complete-extras.el
Created May 10, 2025 18:41
extras for using gptel-fn-complete as a quick llm autocomplete
(defgroup gptel-context nil
"Context helpers for gptel."
:group 'gptel)
(defcustom gptel-context-lines-around 10
"Number of lines above and below point to add as context."
:type 'integer
:group 'gptel-context)
(defun gptel-context-add-lines-around ()
@nullbath
nullbath / sd-webui-generate-image.el
Created May 23, 2025 13:21
Generate image with Stable Diffusion Webui inside of Emacs. Includes progress.
;;; -*- lexical-binding: t -*-
(require 'request)
(require 'json)
(defun sd-webui-generate-image (prompt)
(interactive "sPrompt: ")
(let* ((api-url "http://192.168.1.47:7860/sdapi/v1/txt2img")
(prog-url "http://192.168.1.47:7860/sdapi/v1/progress")
(out-file (expand-file-name
(format "sd-%s.png" (format-time-string "%Y%m%d%H%M%S"))
@nullbath
nullbath / myrient-elisp-scraper.el
Created August 2, 2025 15:09
Scrape ISOs from Myrient archives
(require 'url)
(require 'dom)
(require 'cl-lib)
(defvar myrient-max-recursion-depth 5
"Max recursion depth for scraping Myrient files.")
(defun myrient-valid-subdir-p (url base-url)
"Check if URL is a valid subdirectory under BASE-URL without malformed parts."
(and (string-prefix-p base-url url)
@nullbath
nullbath / pacman-transient.el
Last active August 10, 2025 00:56
A transient menu for Pacman on Arch linux. Supports AUR packages through Yay.
(defun pacman-run-command (command &optional special-buffer)
"Run shell COMMAND in a dedicated buffer and switch to it."
(let ((buffer (get-buffer-create (or special-buffer "*Pacman Output*"))))
(with-current-buffer buffer
(setq buffer-read-only nil)
(erase-buffer)
(compilation-mode)
(setq buffer-read-only t))
(async-shell-command command buffer)
(pop-to-buffer buffer)
@nullbath
nullbath / nb-emms-play-remote.el
Last active August 15, 2025 15:45
Using Tramp, copy file from remote to local tmp and play the file with emms.
(defvar my-emms--temp-file nil
"Full path of the temporary file that EMMS is currently playing.
The value is set by `my-emms-play-remote' and cleared by `my-emms--cleanup'.")
(defun nb/emms-play-remote (tramp-path)
"Play a remote audio file via EMMS (mpv backend).
TRAMP‑PATH is a Tramp‑style file name, e.g.
`/ssh:nullbath@homelab:/home/nullbath/music/track.mp3'.