Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View chris-kobrzak's full-sized avatar

Chris Kobrzak chris-kobrzak

View GitHub Profile
@chris-kobrzak
chris-kobrzak / takeWithTimerSaga.ts
Created March 1, 2024 11:15
Generic Redux Saga task that waits for an event and triggers another timeout event if the former never gets dispatched
function* takeWithTimerTask(
eventName: AnyEvent['type'],
timeoutEventName: AnyEvent['type'],
timeout: number
) {
const timerTask = yield* fork(
fireEventAfterDelayTask,
timeoutEventName,
timeout
)
@chris-kobrzak
chris-kobrzak / kill-high-cpu-processes.sh
Last active January 31, 2024 17:53
Shell script for detecting Linux processes consuming extensive amounts of processing power. Intended to be run on schedule.
#!/usr/bin/env bash
# 95% CPU utilisation
threshold=0.95
log_file="/var/log/kill-high-cpu-processes.log"
get_process_info() {
process_id=$1
ps -p "$process_id" -o pid,ppid,cmd,%cpu,%mem,stat --no-header | awk '{$1=$1};1'
@chris-kobrzak
chris-kobrzak / xcode-device-cleanup.sh
Created February 25, 2023 19:45
Xcode devices clean-up
xcrun simctl list devices
# Remove old devices stored under ~/Library/Developer/CoreSimulator/Devices (and clogging the disk)
xcrun simctl delete unavailable
@chris-kobrzak
chris-kobrzak / find-duplicates.sh
Created January 17, 2023 18:50
Find duplicated files sharing names but with different extensions (e.g. Nikon .nef and .jpg files)
# in this example we are removing JPG files sitting alongside .nef files
for name in `ls * | sed 's/.\{4\}$//' | sort | uniq -d`
do
# Remove echo below to actually delete files
echo rm $name.jpg
done
@chris-kobrzak
chris-kobrzak / verify-fstab.sh
Created January 5, 2023 18:05
Verify /etc/fstab entries
#!/usr/bin/env sh
sudo findmnt --verify --verbose
@chris-kobrzak
chris-kobrzak / readonlyDecorator.ts
Created November 11, 2022 12:01
JS decorators example
function readonly(target: any, name: string, descriptor: TypedPropertyDescriptor<() => void>) {
descriptor.writable = false
return descriptor
}
class Example {
a: number
@readonly
b() {}
@chris-kobrzak
chris-kobrzak / gen_random_string.sql
Created April 30, 2022 16:05
PostgreSQL helper for generating random strings of variable length
CREATE OR REPLACE FUNCTION gen_random_string(_min_length INT = 3)
RETURNS VARCHAR
LANGUAGE SQL
AS '
SELECT substring(
md5(random()::TEXT),
0,
_min_length + floor(random() * 10 + 1)::INT
)
';
@chris-kobrzak
chris-kobrzak / postgresql-commands.sh
Last active June 2, 2022 15:40
Useful PostgreSQL queries and commands. Mostly copied and pasted from the Mastering PostgreSQL 13 book.
# List all available database versions
aws rds describe-db-engine-versions --query '*[].[EngineVersion]' --output text --region eu-west-1 --engine postgres
aws rds describe-db-engine-versions --query '*[].[EngineVersion]' --output text --region eu-west-1 --engine aurora-postgresql
# Connect to Postgres via SSH's ProxyJump
ssh \
-L 5555:your.private.postgres.hostname:5432 \
-J your.proxy.hostname \
private.hostname.with.access.to.postgres
@chris-kobrzak
chris-kobrzak / podman-scribble.sh
Created January 14, 2022 17:04
Basic Podman commands
# Create a beefed up Podman virtual machine
podman machine init --cpus 3 --memory 6144 --disk-size 20
@chris-kobrzak
chris-kobrzak / multipass-scribble.sh
Last active January 15, 2022 21:56
Basic Multipass commands
sudo multipass set local.driver=virtualbox # errors on my work laptop
# Default driver
sudo multipass set local.driver=hyperkit
# Create a VM
multipass launch --name ubuntu2004
# Create a VM with custom parameters
multipass launch \