Skip to content

Instantly share code, notes, and snippets.

Avatar

Quang-Linh LE linktohack

View GitHub Profile
@linktohack
linktohack / loki-pattern.txt
Created December 16, 2022 17:42
Pattern to match loki's log (Nginx and LB app)
View loki-pattern.txt
api.driver.cloud.private
api.driver.cloud.transalliance.eu
|~ "(?i)error"
|= `ms {`
| pattern `<ts> stdout F <method> <url> <code> <ms>ms {`
@linktohack
linktohack / touchid.sh
Created September 14, 2022 15:05
Enable TouchID for sudo
View touchid.sh
sudo sed -i '' '2i\
auth sufficient pam_tid.so
' /etc/pam.d/sudo
@linktohack
linktohack / *scratch*.sh
Created May 23, 2022 08:35
Barcode generator with ImageMagick
View *scratch*.sh
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 / coroutinize.fnl
Created March 28, 2022 23:05
Lua coroutinize
View coroutinize.fnl
;; -- Coroutinize
(fn coroutinize [f ...]
"Coroutinize a function `f' allow to to call functions with a callback within its body naturally
via coroutine, eliminate the callback hell.
These function often need to be evaluated in main thread or where `coroutine.resume' is not
availabe (Hammerspoon). The functions should to be wraped within `(fn [resolve] (f ... resolve))'
and yielded.They will be evaluated (in main thread) and come back via `coroutine.yield'
@linktohack
linktohack / init.fnl
Created March 18, 2022 16:57
Hammerspoon fennel REPL
View init.fnl
(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)
View *scratch*.sh
[[ "$(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
View *scratch*.py
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
View for_blackbox.sh
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
View kobocomic
#!/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
View rmacs.el
(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")