Skip to content

Instantly share code, notes, and snippets.

Avatar

Quang-Linh LE linktohack

View GitHub Profile
@linktohack
linktohack / *scratch*.el
Last active March 23, 2023 10:04
Remove extranouse org ID
View *scratch*.el
;; evaluate this to remove all IDs that are neither: a target, has attachment(s) nor timestamp (synced with caldav)
;; assume everything is in `~/org', including archived files
;; require `rg', `jq' and `awk'
(let* ((default-directory (expand-file-name "~/org"))
(ids (-> (shell-command-to-string
"rg -a -g '*.org*' --json '^:ID:\s*([A-Za-z00-9\-])+\s*$' | jq -r '.data.submatches | select(.) | .[].match.text' | awk '{ print $2 }' | sort")
(string-trim)
(split-string "\n")))
(targets (-> (shell-command-to-string
(format "rg -a -g '*.org*' --json '\\[id:(%s)]' | jq -r '.data.submatches | select(.) | .[].match.text[4:-1]' | sort" (string-join ids "|")))
@linktohack
linktohack / zshrc.zsh
Last active February 17, 2023 11:05
ZSH
View zshrc.zsh
export EDITOR=vim
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="nicoulaj"
plugins=(asdf aws docker direnv fasd fzf git helm history jq kubectl macos)
source $ZSH/oh-my-zsh.sh
export FZF_DEFAULT_OPTS="--bind ctrl-k:kill-line,ctrl-b:preview-page-up,ctrl-f:preview-page-down"
export _FASD_BACKENDS="native spotlight"
export PATH="$PATH:$HOME/Library/Android/sdk/platform-tools"
@linktohack
linktohack / *new*.txt
Last active February 17, 2023 00:13
Firestore maintainancew
View *new*.txt
< Citations.jsonl | curl -vv -H 'Content-Type: application/octet-stream' http://127.0.0.1:5001/hatchi-mobile/us-central1/maintainance\?secret\=$SECRET\&action\=importCol\&col\=Citations\&withSubCollections\=1 --data-binary @- ; \
< Concours.jsonl | curl -vv -H 'Content-Type: application/octet-stream' http://127.0.0.1:5001/hatchi-mobile/us-central1/maintainance\?secret\=$SECRET\&action\=importCol\&col\=Concours\&withSubCollections\=1 --data-binary @- ; \
< Conseils.jsonl | curl -vv -H 'Content-Type: application/octet-stream' http://127.0.0.1:5001/hatchi-mobile/us-central1/maintainance\?secret\=$SECRET\&action\=importCol\&col\=Conseils\&withSubCollections\=1 --data-binary @- ; \
< Devises.jsonl | curl -vv -H 'Content-Type: application/octet-stream' http://127.0.0.1:5001/hatchi-mobile/us-central1/maintainance\?secret\=$SECRET\&action\=importCol\&col\=Devises\&withSubCollections\=1 --data-binary @- ; \
< Dictionnary_mot_interdit.jsonl | curl -vv -H 'Content-Type: application/octet-stream' http://127.0.0.1:5001/ha
@linktohack
linktohack / *scratch*.el
Created February 10, 2023 08:36
Elisp merge lists, keep order
View *scratch*.el
(defun merge-lists (&rest lists)
"Merge list, keep elements' order the same as where they are in the original lists.
E.g `(merge-list '(1 2) '(3 4 5))' should returns `(1 3 2 4 5)'."
(let ((copy (mapcar 'copy-sequence lists))
(result))
(while copy
(dolist (lst copy)
(when-let ((elt (pop lst))) ; pop doesn't change `lst'
(push elt result)))
@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 / 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 / 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 / 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 / *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 / 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]