Skip to content

Instantly share code, notes, and snippets.

@azlan
azlan / pbcopy
Last active January 5, 2025 08:39
Bash script to copy terminal clipboard to OS clipboard with OSC52 from remote ssh session
#!/bin/bash
printf "\033]52;c;%s\007" "$(base64 | tr -d '\n')"
# https://jvns.ca/til/vim-osc52/
# Instructions:
# $ sudo nano /usr/local/bin/pbcopy
# paste this script
# $ sudo chmod +x /usr/local/bin/pbcopy
# example usage:
@azlan
azlan / make-link.bat
Created January 1, 2025 04:09
rust coreutils for windows setup
@azlan
azlan / dec-to-hex.go
Last active January 1, 2025 04:42
decimal to hex
package main
import (
"bufio"
"encoding/binary"
"fmt"
"log"
"os"
"strconv"
"strings"
@azlan
azlan / mc-wrapper.fish
Created December 26, 2024 11:07
How to make Midnight Commander exit to its current directory - Fish Shell
# copy to ~/.config/fish/functions/
function mc
if not test -d "/tmp/mc-$USER"
mkdir -p "/tmp/mc-$USER"
end
set SHELL_PID %self
set MC_PWD_FILE "/tmp/mc-$USER/mc.pwd.$SHELL_PID"
/usr/bin/mc -P $MC_PWD_FILE $argv
@azlan
azlan / config.fish
Created July 11, 2024 03:48
ssh agent for fish shell
# ~/.config/fish/config.fish
if test -z (pgrep ssh-agent | string collect)
eval (ssh-agent -c)
set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
set -Ux SSH_AGENT_PID $SSH_AGENT_PID
end
@azlan
azlan / node-migrate.fish
Last active December 28, 2023 07:50
nodejs repo migration
# https://github.com/nodesource/distributions/wiki/How-to-migrate-to-the-new-repository (for bash)
# Remove the GPG keyring file associated with the old repository
sudo rm /etc/apt/keyrings/nodesource.gpg
# Remove the old repository's list file
sudo rm /etc/apt/sources.list.d/nodesource.list
# Define the desired Node.js major version
set NODE_MAJOR 20
# Update local package index
@azlan
azlan / wgg.go
Created September 1, 2023 03:14
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
@azlan
azlan / rsa.js
Last active July 12, 2023 14:08
// https://en.wikipedia.org/wiki/RSA_(cryptosystem)
// Least common multiple
function lcm(a, b) {
let min = (a > b) ? a : b;
while (true) {
if (min % a === 0 && min % b === 0) {
break;
}
min++;
#!/usr/bin/env fish
set TMP_DIR "/tmp"
function get_latest_go_version
set GO_DEV_DL_PAGE "https://go.dev/dl/"
set LATEST_VERSION (curl -sL $GO_DEV_DL_PAGE | grep -oP 'go\d+(\.\d+)+\.linux-amd64\.tar\.gz' | awk -F '.linux-amd64.tar.gz' '{print $1}' | sort -V | tail -n 1 | sed 's/go//')
echo $LATEST_VERSION
end
@azlan
azlan / update_go.sh
Last active May 4, 2023 02:45
update go
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: ./update_go.sh version (example 1.20.4)"
exit 1
fi
GO_VERSION=$1
GO_ARCHIVE="go${GO_VERSION}.linux-amd64.tar.gz"
GO_DOWNLOAD_URL="https://go.dev/dl/${GO_ARCHIVE}"