Skip to content

Instantly share code, notes, and snippets.

@wojas
wojas / docker-ps-architectures.sh
Created September 2, 2022 06:52
Check which docker containers are running under qemu emulation on macOS
#!/bin/bash
# https://stackoverflow.com/questions/66834864/how-to-determine-when-docker-containers-on-an-m1-macbook-are-running-via-qemu
#for i in `docker ps --format "{{.Image}}"` ; do
# docker image inspect $i --format "$i -> {{.Architecture}} : {{.Os}}"
#done
OPT=$@
set -euo pipefail
docker container ls $OPT --format "{{.ID}}\t{{.Image}}\t{{.Command}}\t{{.Status}}\t{{.Names}}" |
@wojas
wojas / gitlab-runner-docker.sh
Created August 25, 2022 07:09
Run the Gitlab runner locally in Docker (tested on macOS)
#!/bin/sh
# Based on https://stackoverflow.com/a/65920577/297793
# Manually start this first:
## docker run -d \
## --name gitlab-runner \
## --restart always \
## -v "$HOME:$HOME" \
## -v /var/run/docker.sock:/var/run/docker.sock \
## gitlab/gitlab-runner:latest
@wojas
wojas / CMakeLists.txt
Last active May 19, 2020 14:54
Quick and dirty example of how to wrap a callback registration
cmake_minimum_required(VERSION 3.16)
project(luac C)
set(CMAKE_C_STANDARD 11)
find_package(PkgConfig REQUIRED)
pkg_search_module(LUA REQUIRED IMPORTED_TARGET luajit luajit2)
add_executable(retval retval.c)
target_link_libraries(retval PUBLIC PkgConfig::LUA)
@wojas
wojas / kubelog.py
Last active April 2, 2020 09:12
Tool to quickly select and view Kubernetes container logs using fzf (screenshot below in comments)
#!/usr/bin/env python3
"""
kubelog is a tool that lists all pods and their contains using fzf
and prints the logs for the selected one.
Options to get fzf:
- https://github.com/junegunn/fzf
- brew install fzf
"""
@wojas
wojas / git-switch-branch.sh
Created May 24, 2019 13:22
Script to visually select a recent git branch to switch to
#!/bin/bash
# Script to visually select a recent git branch to switch to
# Requires https://github.com/junegunn/fzf (brew install fzf)
branches () {
git for-each-ref --sort=-committerdate refs/heads/ | sed 's|.*refs/heads/||' | head -30
}
branch=$(branches | fzf --no-sort --layout=reverse)
@wojas
wojas / note.sh
Created November 22, 2018 07:05
I replaced nvALT for note taking with this short shell script and fzf
#!/usr/bin/env bash
# When called with a name, open a specific note.
# When called without a name, use fzf to interactively search notes.
# (fzf: https://github.com/junegunn/fzf)
set -e
cd ~/path/to/my/notes/
export EDITOR=nvim
@wojas
wojas / btrfs-subvolume-usage.py
Created April 27, 2017 17:00
Get btrfs subvolume disk usage sorted by incremental size
#!/usr/bin/env python3
# NOTE: btrfs quota must be enabled for this to work:
# btrfs quota enable /btrfs/
import os
import sys
usage = {}
for line in os.popen('btrfs qgroup show / --raw', 'r'):
# 0/10784 15678980096 557056
if not line.startswith('0/'):
@wojas
wojas / prefix.sh
Last active April 6, 2022 02:52
Prefix shell command output with a colored string (supports stderr)
#!/bin/bash
raw_prefix="$1"
prefix_width=${PREFIX_WIDTH:-20}
color=color_${PREFIX_COLOR:-green}
error_color=color_${PREFIX_ERROR_COLOR:-red}
shift 1
if [ "$raw_prefix" = "" ]; then
echo "USAGE: $0 <prefix> <command> [args..]"
@wojas
wojas / docker-compose.yml
Created June 3, 2016 06:29
docker-compose for nginx with php5-fpm using small alpine images
version: '2'
services:
php:
image: php:5.6-fpm-alpine
volumes:
- data:/_data
- ./site:/var/www/html:ro
networks:
- backend
command: sh -c 'chown www-data /_data && exec php-fpm'
@wojas
wojas / feincms_delete_fix.py
Created November 12, 2012 12:40
Workaround for FeinCMS bug, where objects cannot be deleted if there are content types linking to it (IntegrityError)
# Workaround for: https://github.com/feincms/feincms/issues/323
# "Unable to delete pages containing custom content types"
from django.db.models.signals import pre_delete
import logging
log = logging.getLogger(__name__)
def fix_content_model_delete(model):
"""Register a pre-delete handler that will remove all content when a