Skip to content

Instantly share code, notes, and snippets.

View M1ke's full-sized avatar

Mike Lehan M1ke

View GitHub Profile
@M1ke
M1ke / Bookmarklet
Last active February 26, 2024 07:15
Script to add a timer to a page, along with a function to record it in a Trello comment.
javascript:(function(){
var jsCode=document.createElement('script');
jsCode.setAttribute('src','https://gist.github.com/M1ke/4944552/raw/17d5768dab89f3737104202b4fc7a56d286fc4c7/trello-timer.js');
document.body.appendChild(jsCode);
}());
@M1ke
M1ke / disk-usage-alert.sh
Last active February 21, 2024 15:35
A shell script to check your disk usage and alert you if it hits a limit. Change the value (percentage) in the "if" statement on line 7 to alter the threshold. Change the email address to your email address. See readme for mail.cf instructions and crontab.
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
used=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 80 ]; then
echo "The partition \"$partition\" on $(hostname) has used $used% at $(date)" | mail -s "Disk space alert: $used% used" your@email.com
fi
done
@M1ke
M1ke / .jq
Created February 12, 2024 20:35
~/.jq for handy jq pipes
# https://stackoverflow.com/a/28641626/518703
def decode_ddb:
def _sprop($key): select(keys == [$key])[$key]; # single property objects only
((objects | { value: _sprop("S") }) # string (from string)
// (objects | { value: _sprop("NULL") | null }) # null (from boolean)
// (objects | { value: _sprop("B") }) # blob (from string)
// (objects | { value: _sprop("N") | tonumber }) # number (from string)
// (objects | { value: _sprop("BOOL") }) # boolean (from boolean)
// (objects | { value: _sprop("M") | map_values(decode_ddb) }) # map (from object)
// (objects | { value: _sprop("L") | map(decode_ddb) }) # list (from encoded array)
@M1ke
M1ke / README.md
Last active December 7, 2022 22:05
Quickly convert a markdown file into a nice looking PDF formatted in the same way GitHub formats Readme.md files

Markdown to PDF

Quickly convert a markdown file into a nice looking PDF formatted in the same way GitHub formats Readme.md files

  • Install grip $ pip install grip
  • Install wkhtmltopdf $ sudo apt-get install wkhtmltopdf
@M1ke
M1ke / apigw-express.ts
Created September 21, 2022 10:46
Quick helper functions when testing local serverless applications (Typescript + AWS Lambda) to translate `express` req/res objects into the appropriate types for API Gateway
const apiGWEventFromReq = (req: Request): APIGatewayEvent => {
const [headers, multiValueHeaders] = Object.keys(req.headers).reduce((parts, key) => {
const val = req.headers[key]
if (!val) {
return parts
}
const [headers, multiValueHeaders] = parts
if (Array.isArray(val)) {
multiValueHeaders[key] = val;
} else {
@M1ke
M1ke / psalm-query.php
Created April 27, 2022 15:06
This tool processes a SQL query and generates a guess at an appropriate Psalm object-like array definition
<?php
const PSALM_STRING = ': string';
const SELECT_ALL = '*';
// These must be upper case to avoid accidental positives
const SQL_SELECT = 'SELECT';
const SQL_FROM = 'FROM';
const ARG_DEBUG = '--debug';
// This is lower case as the field names are forced to lower case
const SQL_AS = ' as ';
@M1ke
M1ke / bitbucket-pipelines.yml
Created February 14, 2022 17:49
Composer update pipeline in Bitbucket
pipelines:
# Manually triggered Pipelines
custom:
composer-update:
- step:
name: Composer Update
image: prooph/composer:<pick your version, e.g 7.4>
script:
- export COMPOSER_BRANCH="composer-update-auto-$(date +"%Y-%m-%d")"
- git checkout -b "$COMPOSER_BRANCH"
@M1ke
M1ke / markdown-to-github-pdf.sh
Created July 15, 2021 11:39
Simple command line tool using python's grip library and wkhtmltopdf to generate a PDF file from a Markdown file. Basically starts a server, captures it as a PDF and then kills the server (that's the complex bit!)
#!/bin/bash
# Install grip $ pip install grip
# Install wkhtmltopdf $ sudo apt-get install wkhtmltopdf
md=$1
pdf=$md.pdf
port=$(( ( RANDOM % 6000 ) + 5000 ))
echo $port
@M1ke
M1ke / _AWS-AutoScaling.md
Last active July 12, 2021 14:04
Useful scripts to automate components of AWS EC2

AWS EC2 Python scripts

Using EC2 instances within an autoscaling group is the best way to guarantee redundancy, scalability and fault tolerance across your infrastrucutre.

This comes at the price of common paradigms such as being able to SSH into a known URL to manage configuration or logs, and the requirement that configurations must be applied to multiple machines.

DevOps provisioning tools such as Puppet can be used to manage configurations, but they

@M1ke
M1ke / bitbucket-prs.php
Last active July 6, 2021 15:57
Handy PHP script to examine and merge lists of BitBucket PRs
<?php
/*
* Declare the following consts:
*
* REPO_DEFAULT - Set this to avoid having to type each time
* TEAM - Find this in URLs
* USER, PASS - Bitbucket credentials
*
* Install Guzzle and require './vendor/autoload.php'
*/