Skip to content

Instantly share code, notes, and snippets.

@Loupax
Loupax / edit.sh
Created June 8, 2025 19:37
Edit function that, when called from inside a nvim terminal, it will open the file in the already existing nvim instance
edit() {
if [ -z "$NVIM" ]; then
nvim "$1"
return
fi
nvim --server "$NVIM" --remote-send "<C-\\><C-N><C-w>t:edit $1<CR>"
}
@Loupax
Loupax / prompt.sh
Last active May 12, 2025 08:00
Custom bash prompt
C_BLUE="\[\033[0;34m\]"
C_GREEN="\[\033[0;32m\]"
C_RED="\[\033[0;31m\]"
C_RESET="\[\033[0m\]"
__prompt_git_info() {
if $(git rev-parse --is-inside-git-dir 2>/dev/null); then
echo ""
return
fi
@Loupax
Loupax / invalidate
Created April 28, 2025 10:21
Cloudfront mass invalidations
#!/bin/bash
# --- Configuration ---
DISTRIBUTION_ID="DISTRO_ID" # Replace with your actual Distribution ID
URL_FILE="paths" # Your file containing URL paths
BATCH_SIZE=15 # Max paths per invalidation request
ALL_PATHS=()
@Loupax
Loupax / Dockerfile
Created October 31, 2024 15:08
Image Processing Memory Footprint
FROM golang:1.20-alpine3.18
RUN apk add --no-cache -U git build-base libwebp-tools vips-dev
WORKDIR /app
COPY . .
# Builds the server
RUN go build -o app main.go
@Loupax
Loupax / record.sh
Created September 25, 2024 07:21
Script that records the area of a window clicked by the user. Requires ffmpeg with Xcb enabled.
#!/usr/bin/env bash
window_info=$(xwininfo)
x=$(echo "$window_info" | grep "Absolute upper-left X" | awk '{print $4}')
y=$(echo "$window_info" | grep "Absolute upper-left Y" | awk '{print $4}')
width=$(echo "$window_info" | grep "Width" | awk '{print $2}')
height=$(echo "$window_info" | grep "Height" | awk '{print $2}')
if [ -z "$x" ] || [ -z "$y" ] || [ -z "$width" ] || [ -z "$height" ]; then
@Loupax
Loupax / gorefs.sh
Last active August 14, 2024 09:02
Script that lists all the usages of the passed function reference.
#!/usr/bin/env bash
# Example usage: gorefs file.go:10:6
gopls references $1 | while IFS=: read -r file line cols; do
start_col=$(echo $cols | cut -d'-' -f1)
end_col=$(echo $cols | cut -d'-' -f2)
content=$(sed -n "${line}p" "$file")
file="./$(realpath --relative-to="$(pwd)" $file)"
@Loupax
Loupax / stuff.js
Last active March 27, 2024 08:48
Stuff you can find in the hardware store
const stuff = [
"allen wrenches",
"gerbil feeders",
"toilet seats",
"electric heaters",
"trash compactors",
"juice extractor",
"shower rods and water meters",
"walkie-talkies",
"copper wires safety goggles",
@Loupax
Loupax / config
Last active March 28, 2024 20:25
My i3 configuration + dependencies
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
@Loupax
Loupax / queue_processing.go
Last active September 15, 2022 10:46 — forked from valsteen/queue_processing.go
Queue processing
/*
This demonstrates a task scheduling loop where tasks can send back other tasks to the queue.
Program input: a nested list of items that can either be integers, or nested slices:
- when it's an integer, wait for 25 - value seconds
- when it's a slice, wait for len(slice) seconds, then put back each item in the queue to be processed next
waiting time simulates some processing, on which a concurrency limit is applied ( both waiting times share the same
limit ). pushing back to the queue should not be blocking.
package jwt_test
func parsePrivatePEM(pemString string) *rsa.PrivateKey {
block, _ := pem.Decode([]byte(pemString))
key, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
return key
}
func parsePublicPEM(pemString string) *rsa.PublicKey {
block, _ := pem.Decode([]byte(pemString))