Skip to content

Instantly share code, notes, and snippets.

@akomakom
akomakom / SemVer.groovy
Last active February 1, 2024 19:58 — forked from michaellihs/SemVer.groovy
Semantic Versioning class for Groovy
/**
* This evolved from pure SemVer to any-length version with optional -suffix
* accepts any of:
* 1
* 1.2
* 1.2.3
* 1.2.3.4 (etc, no limit)
* 1.2.3-SNAPSHOT
*
* bump() also accepts index values, eg -1 (last component), -2 (second from end), etc:
@akomakom
akomakom / Readme Low Battery Warning Alert for Linux.md
Last active March 25, 2023 06:49
Play periodic sound when laptop battery is low, also when charger is plugged in/unplugged

Suitable for laptops that don't generate udev events when battery charge level changes (but do generate events when unplugged).

Uses MP3 files (use mine or make your own).
You can also change sound() to use a tone as in this example

Installation

  • Copy MP3 files to /usr/local/bin (or change the shell script)
  • Copy other files to the location specified at the top (change "CHANGE_TO_MY_USER" to the username you primarily use)
@akomakom
akomakom / README.md
Last active March 9, 2023 15:26
AWS Lambda function to kill forgotten instances, pure NodeJS

AWS Lambda function to kill old instances

A pure NodeJS function to kill select EC2 instances if they run longer than a defined period.

This is useful as a safety measure when using EC2 in CI and launching many instances.
A CI crash or user action could prevent proper cleanup, leaving expensive machines running forever (or until the next billing cycle when there is much screaming).

Instructions

@akomakom
akomakom / jenkins-groovy-system-script.groovy
Last active October 21, 2022 17:32 — forked from rb2k/gist:8372402
A jenkins script to clean up workspaces on slaves. On all slaves with less than X free GB, this script removes /slaves/workspace/* if slave is idle. If not idle, it removes /full/job/workspace/path for each job that isn't currently running. There are two versions: a "System Groovy Script" and a Jenkinsfile (Pipeline script)
/**
Jenkins System Groovy script to clean up workspaces on all slaves.
Check if a slave has < X GB of free space, perform cleanup if it's less.
If slave is idle, wipe out everything in the workspace directory as well any extra configured directories.
If slave is busy, wipe out individual job workspace directories for jobs that aren't running.
Either way, remove custom workspaces also if they aren't in use.
**/
import hudson.model.*;
@akomakom
akomakom / doshutdown
Last active June 28, 2021 14:03
Plugin for apcupsd to prevent low battery shutdown when external DC source is connected
#!/usr/bin/env python
# Prevent shutdown when batteries are not really empty
# installed in /etc/apcupsd/ as 'doshutdown' and 'mainsback' (symlink)
import os
from sys import argv
from subprocess import check_output
from syslog import syslog
threshold=24.3 # If batteries are above this, don't shut down
#!/usr/bin/env python3
from subprocess import check_output
from re import findall, DOTALL, MULTILINE
import psutil
def log(s):
check_output(['logger', '-t', __file__, s])
inputs = findall(r'.*?index: (\d+).*?sink: (\d+).*?application\.process\.id = "(\d+)"',
@akomakom
akomakom / README.md
Last active April 16, 2021 22:31
Automated DVD Rip (then encode) using dvdbackup and ffmpeg, on insert. udev->systemd->dvdrip(script here)->dvdbackup (automatic rip to VOB). Then, when all are ripped, run dvdencode(script here) to compress all VOBS into a new cleanly named hierarchy

What this is

A collection of files to set up the following automation:

  • Activate on insert
  • Rip the DVD to a temporary path (eg /opt/dvd/tmp.XXXXX/NAME-FROM-DVD-ITSELF/VIDEO_TS)
  • Eject

Then a manual step:

  • Review directory names and rename as needed (a lot of DVD disk identifiers are useless)
  • run dvdencode, it will process all of the above to a new hierarchy, example filename: /opt/dvd/encoded/NAME-FROM-DVD-ITSELF/NAME-FROM-DVD-ITSELF-1-of-7.mp4
@akomakom
akomakom / ansible-setup-windows.ps1
Last active December 25, 2020 23:15
Set up windows host for ansible remoting including upgrading powershell and rebooting if necessary (reboots only if PS requires upgrade)
# This script has been tested on Windows server 2008, 2012, 2016 and Windows 10.
# This script can be run from puppet using puppetlabs/powershell:
# exec { 'setup-ansible-remoting':
# command => file("${module_name}/ansible-setup-windows.ps1"),
# provider => powershell,
# logoutput => true,
# }
# To make sure that we can run local scripts. You may need to run this line manually before you can run this script
@akomakom
akomakom / README.md
Last active November 11, 2019 15:16
barracudavpn <-> systemd-resolve compatibilty script

barracudavpn <-> systemd-resolve compatibilty script

Problem

My corporate Ubuntu laptop is set up with barracudavpn that doesn't understand systemd-resolve.
In its default configuration it simply overwrites /etc/resolv.conf, completely screwing up DNS on my local LAN (and non-work DNS).

Purpose

@akomakom
akomakom / README.md
Last active January 15, 2019 01:03
Bash completion file for tmux using a simple clusters file, autocompletes list names and starts ssh to all matches in a single window with synchronized keyboard input.

What this is

The two bash completion scripts provide two bash completion prefixes:

  • tm or tmuxmulti ("Connect in a split terminal to all hosts in the matched list(s)")
  • tmh or tmuxmultihost ("Tmux Multi by Host", same but for matching against the hostnames rather than list names)

The system-of-record for both of these is a ~/.tmux_clusters file (see below for format).

Installation

Option 1 (static)