Skip to content

Instantly share code, notes, and snippets.

@kidd
kidd / init.lua
Last active October 3, 2024 09:40
hammerspoon snippet to c-n,c-p... in slack and chrome
local function remap(from_key, to_key)
return hs.hotkey.new(from_key[1], from_key[2],
function() hs.eventtap.keyStroke(to_key[1], to_key[2]) end)
end
local maps={}
local function remap_add(win_filter_name, from_key, to_key)
maps[win_filter_name] = maps[win_filter_name] or {}
table.insert(maps[win_filter_name], remap(from_key, to_key))
-- https://github.com/Hammerspoon/hammerspoon/issues/664
slack_c_n = hs.hotkey.new({"ctrl"}, 'n', function()
hs.eventtap.keyStroke({}, 'down')
end)
slack_c_p = hs.hotkey.new({"ctrl"}, 'p', function()
hs.eventtap.keyStroke({}, 'up')
end)
@kidd
kidd / init.el
Last active August 20, 2024 11:58
advice browse-url-at-point to account for stripe ids
;;; (keymap-global-set "C-c o" 'browse-url-at-point)
(defun rgc/add-stripe (args)
"prepend the right stripe path to be able to find the entity
you're looking for"
(let* ((arg (s-replace-regexp "^https?://" "" (car args)))
(path
(cond
(def hh [{:a 1, :b 2, :c 3 :aa 4} {:a 1, :b 2, :c 4 :aa 4} {:a 99, :b 2, :c 3 :aa 5}])
(def rname :trial-ups)
(def main-f [:b :a])
;; first stab, we pivot over the keys of the "root" entity,
;; group by them, and strip the rest out
(defn hydrate-with-main-entity-keys [m ks as]
(->> (group-by #(select-keys % main-f) hh)
(m/map-vals (partial map #(apply dissoc % main-f)))
@kidd
kidd / dup-file.sh
Created October 9, 2023 11:16
Duplicate file finder helpers
# helping to find dupes. Not complete,
# but this can serve as a basis for a pure shellscript dup finder
find . -type f -exec du -s {} \; -exec /usr/bin/basename {} \; >/tmp/list.txt
cat /tmp/list.txt | cut -f1 -d' ' | paste - - | grep png | sort | uniq| wc -l
cat /tmp/list.txt | cut -f1 -d' ' | paste - - | grep png | sort | wc -l
@kidd
kidd / fzf.sh
Last active October 4, 2023 07:53
pure shell naive version of a picker like fzf (without the filtering, but only picking by number)
# fzf is either fzf or a naive version of it
# the input is a sed line number, so it can be
# single number: 42
# range: 1,10
# separate lines: 10p;50p
mute command -v fzf ||
fzf() {
local in=$(cat)
for p in "${@}"; do
[ "$p" = "-0" ] && [ "$(echo "$in" | wc -l)" -eq 1 ] && [ "" = "$in" ] && return 1
@kidd
kidd / whiteboard.js
Created September 21, 2023 07:58
whiteboard bookmarklet
data:text/html,<canvas id="v"><script>d=document,d.body.style.margin=0,f=0,c=v.getContext("2d"),v.width=innerWidth,v.height=innerHeight,c.lineWidth=2,x=e=>e.clientX||e.touches[0].clientX,y=e=>e.clientY||e.touches[0].clientY,d.onmousedown=d.ontouchstart=e=>{f=1,e.preventDefault(),c.moveTo(x(e),y(e)),c.beginPath()},d.onmousemove=d.ontouchmove=e=>{f&&(c.lineTo(x(e),y(e)),c.stroke())},d.onmouseup=d.ontouchend=e=>f=0</script>
mb:maybehelp() {
local msg="$1";shift
if any equals_help "$@"; then
warn "$msg"
return 1
fi
}
mb:maybehelp "mmsg" "$@" || return 1
-- select internal.array_unique(array['foo','bar'] || array['foo'])
create or replace function array_unique (a text[]) returns text[] as $$
select array (
select distinct v from unnest(a) as b(v)
)
$$ language sql;
-- Example usage:
-- select ts, op, jsonb_pretty(mb_jsonb_diff(record, old_record))
-- from audit.record_version
@kidd
kidd / util.clj
Last active September 6, 2023 17:04
(defn apply-if
"if(p(m)) then f(m, ...args) else m
Useful for `maybe-*` like updates."
[m p f & args]
(if (p m)
(apply f m args)
m))
(defn fork [l c r]