Skip to content

Instantly share code, notes, and snippets.

View seanf's full-sized avatar

Sean Flanigan seanf

  • Brisbane, Australia
View GitHub Profile
@seanf
seanf / process.kt
Created August 23, 2017 02:12
Execute process from Kotlin
import java.lang.ProcessBuilder.Redirect
import java.util.concurrent.TimeUnit
fun String.runCommand(workingDir: File? = null) {
val process = ProcessBuilder(*split(" ").toTypedArray())
.directory(workingDir)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT)
.start()
if (!process.waitFor(10, TimeUnit.SECONDS)) {
@seanf
seanf / 81-thinkpad-dock.rules
Last active March 20, 2023 10:42
Example ThinkPad docking script for multi-monitor
# Save this file (after modifying ID_VENDOR and ID_MODEL if necessary) as /etc/udev/rules.d/81-thinkpad-dock.rules
# These values seem to work for "ThinkPad Mini Dock Plus Series 3"
SUBSYSTEM=="usb", ACTION=="add|remove", ENV{ID_VENDOR}=="17ef", ENV{ID_MODEL}=="100a", RUN+="/etc/sbin/thinkpad-dock.sh"
@seanf
seanf / jenkins-log-slowest-pipeline-steps.js
Created October 17, 2022 22:58
Log the slowest steps in a Jenkins build
// Paste this JavaScript into the JS console of your Jenkins build page
// eg https://jenkins.example.com/jenkins/job/MyJob/main/lastSuccessfulBuild/
// to see the slowest (non-paused) steps in your pipeline.
//
// Warning: this may not work for large jobs, or parallel steps.
// Ref: https://issues.jenkins.io/browse/JENKINS-52394
//
// This requires https://plugins.jenkins.io/pipeline-rest-api/
// (for https://github.com/jenkinsci/pipeline-stage-view-plugin/blob/master/rest-api/README.md#pipeline-rest-api-plugin)
const NUMBER_OF_CULPRITS = 10;
@seanf
seanf / scriptengines.groovy
Created July 18, 2016 06:01
Groovy script to list installed script engines
import javax.script.ScriptEngineManager;
def fs = new ScriptEngineManager().getEngineFactories()
fs.forEach{
println "Script Engine: " + it.engineName
println "Names: " + it.names
println()
}
@seanf
seanf / jenkins-ensure-timeout.groovy
Last active September 27, 2022 11:00
Jenkins Groovy script: sets a timeout strategy for any job which doesn't have one
// This script is for Jenkins' Groovy console, and sets a timeout
// strategy for any job which doesn't have one.
// Based on http://janmaterne.wordpress.com/2010/07/11/how-to-check-if-all-hudson-jobs-have-a-timeout/
// Updated and modified by Sean Flanigan.
import hudson.model.*
String describe(strat) {
if (strat instanceof hudson.plugins.build_timeout.impl.ElasticTimeOutStrategy) {
return "Elastic(${strat.timeoutPercentage}, ${strat.numberOfBuilds}, ${strat.timeoutMinutesElasticDefault})"
@seanf
seanf / rmb.sh
Last active September 27, 2022 11:00
Remove Merged Branches From Git. Copied from http://stackoverflow.com/a/9739058/14379 based on http://rob.by/2013/remove-merged-branches-from-git
#!/bin/bash
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo -e "Fetching merged branches...\n"
git remote update --prune
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
@seanf
seanf / zanata-table-fix-case.groovy
Last active September 27, 2022 11:00
zanata-table-fix-case.groovy: convert lower case Zanata table names back to their original (title) case in an SQL backup
#!/bin/env groovy
/*
* zanata-table-fix-case.groovy
*
* Unix filter script to convert lower case Zanata table names back to their original (title) case in an SQL backup
*
* Usage: zcat zanata_backup.sql.gz | zanata-tables-fix-case.groovy | gzip -c > zanata_backup.casefixed.sql.gz
*
* Version 3
* Date: 7 Nov 2013
@seanf
seanf / JenkinsSlaveWorkspaceCleanup.groovy
Last active September 27, 2022 10:42
Jenkins Slave Workspace Cleanup by Bertrand Renuart: http://narkive.com/gsOMTV6x#post6
import hudson.FilePath;
// Initialize dryRun parameter to TRUE if not given as script parameter
if( !binding.variables.containsKey("dryRun") ) {
dryRun = true;
}
if( dryRun == true ) {
println "** Execute a dryRun - no files will ever be deleted **";
}
@seanf
seanf / convert-git-team.sh
Created July 15, 2022 06:44
convert a `git-team` config to `.git_coauthors`
brew install jc jq
cat ~/.gitconfig | jc --ini | jq -r '."team \"alias\"" | to_entries[] | .value'
@seanf
seanf / describe.java
Created November 26, 2021 03:56
describe: a cheap toString substitute for objects which may have verbose toString implementations
public static String describe(Object obj) {
return obj.getClass().getSimpleName() + '@' + System.identityHashCode(obj);
}