Skip to content

Instantly share code, notes, and snippets.

View linktohack's full-sized avatar

Quang-Linh LE linktohack

View GitHub Profile
@linktohack
linktohack / init.fnl
Created March 18, 2022 16:57
Hammerspoon fennel REPL
(local fennel (require :fennel))
(require :hs.ipc)
(let [coro (coroutine.create fennel.repl)]
(coroutine.resume coro {:readChunk (fn []
(let [input (coroutine.yield)]
(.. input "\n")))
:onValues (fn [xs]
(print (table.concat xs "\t")))
:onError (fn [_ msg]
@linktohack
linktohack / *scratch*.sh
Last active March 15, 2022 10:29
Health check SSL (restart to take new SSL cert)
[[ "$(date '+%Y-%m-%d')" < "$(date '+%Y-%m-%d' -d "$(openssl s_client -connect localhost:465 2>/dev/null </dev/null | openssl x509 -noout -dates | awk -F= '/notAfter/ { print $2 " - 1 month" }')" )" ]]
@linktohack
linktohack / *scratch*.py
Created March 9, 2022 13:47
NeoPixel heart beat
pixels.fill((0, 128, 0))
pixels.show()
time.sleep(1.0)
pixels.fill((0, 255, 0))
pixels.show()
time.sleep(0.05)
pixels.fill((0, 128, 0))
pixels.show()
@linktohack
linktohack / for_blackbox.sh
Last active July 5, 2022 07:56
KUBERNETES List all ingress
k get ingress -A --output json | jq '
def pad(n): tostring | if length >= n then . else ([range(n-length) | "0"] | join("")) + . end;
.items
| sort_by(.metadata.namespace)
| map({ ns: .metadata.namespace, name: .spec.rules[].http.paths[].backend.service.name, host: .spec.rules[].host, path: .spec.rules[].http.paths[].path })
| to_entries
| map({ name: [.value.ns, .value.name, .key | pad(2)] | join("-"), url: ["https://", .value.host, .value.path] | join("") })
| map(select(.url | contains("*") | not))
| unique_by(.url)
| sort_by(.name)
@linktohack
linktohack / kobocomic
Created November 10, 2021 23:52
KOBO Modifies CBR and CBZ files to be displayed correctly on Kobo devices
#!/bin/bash
# kobocomic: Modifies CBR and CBZ files to be displayed correctly on Kobo devices
# Requires perl, rar, unrar, zip, unzip
if [ "$#" -lt 1 ]; then
echo Supply a CBZ, CBR, ZIP, or RAR file to modify.
exit
fi
if [ -d "tmp_kobocomic" ]; then
@linktohack
linktohack / rmacs.el
Last active November 10, 2021 16:34
Rmate style remote editing with Emacs
(make-network-process :name "rmacs"
:server t
:host 'local
:service 52699
:filter #'(lambda (proc string)
(delete-process proc)
(raise-frame)
(let ((tramp-allow-unsafe-temporary-files t))
(find-file (string-trim string)))))
;; (delete-process "rmacs")
@linktohack
linktohack / tldr.sh
Created September 30, 2021 09:59
tldr with fzf integration
function tl() {
tldr --list | awk -v RS=', |\n' '/^[^\s]/ { print }' \
| fzf --preview 'tldr {}' --query "$1" \
| xargs -I{} tldr '{}'
}
@linktohack
linktohack / clock.lua
Created August 24, 2021 08:59
HAMMERSPOOL Clock item in menubar
local clockingLog = hs.logger.new("clocking")
local clockingMenu = hs.menubar.new()
local currentTask = nil
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local function eval(sexp, callback)
hs.task.new(
@linktohack
linktohack / tab-line-close-tab-function.el
Created July 30, 2021 11:07
Delete window when the last tab buried.
(setq tab-line-close-tab-function
#'(lambda (tab)
"Delete window when the last tab buried."
(let* ((buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))
(window (get-buffer-window buffer)))
(with-selected-window (or window (selected-window))
(let ((last-tab-p (length< (tab-line-tabs-window-buffers) 2)))
(if (eq buffer (current-buffer))
(bury-buffer)
(set-window-prev-buffers nil (assq-delete-all buffer (window-prev-buffers)))
@linktohack
linktohack / kubel-lens.el
Last active February 25, 2022 14:50
KUBEL with Lens config
(defvar helm-source-lens-kubeconfigs nil "Lens kubeconfigs source")
(defun my/kubel-with-lens-configs (&optional kubeconfigs-dir)
"Launch kubel with Lens configs.
Require `yq' (a wrapper of `jq' for `yaml') in your path."
(interactive)
(unless kubeconfigs-dir
(setq kubeconfigs-dir "~/Library/Application Support/Lens/kubeconfigs"))