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 / 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 \
@chris-kobrzak
chris-kobrzak / getCurrentPositionTask.js
Created October 20, 2021 16:05
Promisified navigator.geolocation.getCurrentPosition
function getCurrentPositionTask(positionConfig) {
const { geolocation } = navigator
return new Promise((resolve, reject) => {
const handleSuccess = ({ coords }) => {
resolve(coords)
}
const handleError = error => { reject(error) }
@chris-kobrzak
chris-kobrzak / postman-jwt-auth-pre-request.js
Last active September 22, 2021 15:14
Postman pre-request script for automatic JWT-authentication. Please see config options at the top of the script.
// Environment variable names config
const env = {
ACCESS_TOKEN: '_token', // This env var will be created by the script
AUTH_TIME: '_authTime', // This env var will be created by the script
BASE_URL: 'baseUrl',
ID: 'username',
SECRET: 'password'
}
// API config
const api = {
@chris-kobrzak
chris-kobrzak / interface-with-generics.cs
Created April 30, 2021 14:31
c# interface with generics
using MyService.Core.Models;
namespace MyService.Providers.Mappers
{
public interface IMyMapper<in T> where T : ISomething
{
MappedSomething MapToSomething(T somethingGeneric);
}
public class MyConcreteMapper : IMyMapper<SomethingA>
@chris-kobrzak
chris-kobrzak / convert-m4a-to-ogg.sh
Created February 28, 2021 22:22
Convert .m4a to .ogg files
for m4aFile in *.m4a; \
do ffmpeg -i "$m4aFile" \
-ab 128k \
ogg/"${m4aFile%.m4a}.ogg"; \
done
@chris-kobrzak
chris-kobrzak / namei.sh
Last active April 14, 2021 11:47
Display all permissions on a path and its parents on Linux
namei -om /path/to/a/dir-or-file
# Sample output
#
# f: /usr/local/bin/nginx_modsite
# drwxr-xr-x root root /
# drwxr-xr-x root root usr
# drwxr-xr-x root root local
# drwxr-xr-x root root bin
# -rwxr-xr-x root root nginx_modsite
kafkacat -L -b <BROKER_URL:PORT> -t <KAFKA_TOPIC>