Skip to content

Instantly share code, notes, and snippets.

@adduc
adduc / README.md
Last active January 27, 2025 22:34
Fixing problem: k3s shows as a new node every time its recreated

Problem: k3s shows as a new node every time its recreated

Solution: Pass --node-name=example as parameter to the server or agent command.

 services:
   server:
     image: rancher/k3s:v1.32.0-k3s1
     command:
 - server
@adduc
adduc / README.md
Last active January 25, 2025 21:01
bash prompt

Bash Prompt

My current directory structure can result in lengthy directory paths, which can make for difficult bash prompts with Fedora's default prompt. To deal with this, I constructed a bash prompt that allows for lengthy directory paths without impacting where the cursor for the command begins.

PS1

# set prompt: <horizontal line>\n<green>user@hostname</green>:<cyan>current directory</cyan>\n<yellow>time</yellow> $
export PS1="\[\033[1;30m\]$(printf '─%.0s' {1..80})\n\[\033[0;32m\]\u@\h\[\033[0m\]:\[\033[0;36m\]\w\[\033[0m\]\n\[\033[0;33m\]\t\[\033[0m\] $ "
@adduc
adduc / README.md
Last active January 25, 2025 22:18
Function to initialize new exercise

Bash function for new exercises

I find myself frequently creating one-off repos to test a concept or technology. To streamline this process, I have written a bash function and included it in my bashrc configuration.

When invoked, it creates a new directory, creates a mercurial repository preconfigured for git integration with a main bookmark activated, creates a README.md file, and then opens the directory in my editor of choice (VSCode).

@adduc
adduc / README.md
Last active January 27, 2025 22:34

VSCode keybindings for terminal in editor-area

While VSCode supports opening terminals in the editor area, its shortcuts are generally hard-coded to deal with the terminal in the bottom-panel. To change this, we can define keyboard shortcuts to mitigate and make the "ctrl+`" functionality toggle between the terminal and the last editor used.

@adduc
adduc / docker-compose.yml
Last active March 19, 2025 18:44
Script to provision a forgejo / woodpecker CI setup and a token to interact with Woodpecker's services
services:
forgejo:
image: codeberg.org/forgejo/forgejo:1.19.3-0
tmpfs: ["/data"]
stop_signal: SIGKILL
ports: [ "3000:3000", "8000:8000" ]
environment:
# @see https://docs.gitea.com/next/administration/config-cheat-sheet
GITEA__database__DB_TYPE: sqlite3
@adduc
adduc / Todo.php
Last active January 24, 2025 19:09
Laravel Eloquent PoC: Use existing PDO connection in standalone application
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Todo extends Model
{
@adduc
adduc / gist:d58a33c899cf078006b7f00291668477
Created November 9, 2021 05:45
stacktrace-on-sighup.php
<?php
declare(strict_types=1);
pcntl_async_signals(true);
pcntl_signal(SIGHUP, function ($signal) {
echo "HUP! {$signal} \n";
error_log((new Exception())->getTraceAsString());
});
@adduc
adduc / script.sh
Created February 10, 2021 19:50
Bash: Load config without overwriting existing env variables
# export current environment
EXISTING_ENV=$(export -p)
# import variables from file
. config.env
# import previous environment
source <(echo "$EXISTING_ENV")
# At this point, only variables from config.env that did
@adduc
adduc / find-unused.sh
Created October 11, 2020 18:01
Naive approach to finding unused files, classes, and functions
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 <dir>"
exit 1
fi
DIR="$(realpath $1)"
find_unused_classes()
@adduc
adduc / install.sh
Last active August 24, 2021 09:23
My installation of mercurial, tortoisehg, and hg-git on Ubuntu 20.04 and newer
#!/bin/bash
TARGET_DIR=/opt/repos/third-parties
HG_GIT_VERSION=${1:-default}
HG_RELEASE_VERSION=${2:-5.5.2}
HG_REPO_VERSION=${3:-stable}
TORTOISEHG_VERSION=${4:-stable}
update() {
# Update packages