Skip to content

Instantly share code, notes, and snippets.

@nijave
nijave / migrate.sh
Last active October 31, 2022 18:51
Postgres database migration with pg_dump and logical replication
#!/bin/bash
export PGSSLMODE=prefer
DATABASE=postgres
USER=postgres
SOURCE_PASSWORD=postgres
SOURCE_HOST=$(docker inspect postgres-5433 | jq -r '.[0].NetworkSettings.IPAddress')
SOURCE_PORT=5432
@nijave
nijave / crystal-disk-mark-fio-bench.sh
Last active July 10, 2022 02:11 — forked from O1ahmad/crystal-disk-mark-fio-bench.sh
CrystalDiskMark-esque Disk Benchmark (using fio)
#!/bin/bash
LOOPS=3 # How many times to run each test
SIZE=10240 # Size of each test, multiples of 32 recommended for Q32 tests to give the most accurate results.
WRITEZERO=0 # Set whether to write zeroes or randoms to testfile (random is the default for both fio and crystaldiskmark); dd benchmarks typically only write zeroes which is why there can be a speed difference.
QSIZE=$(($SIZE / 32)) #Size of Q32Seq tests
SIZE+=m
QSIZE+=m
@nijave
nijave / ssh-pod.sh
Last active July 16, 2022 00:12
Privileged k8s "ssh" pod
#!/usr/bin/env bash
pod_name=nick-ssh
# the first node
k8s_node=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
@nijave
nijave / jellyfin-contine-watching.sql
Created March 14, 2022 02:46
Jellyfin playbackPositionTicks info query
SELECT
key, COALESCE(ti.SortName, mi.sortname) SortName, COALESCE(ti.Path, mi.Path) Path
FROM UserDatas u
LEFT JOIN TypedBaseItems ti
ON
u.key = ti.UserDataKey
OR REPLACE(u.key, '-', '') = ti.PresentationUniqueKey
LEFT JOIN MediaItems mi
ON
REPLACE(u.key, '-', '') = mi.PresentationUniqueKey
@nijave
nijave / iscsi.sh
Last active July 11, 2023 02:18
iSCSI initiator (client) commands
# List targets
iscsiadm -m discovery --type sendtargets -p <portal host/socket>
# Login to a target
iscsiadm -m node -T <target IQN> -l
# List active/logged in targets
iscsiadm -m session
# Logout of a target
@nijave
nijave / dns.sh
Created July 23, 2021 13:02
Temporarily set openvpn split tunnel dns
resolvectl dns tap0 172.16.3.254
resolvectl domain tap0 ~.
@nijave
nijave / windows-event-logs.ps1
Created July 19, 2021 14:39
List/remove Windows Event Logs
# List
Get-WmiObject win32_nteventlogfile
Remove-EventLog -LogName "Some Log Name"
@nijave
nijave / tethering.sh
Created June 20, 2021 21:03
Android 10 Tethering Fix
#!/bin/sh
# Don't require DUN APN type
settings put global tether_dun_required 0
# use MagiskHide Props Config
# echo "net.tethering.noprovisioning=true" >> /system/build.prop
# iptables increment TTL for nat packets since carriers block these
# Requires kernel with CONFIG_IP_NF_TARGET_TTL enabled
# see https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
import requests
from requests.adapters import HTTPAdapter, Retry
class TimeoutHTTPAdapter(HTTPAdapter):
DEFAULT_TIMEOUT = 30
def __init__(self, *args, **kwargs):
@nijave
nijave / cluster_dash.py
Last active May 23, 2021 19:34
CloudWatch CPU/Disk IOPs dashboard JSON generator for ASG-backed EC2 ECS clusters
import boto3
import json
# assumes ASG has tag Name="ECS Cluster - cluster_name"
cluster_name = "some-clsuter"
asgs = [
{
"name": asg["AutoScalingGroupName"],
"instance_type": asg["Instances"][0]["InstanceType"],