Skip to content

Instantly share code, notes, and snippets.

View guyc's full-sized avatar

Guy Carpenter guyc

  • Clearwater Software
  • Australia
View GitHub Profile
@guyc
guyc / enable_stack_termination_protection.sh
Created November 22, 2019 04:39
enable stack termination protection on all aws stacks
export AWS_PROFILE=xxxx
aws cloudformation list-stacks --stack-status-filter UPDATE_COMPLETE --query StackSummaries[*].StackName --output text | xargs -n 1 aws cloudformation update-termination-protection --enable-termination-protection --stack-name
@guyc
guyc / find_latest_ami.py
Created April 23, 2019 05:58
Find the latest available ami owned by me with a specific Name tag.
#!./env/bin/python
import boto3
import sys
def format_filter(fils=None, tags=None):
f = []
if fils is not None:
for k, v in fils.items():
f.append({'Name': k, 'Values': [v]})
@guyc
guyc / encode_user_data.py
Created April 23, 2019 05:55
Encode a bash file into base64 cloudinit user data.
#!./env/bin/python
import base64
import sys
def encode_user_data(lines):
"""
Input is an array of lines that together make a script.
Output is a base64 encoded block suitable for the userdata parameter
of an instance config.
"""
#!/usr/bin/env bash
# When sourced, this script will export the AWS_ACCESS_KEY_ID and
# AWS_SECRET_ACCESS_KEY credentials from the a specific profile in
# ~/.aws/credentials.
#
# Usage:
#
# export-aws-credentials [PROFILE]
#
@guyc
guyc / tachoFilter1
Last active November 27, 2016 01:37
Filter out short spikes from tacho sensor
unsigned long hTime = 0; // integer for storing high time
unsigned long lTime = 0; // integer for storing low time
const int window = 4; // sliding window size
const int shift = 3; // reject pulses if width < sum * (window / 2^shift) or 1/2 of mean pulse
unsigned long highFilter[window];
int highIndex = 0;
unsigned long lowFilter[window];
int lowIndex = 0;
@guyc
guyc / xmlsort.py
Created March 21, 2016 01:25
This is a quick-and-dirty tool to reformat XML configuration files to make it possible to diff them. It only preserves tag and attribute values.
#!/usr/bin/python
from xml.etree import ElementTree as ET
import sys
def compareString(a,b):
aLower = a.lower()
bLower = b.lower()
order = 0
if aLower > bLower:
@guyc
guyc / Forgiveness
Last active August 29, 2015 14:12
This is a Groovy script for Jenkins that will change the first failure to a success status, subsequent failures will be reported as failures. We use this to shut up spurious failure notifications for intermittent failures while we get some false alarms from our Sahi monitoring system ironed out.
Boolean failed = manager.getResult() != "SUCCESS";
def file = new File(manager.build.getWorkspace().getRemote() + '/FailedBuildsCount.txt');
def count = 0;
if (failed) {
if (!file.exists()) {
file.createNewFile();
} else {
FileReader reader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(reader);
@guyc
guyc / custom_query.py
Last active August 29, 2015 14:04
Tools for writing efficient zabbix custom queries. Includes data collection for mysqladmin extended-status, mysql show slave status and port usage collected with ss
#!/usr/bin/python
#
# Command-line:
# Dump everything
# ./portstat.py
#
# Dump specific value
# ./portstat.py state-time-wait
#
# UserParameter=oth.port[*],/etc/zabbix/scripts/portstat.py '$1'
@guyc
guyc / hipchat-notify.rb
Created July 11, 2014 01:41
zabbix notifier for hipchat
#!/usr/local/rvm/rubies/ruby-1.9.3-p547/bin/ruby
# Guy Carpenter - 11 Jul 2014
require 'rubygems'
require 'hipchat'
# API: https://github.com/hipchat/hipchat-rb
# https://www.hipchat.com/docs/api/method/rooms/message
to = ARGV[0]
subject = ARGV[1] # <Host>:(PROBLEM|OK):(Warning|Error|):<Name>
@guyc
guyc / capswitch.py
Created May 12, 2013 22:37
Test code for capacitive switch on raspberry pi.
import wiringpi
import time
# 1M external pull-up resistor
# 1) set pin low and to output to discharge
# 2) make the pin an input without the internal pull-up on
# 3) read input and see how long it takes to go high
# ref: https://github.com/WiringPi/WiringPi-Python
# pins: https://projects.drogon.net/raspberry-pi/wiringpi/pins/