Skip to content

Instantly share code, notes, and snippets.

@skull-squadron
skull-squadron / force-replace-docker-binaries-with-unsupported-generic-ones
Created April 9, 2024 05:57
Oracle Linux and Fedora: Replace docker YUM/RPM binaries with generic ones from the interwebs without hash/sig checking or confirmation
#!/usr/bin/env bash
# Needed for btrfs support on RH/Fedora-derived platforms
set -Eeuo pipefail
files=(containerd containerd-shim-runc-v2 ctr docker dockerd docker-init docker-proxy runc)
url_prefix="https://download.docker.com/linux/static/stable/$(/bin/arch)/"
ua='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
tarball=$(/bin/curl -fsSL -A "$ua" "$url_prefix" | /bin/grep -Eo 'docker-[0-9.]+tgz' | /bin/sort -Vur | /bin/head -1)
url="${url_prefix}${tarball}"
@skull-squadron
skull-squadron / Makefile
Last active April 9, 2024 04:57
Find a crc32 hash collision to embed in a file (requires zlib)
CFLAGS ?= -std=c99 -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wpedantic -Wformat=2 -flto -O3 -DNEBUG
build: find-crc32-worker
find-crc32-worker: find-crc32-worker.c Makefile
$(CC) $(CFLAGS) -lz $< -o $@
clean:
rm -f find-crc32-worker
@skull-squadron
skull-squadron / figsample
Last active April 9, 2024 05:14
Figlet sample viewer (require crc32 from Perl)
#!/usr/bin/env bash
#
#
# _______ _____ ______ _______ _______ _______ _____ _______
# |______ | | ____ |______ |_____| | | | |_____] | |______
# | __|__ |_____| ______| | | | | | | |_____ |______
#
#
# ___ ___ ___
#
@skull-squadron
skull-squadron / ssh-regen-moduli
Last active April 8, 2024 10:39
Regenerate /etc/ssh/moduli for modern openssh
#!/usr/bin/env bash
set -euo pipefail
# This script supports openssh 8.2+
(( ! UID )) || exec /usr/bin/sudo "$0" "$@"
var=${0//[^a-zA-Z0-9_]/_}
eval [ "\${$var-}" ] || exec /usr/bin/env ${var}=1 /usr/bin/flock -en "$0" "$0" "$@"
bits=${1:-4096}
min_bits=$((bits - 1))
moduli::generate() {
@skull-squadron
skull-squadron / cmdline.txt
Created April 8, 2024 05:17
Kernel config diff between CentOS 9-stream (5.14.0-430.el9.x86_64) and Oracle 9.3 UEK (5.15.0-204.147.6.3.el9uek.x86_64)
(HOST1={{hostname1}} HOST2={{hostname2}}; diff -u <(ssh "$HOST1" 'sed "/CONFIG_/!d;s/^# //" /boot/config-$(uname -r) | sort') <(ssh "$HOST2" 'sed "/CONFIG_/!d;s/^# //" /boot/config-$(uname -r) | sort'))
@skull-squadron
skull-squadron / libc-bits.h
Created March 23, 2024 22:25
Include all C headers for C89, C99, C11, C17, and C23 for programming contests and such
#ifndef LIBC_BITS_H
#define LIBC_BITS_H
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
@skull-squadron
skull-squadron / RESOLUTION.md
Last active March 14, 2024 20:24
node v18 refuses to compile with Apple Clang/LLVM >= 16
  1. brew edit node@18
  2. Insert ENV["CXXFLAGS"] = "-Wno-enum-constexpr-conversion" after ENV["PYTHON"] = ...
  3. brew install node@18
  4. Profit!

Notes:

  • i. Don't bother reporting this to homebrew because it has severely unprofessional contributors.
  • ii. Clang/LLVM people insist on breaking all software and systems for idealological purity.
  • iii. Node people refuse to take ownership of this.
@skull-squadron
skull-squadron / 000_README.md
Created March 14, 2024 08:48
macOS Ventura/Sonoma auto Ethernet/Wi-Fi switching

Auto Ethernet/Wi-Fi switching script for macOS

! CRITICAL PROBLEM ! Currently broken because ...../airport -z no longer functions and the replacement is uncertain and nonexistent for now

Installation

  1. Add local.auto-switch-wifi-ethernet.zsh to /usr/local/sbin
  2. Add local.auto-switch-wifi-ethernet.plist to /Library/LaunchDaemons
  3. Create /usr/local/.home.wifi.ssid containing the Wi-Fi network name (SSID) to try to connect to when Ethernet is no longer internet reachable
  4. Start it permanently sudo launchctl unload -w /Library/LaunchDaemons/local.auto-switch-wifi-ethernet.plist
@skull-squadron
skull-squadron / README.md
Last active March 13, 2024 13:36
How to install curses 1.4.x gem on modern macOS

0. brew install ncurses ruby

1. gem install curses -- --use-system-libraries --with-ncurses-dir="$(brew --prefix ncurses)" --with-cflags='-Wno-error=incompatible-pointer-types'

This is because the Ruby maintainers are hipsters unable to work effectively with reality and Clang/LLVM breaking everyone's shit.

@skull-squadron
skull-squadron / main.cpp
Created March 8, 2024 08:41
C++ specialization of stack adapter for forward_list
// Specialize stack to work with forward_list (STL singly-linked lists)
// Notes:
// - This is a proof-of-concept as an exercise for template specialization. Don't use in production!
// - Not cache-efficient.
// - Use stack<T, vector<T>> most of the time instead.
// Output
// ======
// t: