Skip to content

Instantly share code, notes, and snippets.

View linktohack's full-sized avatar

Quang-Linh LE linktohack

View GitHub Profile
@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 / *scratch*.sh
Created May 23, 2022 08:35
Barcode generator with ImageMagick
for i in `seq 150 650`; do
convert -size 1016x200 -background white -fill black -font Libre-Barcode-39-Regular -pointsize 160 -gravity center caption:"*66250${i}*" -gravity south -extent 1016x260 -resize 1016x648\! "66250${i}.png"
done
convert *.png 0.pdf
@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 / rec.ml
Created July 4, 2018 14:29
REASONML Two modules
module Sig =
struct
module type NoteSig = sig type t end
module type TodoSig = sig type t end
end
module Same =
struct
module rec Note:Sig.NoteSig = struct type t = {
todo: Todo.t;} end
and Todo:Sig.TodoSig = struct type t = {
@linktohack
linktohack / org-sync-attachments.el
Last active February 25, 2022 14:54
Org Sync attachments
(defun org-sync-attachments ()
"Update the current entry's attachment metadata."
(interactive)
(let* ((attachments (if (org-attach-dir)
(org-attach-file-list (org-attach-dir))))
(tag-state (if attachments 'on 'off))
(org-attach-file-list-property "Attachments"))
(if attachments
(org-set-property org-attach-file-list-property
@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"))
@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 / 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(