Skip to content

Instantly share code, notes, and snippets.

@garlic0x1
garlic0x1 / defmemo.lisp
Created November 22, 2023 05:08
defmemo/int->int
; depends on alexandria
; memoizes int->int functions in a mutable vec
(defmacro defmemo/int->int (size name (in) &body body)
(let ((memo-name (read-from-string (format nil "~a-memo" name))))
`(progn (defvar ,memo-name (make-array (+ 1 ,size) :initial-element nil))
(defun ,name (,in)
(if-let ((memo (aref ,memo-name ,in)))
memo
(setf (aref ,memo-name ,in) (progn ,@body)))))))
@garlic0x1
garlic0x1 / workers.lisp
Last active September 5, 2023 11:36
CL concurrent worker functions
(defpackage workers
(:use :cl)
(:export #:list->simple-cqueue
#:simple-cqueue->list
#:join-workers
#:join-consumers
#:wmap
#:wfilter
#:wforeach))
@garlic0x1
garlic0x1 / glob.scm
Last active August 28, 2023 08:52
scheme glob->regex
(module (web globby) (globby->regexpstr globby->regexp globby-match)
(import (garlic base) regex)
;; made this since the one in `regex` egg doesnt support globstar
(define (globby->regexpstr glob)
"Only supports | ? * **"
;; mutable variable to dedupe globstars, sorry
(define ignoring-stars #f)
@garlic0x1
garlic0x1 / mp3sort.scm
Created July 27, 2023 10:44
tag mp3s based on directory convention
(import (garlic base)
(garlic sys)
(garlic strings))
(define (tag-file dir file data)
(sh (string-append "id3v2 '" dir file "' -A " (car data) " -a " (cdr data))))
(define (escape-unix-filename-spaces name)
(string-replace " " "\\ " name))
@garlic0x1
garlic0x1 / gist:0b6db302aa1b079244176c1cfc79fef0
Last active July 25, 2023 09:06
[Clojure] Tally unique items in sequence
(defn tally
"tally unique things in a sequence"
[seq]
(reduce (fn [ag i] (update ag i (fnil inc 0))) {} seq))
;; (tally [:a :a :a :b :b :c])
;; => {:a 3, :b 2, :c 1}
@garlic0x1
garlic0x1 / hist
Created November 5, 2022 01:55
Search shell history in an easy format for copy/paste
if [ "$#" -eq 1 ]; then
history | cut -c 8- | grep $1
else
history | cut -c 8-
fi
@garlic0x1
garlic0x1 / wifi-connect
Created September 23, 2022 04:32
Fix Arch bug connecting to wifi using wifi-menu and iwd
#!/bin/bash
sudo systemctl stop netctl
sudo systemctl restart iwd
sudo ip link set wlan0 down
sudo wifi-menu
@garlic0x1
garlic0x1 / gist:60f907e1b1e736d8593d235572240a08
Last active May 29, 2022 02:41 — forked from cranelab/gist:940d76283414908b464074dba1aaa7af
all wp plugins with over 100+ active installations
5,000,000+ : wpforms-lite
5,000,000+ : wordpress-seo
5,000,000+ : woocommerce
5,000,000+ : really-simple-ssl
5,000,000+ : jetpack
5,000,000+ : elementor
5,000,000+ : contact-form-7
5,000,000+ : classic-editor
5,000,000+ : akismet
4,000,000+ : wordpress-importer