Skip to content

Instantly share code, notes, and snippets.

View wsgac's full-sized avatar

Wojciech S. Gac wsgac

  • Keepit
  • Warszawa, Poland
View GitHub Profile
@wsgac
wsgac / mark-next-previous.el
Created July 16, 2025 11:27
Make Eww recognize additional types of URLs as next/previous
(defvar navigation-group-regex "postnav\\|navigation"
"Regular expression to match the class of the navigation container")
(defvar prev-link-labels-regex "earlier\\|previous"
"Regular expression matching the `previous` link")
(defvar next-link-labels-regex "later\\|next"
"Regular expression matching the `next` link")
(defun my-eww-add-rel-prev-next ()
"Add rel=\"prev\" and rel=\"next\" attributes to postnav links in EWW."
(when (eq major-mode 'eww-mode)
@wsgac
wsgac / get-file-path.el
Created June 11, 2025 09:59
Elisp function for getting position in files + an opinionated keybinding
(require 'cl-lib)
(defun get-current-file-path (prefix)
"Get filesystem from current buffer, provided it's a file buffer. With
prefix 4 also append line number. With prefix 16 append column number to
everything. Put the resulting string in the kill-ring and also display
it int the minibuffer."
(interactive "p")
(let* ((file-name (buffer-file-name (current-buffer)))
(position (when (>= prefix 4) (list ":" (int-to-string (line-number-at-pos)))))
@wsgac
wsgac / random-state.lisp
Created June 5, 2025 13:04
Common Lisp random state
;; Stores random state in a structure SB-KERNEL::RANDOM-STATE
*random-state*
;; Get the actual state vector
(sb-kernel::random-state-state *random-state*)
;; Intercept the state vector (copying it)
(defvar *rs1* (copy-seq (sb-kernel::random-state-state *random-state*)))
;; Sample a bunch of random numbers
@wsgac
wsgac / tooltips.el
Created May 9, 2025 14:41
Kanji-mode exploration with tooltips
;;;;;;;;;;;;;;
;; Tooltips ;;
;;;;;;;;;;;;;;
;; TODO: These need polishing and weaving them into the broader
;; picture
(defun get-point-coordinates ()
(let* ((posn (posn-at-point))
(abs-pos (posn-x-y posn))
@wsgac
wsgac / invert_recursive_dict.py
Created October 19, 2024 22:14
Recursive dict reversal in Python
def invert_recursive_dict(d: Dict) -> Dict:
"""
Assuming `d` is a recursive Dict, invert it by mapping its leaves to the
lists/paths of keys leading to them in the original dict.
"""
def invert(d, path: List, acc: Dict):
if isinstance(d, Dict):
# Handle dict contents recursively
for k, i in d.items():
invert(i, path+[k], acc)
@wsgac
wsgac / .psqlrc
Created July 29, 2024 09:41
More reasonable PSQL config
-- prevent noisy loading of psqlrc file
\set QUIET yes
--customize prompt
\set PROMPT1 '\n%[%033[1;31m%]➤ %[%033[2;37m%]%`\! date "+%F %I:%M %p %Z"`%[%033[0m%] %[%033[1;36m%]%n%@%/%[%033[1;31m%]%x %[%033[K%]%[%033[0m%]\n%[%033[1;33m%]%R%#%[%033[0m%] '
\set PROMPT2 '%[%033[1;33m%]%R%#%[%033[0m%] '
--show timing info for queries
\timing
-- allow pasting of values to avoid stupid indenting
\set paste
--get rid of duplicates in history
@wsgac
wsgac / lookup-fiveam-fixtures.lisp
Last active July 25, 2024 22:29
Teach SLIME how to jump to new kinds of definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HACK: Teach SLIME about jumping to FiveAM fixture definitions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'sb-introspect)
(ql:quickload :swank)
(ql:quickload :fiveam)
;; Poor man's defadvice - stolen from https://gist.github.com/spacebat/46740966846623148c014ab261050bc0
@wsgac
wsgac / paredit-setup.el
Last active September 24, 2024 14:41
A `use-package` enabled configuration of Paredit with an annoying problem worked around
;;;;;;;;;;;;;
;; Paredit ;;
;;;;;;;;;;;;;
(use-package paredit
:ensure t
:init
:config
(show-paren-mode t)
;; Workaround for superfluous spaces inserted in e.g. pathnames, as
@wsgac
wsgac / maze.hs
Created February 23, 2024 09:27
Some snippets from the IOHK Haskell course (https://github.com/input-output-hk/haskell-course)
{-
**************************** IMPORTANT ****************************
This week is a two-step homework. First, you have to solve the
"Maze" challenge, and then the "Forest" challenge. The challenges
are in two separate files in both the homework and solution, so
you can check the solution for the first "Maze" challenge without
spoilers of the "Forest" one. Make sure to check the solution for
"Maze" (and only "Maze," I see you 🥸👀) before starting with the
@wsgac
wsgac / requests_debugging.py
Last active November 30, 2023 12:38
How to enable request debugging in Python `requests` library
# Add debugging outputs to requests
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.