Skip to content

Instantly share code, notes, and snippets.

View johnl's full-sized avatar

John Leach johnl

View GitHub Profile
@johnl
johnl / collectd.conf
Created November 20, 2020 23:08
collectd script to report ipt hashtable sizes
<Plugin exec>
Exec "nobody" "/usr/local/bin/collectd_ipt_hashtable.sh"
</Plugin>
@johnl
johnl / terraform wrapper
Last active August 4, 2020 09:50
a script to run the right version of terraform for the current repository
#!/bin/bash
# this script expects to find each terraform version binary available in the path
# with the filename format terraform_0.x.x
#
# requires jq
# doesn't currently support reading states in terraform workspaces
function die {
echo $1
exit 1
@johnl
johnl / broadcast.rb
Created August 17, 2018 15:32
Puppet Facter v2+v3 compatible broadcast address fact provider. Get broadcast address for each available network interface.
# Fact: broadcast
#
# Purpose:
# Get broadcast addresses for each interface.
#
Facter.value('interfaces').split(',').each do |interface|
Facter.add("broadcast_" + interface) do
setcode do
require 'ipaddr'
@johnl
johnl / set-all-file-mtime-to-commit-time.sh
Last active January 13, 2023 16:56
Change file modification timestamps to the last git commit timestamps for all files in a git tree
#!/bin/bash
git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="%at {}" {} | perl -ane '($t,$f)=@F;utime($t,$t,$f)'
@johnl
johnl / gnome-keyring-key-deleter.py
Created February 15, 2018 14:43
rough and dangerous script to delete all keys in gnome-keyring matching a certain application id
#!/usr/bin/env python
import getpass, re, sys
import gnomekeyring
all_items = gnomekeyring.list_item_ids_sync("login")
for item in all_items:
attributes = gnomekeyring.item_get_attributes_sync("login", item)
if attributes.has_key("application") == False or attributes["application"] != "chrome-10788085": continue
print attributes["action_url"]
@johnl
johnl / segfault-shared-lib-symbol-resolver.rb
Created January 5, 2018 18:50
Script to resolve segfault symbol addresses in shared libs
#!/usr/bin/ruby
# use this like: dmesg | grep segfault | segfault-shared-lib-symbol-resolver.rb | addr2line -e /usr/lib/debug/usr/lib/i386-linux-gnu/libruby-2.1.so.2.1.0
# kernel: [352246.560406] ruby[1178]: segfault at bf6630d0 ip b75f6fa3 sp bf6630c0 error 6 in libruby-2.1.so.2.1.0[b7469000+254000]
STDIN.each_line do |l|
r = /ip ([^ ]+).*\[([^+]+)/
m = r.match l
ip = m[1].to_i(16)
offs = m[2].to_i(16)
@johnl
johnl / pipeline.groovy
Last active January 3, 2018 12:42
jenkins docker-node-maintenance pipeline job
@NonCPS
List <String> getOnlineNodeNames() {
List <String> nodeNames = []
for (node in Jenkins.getInstance().getNodes()) {
if (node.getComputer().isOnline()) {
nodeNames.add(node.name.toString())
}
}
return nodeNames
@johnl
johnl / mp4.sh
Created July 14, 2017 21:56 — forked from anonymous/mp4.sh
Merge multiple mp4 files as chapters
#! /usr/bin/env bash
####################################################
# Required Libraries
#
# library name | commands used | verified version
# ------------------------------------------------
# ffmpeg | ffmpeg/ffprobe | 3.1.4 3.2
# gpac | MP4Box | 0.6.1
# mp4v2 | mp4chaps | 2.0.0
@johnl
johnl / nginx-status.nse
Last active February 27, 2021 13:39
nmap script to check if a service is serving an nginx status page
local http = require "http"
local nmap = require "nmap"
local shortport = require "shortport"
local string = require "string"
description = [[
Detects if the service is serving an nginx status page
]]
---
cat /proc/stat | grep "cpu " | perl -e 'use List::Util qw(sum); @cols = split /\s+/, <>; shift @cols; $total = sum(@cols); $steal = ($cols[7] / $total) * 100; printf("%0.5f%\n", $steal)'