Skip to content

Instantly share code, notes, and snippets.

View akhy's full-sized avatar

Akhyar Amarullah akhy

View GitHub Profile
@akhy
akhy / mfatoken.applescript
Created October 16, 2023 01:59 — forked from akhoury6/mfatoken.applescript
Generate an MFA token with an OS X Keyboard Shortcut
-- Settings
set mfaSecret to "<token>"
-- Install oath-toolkit if not available
try
do shell script "which /usr/local/bin/oathtool"
on error
display dialog "This script needs to install oath-toolkit. Please ensure that brew is installed, then hit OK to continue."
do shell script "brew install oath-toolkit"
end try
@akhy
akhy / k8s_secret_decode.sh
Created September 22, 2023 01:57
Decode k8s secret using JQ
kubectl -n $namespace get secret $name -o json | jq -r '.data | map_values(@base64d)'
@akhy
akhy / syncthing-automerge.py
Created August 5, 2023 07:02 — forked from solarkraft/syncthing-automerge.py
Monitors a Syncthing-synced directory and tries to merge conflicting files (based on https://www.rafa.ee/articles/resolve-syncthing-conflicts-using-three-way-merge/). Probably adaptable for other directory types, but only tested with Logseq (works for me™️).
import os
import time
import re
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
def get_relative_path(path):
return os.path.relpath(path)
@akhy
akhy / command_exists.go
Created July 14, 2023 15:58 — forked from miguelmota/command_exists.go
Golang check if command exists
package main
import (
"log"
"os/exec"
)
func main() {
path, err := exec.LookPath("ls")
if err != nil {
@akhy
akhy / sqlmap.go
Created June 12, 2023 02:41 — forked from heyimalex/sqlmap.go
Functions for querying directly into map[string]interface{}
// Package sqlmap provides functions for querying directly into
// map[string]interface{}.
//
// In developing really simple api endpoints, I found the boilerplate needed
// to take the results of a database query and output them as JSON to be
// really fucking annoying; make a custom struct, scan into that struct, if
// there are multiple rows do the whole rows.Next() song and dance, and if
// anything changes update the three spots each column of the result is now
// dependent on. Even when using libraries like sqlx, there's still a lot of
// extraneous code that needs to be written.
kubectl -n $namespace get secret $name -o json | jq -r '.data | map_values(@base64d)'
@akhy
akhy / grpc_http_mux.go
Created July 5, 2022 09:21
gRPC + HTTP handler
package mux
import (
"net/http"
"strings"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
@akhy
akhy / send_metric_to_statsd.sh
Created June 14, 2021 19:40 — forked from nstielau/send_metric_to_statsd.sh
Send a metric to StatsD from bash
# Send a metric to statsd from bash
#
# Useful for:
# deploy scripts (http://codeascraft.etsy.com/2010/12/08/track-every-release/)
# init scripts
# sending metrics via crontab one-liners
# sprinkling in existing bash scripts.
#
# netcat options:
# -w timeout If a connection and stdin are idle for more than timeout seconds, then the connection is silently closed.
@akhy
akhy / webpacker_rails.md
Created August 23, 2020 19:59 — forked from maxivak/webpacker_rails.md
Webpack, Yarn, Npm in Rails
@akhy
akhy / runinenv.sh
Created October 24, 2019 06:00 — forked from parente/runinenv.sh
run a command in virtualenv, useful for supervisord
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
shift 1
echo "Executing $@ in ${VENV}"
exec "$@"