Skip to content

Instantly share code, notes, and snippets.

Avatar
🐮

David Goodwin DavidGoodwin

🐮
View GitHub Profile
@DavidGoodwin
DavidGoodwin / pressure.sh
Last active Aug 12, 2019
linux psi pressure munin plugin
View pressure.sh
#!/bin/bash
# -*- sh -*-
: << =cut
=head1 NAME
Munin plugin to plot Linux CPU pressure - see: https://lwn.net/Articles/759781/
=head1 CONFIGURATION
@DavidGoodwin
DavidGoodwin / kill-long-running-mysql-queries-in-rds.sh
Created Oct 9, 2018
Kill long running MySQL queries (in AWS RDS)
View kill-long-running-mysql-queries-in-rds.sh
#!/bin/bash
MYSQL="mysql --defaults-extra-file=/path/to/something.cnf"
# Find queries which have been running for longer than 1800 seconds.
for PID in $($MYSQL -BNe "SELECT id FROM information_schema.processlist WHERE command <> 'Sleep' AND info NOT LIKE '%PROCESSLIST%' AND command <> 'Killed' AND time > 1800" )
do
#OUTPUT=$($MYSQL -NBe "SELECT id,time,command,info FROM information_schema.processlist WHERE id = $PID ")
#echo "Long running query output - $OUTPUT "
@DavidGoodwin
DavidGoodwin / tplink.sh
Created Jan 18, 2018
control a tplink HS100/HS110 smart plug from bash/the cli
View tplink.sh
@DavidGoodwin
DavidGoodwin / mysql-backup.sh
Created Nov 5, 2017
MySQL backup script (bash)
View mysql-backup.sh
#!/bin/bash
# Simple backup script for MySQL/MariaDB on a Debian/Ubuntu based server.
# You can run this as often as you like (hourly, daily, weekly). It contains locking to stop multiple executions at once.
# Dependencies:
# apt-get install lockfile-progs
## Begin config.
@DavidGoodwin
DavidGoodwin / lxc_cpu_top.py
Last active Apr 9, 2017 — forked from wryfi/lxc_load.py
simple python script to check cpu utilization of lxc containers and print percentage
View lxc_cpu_top.py
#!/usr/bin/python
# See https://gist.github.com/wryfi/3902757
# Crude CPU usage thing for container(s).
import multiprocessing, os, re, sys, time
import getopt
cgroup_dir = '/sys/fs/cgroup/lxc/'
View auto_increment_capacity.sql
SELECT table_schema,
table_name,
data_type,
( CASE data_type
WHEN 'tinyint' THEN 255
WHEN 'smallint' THEN 65535
WHEN 'mediumint' THEN 16777215
WHEN 'int' THEN 4294967295
WHEN 'bigint' THEN 18446744073709551615
end >> IF(Locate('unsigned', column_type) > 0, 0, 1) ) AS MAX_VALUE,
View fix-nextgen-lightbox-path.php
<?php
/*
INSTRUCTIONS: Use at your own risk. Backup your database before continuing.
1. Copy code to a file in the root of your website.
2. Change YOUR_SITE_ROOT to a value that makes sense.
3. Execute by visiting the page. Verify before/after results.
4. Change MAKE_CHANGES_TO_SITE to true and execute it again.
*/
View fix-nextgen-lightbox-path.php
<?php
/*
INSTRUCTIONS:
Use at your own risk. Backup your database before continuing.
1. Copy code to a file in the root of your website.
2. Change YOUR_SITE_ROOT to a value that makes sense.
3. Execute by visiting the page. Verify before/after results.
4. Change MAKE_CHANGES_TO_SITE to true and execute it again.
View gist:10023233
<?php
/* Original effort: https://gist.github.com/Daniel15/5991193 */
function last($arr)
{
eval('list(' . str_repeat(',', count($arr) - 1) . '$result) = $arr;');
return $result;
}
@DavidGoodwin
DavidGoodwin / sshfp-tinydns.pl
Created Mar 14, 2014
convert BIND style SSHFP record into something TinyDNS can understand
View sshfp-tinydns.pl
#!/usr/bin/perl
use strict;
# Take in, e.g. :
# foobar.palepurple.co.uk IN SSHFP 1 1 9676BB7A92C7E11B90E9508A343A4CAE9888B43D";
# foobar.palepurple.co.uk IN SSHFP 2 1 D4F49CE2195A0BF531275B889ED6ABFF2F24C2BC
# on standard input, and output the appropriate tinydns records for sshfp -
# e.g.
# :foobar.palepurple.co.uk:44:\001\001\226\166\273\172\222\307\341\033\220\351\120\212\064\072\114\256\230\210\264\075:
# :foobar.palepurple.co.uk:44:\002\001\324\364\234\342\031\132\013\365\061\047\133\210\236\326\253\377\057\044\302\274: