Skip to content

Instantly share code, notes, and snippets.

View partition.WORKSTATION
#!/usr/bin/perl
# vim: ts=4 sw=4 et
use warnings;
use strict;
use autodie;
use Data::Dumper;
exit(0) unless ($ENV{FAI_ACTION} // '' eq 'install' and $ENV{disklist} // '' eq 'nvme0n1');
@glance-
glance- / Makefile
Created Jun 12, 2020
use hass-cli to edit lovelace config as yaml in vim
View Makefile
# make edit_lovelace-ui.yml
edit_lovelace-ui.yml:
TMPFILE=$$(mktemp /tmp/XXXXXX-lovelace-ui.yml) ; \
~/lap/homeassistant/bin/hass-cli raw ws lovelace/config > "$${TMPFILE}" ; \
perl -pi -e 'BEGIN {undef $$/;} s/^id: 1\ntype: result\nsuccess: true\nresult:\n/config:\n/' "$${TMPFILE}"; \
vim "$${TMPFILE}" ; \
~/lap/homeassistant/bin/hass-cli raw ws lovelace/config/save --yaml "@$${TMPFILE}" && \
rm -f "$${TMPFILE}"
@glance-
glance- / .rtorrent.rc
Created May 13, 2020
rtorrent / screen / systemd
View .rtorrent.rc
# If we're running with the right systemd env, run our heartbeat to systemd.
execute2={/bin/systemd-notify,--ready}
execute2={/bin/bash,-c,systemd-notify MAINPID=`ps -p "$\{1:-$$\}" -o ppid= | tr -d " "`}
execute2={/bin/systemd-notify,WATCHDOG_USEC=480000000}
schedule=systemd_watchdg, 10, 60, "execute2={/bin/systemd-notify,WATCHDOG=1}"
@glance-
glance- / .git-pre-commit.sh
Created Oct 14, 2019
Don't allow git commit as root
View .git-pre-commit.sh
#!/bin/bash
# install with ln -s ../../.git-pre-commit.sh .git/hooks/pre-commit
AUTHORINFO=$(git var GIT_AUTHOR_IDENT) || exit 1
NAME=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^\(.*\) <.*$/\1/p')
EMAIL=$(printf '%s\n' "${AUTHORINFO}" | sed -n 's/^.* <\(.*\)> .*$/\1/p')
[ "${NAME}" != root ] && [ "${NAME}" != "Your Name" ] && [[ ! "${EMAIL}" =~ root@.* ]] || {
cat <<EOF >&2
Please commit under your own name and email instead of "${NAME} <${EMAIL}>":
@glance-
glance- / hack-docker-plugin-instance-cap.groovy
Created Oct 10, 2019
This is a nice hack to workaround a bug in docker-plugin
View hack-docker-plugin-instance-cap.groovy
def c = com.nirima.jenkins.plugins.docker.DockerCloud.getCloudByName('Host docker')
// We're going to hack java final fields here...
import java.lang.reflect.Field
import java.lang.reflect.Modifier
for (def jt in c.getJobTemplates().values()) {
Field field = jt.getClass().getDeclaredField("instanceCap")
Field modifiersField = Field.class.getDeclaredField("modifiers")
@glance-
glance- / LockableResourcesHelper.groovy
Created Aug 10, 2017
Helper pipeline library for label based locking in jenkins pipeline
View LockableResourcesHelper.groovy
// vim: noet sw=4 ts=4 cindent
// This is a helper that runs as privileged code, to get the LockableResource to pipeline jobs
package PipelineHelpers;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
// Wrapper class to expose a safe subset to the client code
class LockableResourcesHelper implements Serializable {