Skip to content

Instantly share code, notes, and snippets.

View edr3x's full-sized avatar
🦥
Naffing

Anuj Dhungana edr3x

🦥
Naffing
View GitHub Profile
@edr3x
edr3x / getlsp.sh
Created May 27, 2025 19:33
Fetch LSP client config for Neovim ( Requires: curl, jq and fzf )
#!/usr/bin/env bash
GHAPI="https://api.github.com"
REPO="neovim/nvim-lspconfig"
API_URL="$GHAPI/repos/$REPO/contents/lsp"
TMP_JSON="/tmp/nvim_lspconfig_lsp_files.json"
curl -s "$API_URL" -o "$TMP_JSON"
@edr3x
edr3x / k3s.sh
Last active December 25, 2024 09:07
#!/usr/bin/env bash
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --disable-traefik
helm repo add traefik https://traefik.github.io/charts
helm install traefik traefik/traefik
# or
# helm install traefik oci://ghcr.io/traefik/helm/traefik
@edr3x
edr3x / jwk.go
Created December 9, 2024 06:41
GO package to encode and decode JWK public keys
package jwk
import (
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"math/big"
)
@edr3x
edr3x / postgres.md
Created November 19, 2024 05:18
scripts related to PostgreSQL

Scripts to make working with multiple pg dbs

Dump multiple database on same db instance

dump.sh

#!/usr/bin/env bash

DB_USER="user"
func PrintStructInTable(v interface{}) {
val := reflect.ValueOf(v)
typ := reflect.TypeOf(v)
// Ensure that the input is a struct
if typ.Kind() != reflect.Struct {
fmt.Println("Input is not a struct")
return
}
@edr3x
edr3x / tls-secret-gen.sh
Created August 7, 2024 06:42
create kubernetes tls secrets from json certificate file generated by traefik
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "Usage: $0 <json_file>"
exit 1
fi
json_file="$1"
certificates=$(jq -c '.production.Certificates[]' $json_file)
@edr3x
edr3x / container-cpu-usae.sh
Created July 3, 2024 04:34
Get absolute CPU usae of container
#!/usr/bin/env bash
if [ -z "$1" ]; then
echo "Usage: $0 <container-id>"
exit 1
fi
CONTAINER_ID=$1
CPU_PERCENT=$(docker stats $CONTAINER_ID --no-stream --format "{{.CPUPerc}}" | tr -d '%')
create or replace function gen_uuidv7() returns uuid as $$
declare
begin
return gen_uuidv7(clock_timestamp());
end $$ language plpgsql;
create or replace function gen_uuidv7(p_timestamp timestamp with time zone) returns uuid as $$
declare
v_time numeric := null;
v_unix_t numeric := null;
@edr3x
edr3x / base64url.sh
Created May 25, 2024 06:01
url friendly base64 encoder and decoder
#!/usr/bin/env bash
encode() {
local input="$1"
if [ -z "$input" ]; then
input=$(cat)
fi
echo -n "$input" | base64 -w0 | tr '+/' '-_' | tr -d '='
}
@edr3x
edr3x / isValidDomain.go
Created May 17, 2024 10:43
Utility function to check if the domain is valid or not
package main
import (
"fmt"
"regexp"
"golang.org/x/net/publicsuffix"
)
func isRootDomain(domain string) (bool, error) {