Skip to content

Instantly share code, notes, and snippets.

@pwalkr
pwalkr / repatch.sh
Created February 28, 2025 21:33
Apply git patches to alternative folders in a repository
#!/bin/sh
# This script applies a git commit cherry-pick style from one path to another.
# A patch is generated relative to the source folder, and reapplied on the
# destination folder.
#
# This is useful for promotion in infrastructure-as-code (IaC) implementations
# using folder-per-environment layouts.
#
# TODO: apply backlink to source commit in message, and potentially message
@pwalkr
pwalkr / unstableStep.groovy
Last active February 17, 2025 20:49
Mark previous step unstable (Jenkins shared library)
import org.jenkinsci.plugins.workflow.actions.WarningAction
import org.jenkinsci.plugins.workflow.graph.FlowNode
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import hudson.model.Result
/**
* Mark previous step unstable, without marking the whole build unstable
*
* This can be used to highlight inefficiencies or non-ideal usage of a pipeline, while permitting overall
* status (e.g. pull request checks) to return green/success. This will highlight the step and stage in
@pwalkr
pwalkr / self_virtualize.py
Created October 2, 2024 02:11
Self-virtualizing python script
import os
import subprocess
import sys
if 'VIRTUAL_ENV' not in os.environ:
os.environ['VIRTUAL_ENV'] = os.path.realpath('.venv') # Replace .venv with the virtual environment to load
virtual_python = os.environ['VIRTUAL_ENV'] + '/bin/python'
subprocess.call([virtual_python] + sys.argv)
sys.exit()
@pwalkr
pwalkr / pwned.sh
Created February 17, 2023 04:05
Check haveIbeenpwned database for a password
#!/bin/sh
if [ -z "$1" ]; then
echo "$0 <password>"
exit
fi
checksum="$(printf '%s' "$1" | sha1sum | awk '{print $1}')"
prefix="$(printf '%.5s' "$checksum")"
suffix="$(printf "$checksum" | sed 's/^.\{5\}//')"
@pwalkr
pwalkr / ansible-docker-swarm-config.yaml
Created February 5, 2023 20:38
Automatic rotation of a docker swarm config using an ansible template
# This set of tasks rotates a swarm config by generating a config name.
# If input contents change, the hash changes, triggering a name change and restart of consuming service(s)
# Tasks should all `run_once` if multiple swarm managers are in play.
- hosts: swarm_manager
tasks:
- set_fact:
config_data: '{{ lookup("template", "templates/my-template.cfg") }}'
- name: create config
@pwalkr
pwalkr / jenkins-extract-file-cred.groovy
Created January 11, 2023 18:22
Extract file credential from Jenkins using script console
import java.nio.charset.StandardCharsets
import org.apache.commons.io.IOUtils
// https://stackoverflow.com/questions/57107486/how-to-read-jenkins-credentials-at-folder-level
def folder = Jenkins.instance.getItems(com.cloudbees.hudson.plugins.folder.Folder).find({
// TODO handle sub-folders as required
it.getFullName() == 'folder-name'
})
@pwalkr
pwalkr / retropie-n64-controller.md
Last active December 18, 2022 23:38
Configuring N64 controller in RetroPie

The controller is easy enough to configure in Emulation Station frontend, but once in a game, the buttons are not correct. A tuned configuration is required for use with mupen64 emulators.

$ dmesg
[194164.863158] usb 1-1: new low-speed USB device number 6 using xhci_hcd
[194165.007396] usb 1-1: New USB device found, idVendor=0079, idProduct=0006, bcdDevice= 1.09
[194165.007420] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[194165.007432] usb 1-1: Product: Generic   USB  Joystick  
[194165.036270] input: Generic USB Joystick as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/0003:0079:0006.0006/input/input28
@pwalkr
pwalkr / ansible-find-exec-docker-swarm.yml
Last active December 11, 2022 17:14
Find (gitlab) container/node in swarm for executing backup via ansible
# Run on a swarm manager node
- name: find container and node
shell: |
set -e
{% raw %}
task_id="$(docker stack ps gitlab --filter desired-state=running --format="{{.ID}}")"
# stdout_lines[0]
docker inspect $task_id --format="{{.Status.ContainerStatus.ContainerID}}"
@pwalkr
pwalkr / error.md
Last active May 31, 2023 21:13
Ansible not detecting locale after system update
ansible --version
ERROR: Ansible requires the locale encoding to be UTF-8; Detected None.

Hacked with explicit assignment of LC_ALL:

LC_ALL=C.UTF-8 ansible --version
ansible [core 2.14.1]
@pwalkr
pwalkr / error.md
Created December 9, 2022 02:59
Foreground ansible docker_container times out

Error

TASK [backup to backblaze] ********************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: requests.exceptions.ConnectionError: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out.
fatal: [cirrus]: FAILED! => {"changed": false, "msg": "An unexpected requests error occurred when trying to talk to the Docker daemon: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out."}

Source