Skip to content

Instantly share code, notes, and snippets.

View afriza's full-sized avatar

Afriza N. Arief afriza

  • Indonesia
  • 18:22 (UTC +07:00)
View GitHub Profile
@afriza
afriza / proxmox-mikrotik.md
Last active March 16, 2024 02:17
install Mikrotik CHR on ProxMox Virtual Environment 8.1.4
  • create bridges for use by mikrotik CHR
  • create VM without any media
wget https://download.mikrotik.com/routeros/7.14/chr-7.14.img.zip
apt update
apt install unzip
unzip chr-7.14.img.zip
qemu-img resize -f raw chr-7.14.img 256M
qm disk import 100 chr-7.14.img local-lvm
@afriza
afriza / lvm-extend-lv-vg.md
Created February 3, 2024 06:39
Extend LVM Logical Volume / Volume Group
  1. Check status
    vgdisplay
    lvdisplay
    
  2. Extend Logical Volume
    lvextend -l +100%FREE /dev/VG_NAME/LV_NAME
    
  3. Resize Filesystem
@afriza
afriza / goroutine-id.go
Last active February 22, 2023 05:59 — forked from metafeather/main.go
Get goroutine id for debugging
package main
import (
"fmt"
"runtime"
"strings"
"sync"
)
// Goid gets goroutine ID. Only used for debugging purpose.
@afriza
afriza / git-shallow-all.sh
Last active January 1, 2023 03:25
Convert git repository into shallow clone to save storage space when there is no need for git histories
#! /bin/sh
# Ref: https://stackoverflow.com/a/62650346/109747
# macOS/BSD find requires root path
root=${1:-.}
# TODO: handle if git-shallow.sh exits with non-zero code
find $root -type d -name '.git' -exec sh -c 'pushd "${0%/*}" && ( git-shallow.sh ) && popd' {} \;
@afriza
afriza / set-suid-mtr-homebrew.sh
Created December 22, 2022 10:08
Run mtr without sudo by using SUID bit
#! /bin/sh
# Optional: if not already in $PATH
ln -s /usr/local/Cellar/mtr/0.95/sbin/mtr /usr/local/sbin/
ln -s /usr/local/Cellar/mtr/0.95/sbin/mtr-packet /usr/local/sbin/
# or on newer macOS/Homebrew
ln -s /opt/homebrew/Cellar/mtr/0.95/sbin/mtr /opt/homebrew/bin/
ln -s /opt/homebrew/Cellar/mtr/0.95/sbin/mtr-packet /opt/homebrew/bin/
# A quick and dirty way to run mtr without sudo by using SUID bit.
@afriza
afriza / setup-gpg-over-ssh-forwarding.md
Last active February 19, 2023 14:07
Remote git signing with GPG (GnuPG / GNU Privacy Guard) over SSH Forwarding

On local machine

$ brew install gnupg pinentry-mac # macOS
$ echo 'export GPG_TTY=$(tty)' >> ~/.bashrc
$ echo 'export GPG_TTY=$(tty)' >> ~/.zshrc
$ echo "pinentry-program $(command -v pinentry-mac)" > ~/.gnupg/gpg-agent.conf # macOS
$ defaults write org.gpgtools.common UseKeychain NO # macOS
$ gpgconf --kill gpg-agent
$ gpg-connect-agent /bye
@afriza
afriza / gsed-rm-color.sh
Last active November 23, 2022 03:09
GNU sed to remove color
#!/bin/sh
sed=sed
if [ `uname` == "Darwin" ]; then
sed=`command -v gsed`
ret=$?
if [ "$ret" -ne 0 ]; then
echo 'GNU sed needs to be installed. Install with: brew install gnu-sed'
exit $ret
fi
fi
@afriza
afriza / ppp-profile-on-down.rsc
Last active November 16, 2022 05:12
Automatically add & remove PPP Profile connections to & from Mikrotik IGMP Proxy Multicast Routing
# The actual on-down script. local variable matching against comment is required as of RouterOS v6.49.7
/log info "igmp-proxy interface removing $interface"
:local komen $interface
/routing igmp-proxy interface remove [/routing igmp-proxy interface find comment=$komen]
@afriza
afriza / mount-hdd.sh
Last active May 12, 2023 01:43
mount disk filesystem by LABEL from Linux and mount Samba shares from macOS via AppleScript
#!/bin/sh
domnt() {
local lbl="$1" mnt="$2"
if ! mount | grep -qF " $mnt " ; then
mkdir -p "$mnt"
if mount "LABEL=$lbl" "$mnt" ; then
echo "'LABEL=$lbl' has been mounted at '$mnt'"
fi
@afriza
afriza / ap-wlan0.network
Last active August 29, 2022 09:30
Access Point using `hostapd`, `systemd-networkd`, `dnsmasq` adapted from https://raspberrypi.stackexchange.com/q/89803/90456
# /etc/systemd/network/ap-wlan0.network
[Match]
Name=wl*
[Network]
LLMNR=no
MulticastDNS=yes
IPMasquerade=ipv4
Address=192.168.90.1/24
DHCPServer=yes