Skip to content

Instantly share code, notes, and snippets.

View MattHealy's full-sized avatar

Matt Healy MattHealy

View GitHub Profile
@MattHealy
MattHealy / docx-sample.py
Created January 3, 2018 07:05
python-docx example
def merge(r):
if '{{LESSOR}}' in r.text:
r.text = r.text.replace('{{LESSOR}}', 'my name')
if '{{LESSORADDRESS}}' in r.text:
r.text = r.text.replace('{{LESSORADDRESS}}', 'my address')
from docx import Document
@MattHealy
MattHealy / convert.py
Created May 16, 2019 03:27
Convert minutes in to days, hours and minutes
def convert(minutes):
if isinstance(minutes, int):
return str(minutes/24/60) + " day, " + \
str(minutes/60 % 24) + " hours, " + \
str(minutes % 60) + " minutes"
else:
return "0 days, 0 hours, 0 minutes"
@MattHealy
MattHealy / apigateway-sqs-integration.yaml
Created May 22, 2019 02:53
Cloudformation Template for API Gateway AWS Service Integration to SQS Queue
Description: API Gateway to JSON payloads and send to SQS
Outputs:
ApiEndpoint:
Description: Endpoint for this stage of the api
Value: !Join
- ''
- - https://
- !Ref 'SQSProxy'
- .execute-api.ap-southeast-2.amazonaws.com/
- prod
@MattHealy
MattHealy / vimrc
Created August 7, 2019 23:06
Mac OSX vimrc file
" Display a red column 80 chars in .py files (to assist with line length)
" set colorcolumn=80
autocmd FileType python setlocal colorcolumn=80
" Return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
@MattHealy
MattHealy / pre-push
Created August 13, 2019 11:47
Git pre-push hook to automatically deploy on master branch push
#!/bin/bash
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [[ "$BRANCH" == "master" ]]; then
./deploy.sh
fi
#!/usr/bin/env python3
import subprocess
import zipfile
import os
dirs = next(os.walk('.'))[1]
for d in dirs:
print("Preparing {} ZIP archive".format(d))
@MattHealy
MattHealy / list-pull-requests.py
Last active October 23, 2022 02:35
List all open pull requests in AWS Codecommit
import boto3
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
'--repo', metavar='repo', type=str,
help='Optionally filter by repository')
args = parser.parse_args()
@MattHealy
MattHealy / kill-mysql-processes.txt
Last active June 13, 2023 04:27
Kill long running mysql select queries
To kill stuck processes
select group_concat(concat('KILL ',id,';') separator ' ')
from information_schema.processlist
where Time>'100' and Info like 'select %';
To kill sleeping processes and allow alter table to occur
select group_concat(concat('KILL ',id,';') separator ' ')
from information_schema.processlist
@MattHealy
MattHealy / watchAmazon.sh
Last active December 11, 2019 23:29
Watch an amazon product price
watch -n 60 "curl -s \
--url 'https://www.amazon.com.au/Thermos-THERMOcafe-Vacuum-Insulated-BOL750R6AUS/dp/B07DHGBNM9' \
--compressed | grep 'priceblock_ourprice' | grep 'priceBlockBuyingPriceString' >> /tmp/amazon.log"
@MattHealy
MattHealy / amazon-s3-put.pl
Created July 7, 2020 11:51
PUT a large file directly to Amazon S3
#!/usr/bin/perl
use File::Slurp; # not strictly needed, but nice to have
use Data::Dumper;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;
my $key = '';
my $token = '';