Skip to content

Instantly share code, notes, and snippets.

View M1ke's full-sized avatar

Mike Lehan M1ke

View GitHub Profile
@M1ke
M1ke / tech-debt.md
Created February 7, 2025 16:51
My notes on the "Tech Debt" roundtable discussion at Branch, a CTO & engineering leader group in Manchester

Branch: Tech debt

Poor quality notes, by Mike

This is some notes I took during our discussion; at the start I did try to attribute names to quotes, but as it went on a) people interjected more and it was harder to give direct attribution and b) I got a few peoples' names confused early on and that messed the rest up!

We began with the question of "define technical debt" and in fact this was the only question Dave really got to ask, as our discussion progressed naturally from trying to define it to trying to identify causes.

A few early point were made:

  • Measured decision, understand the interest rate. "Different kinds of debt need different kinds of remedies"
@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 / 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 / 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'
*/
@M1ke
M1ke / cloudwatch-parse-slow-query.md
Last active May 28, 2021 10:23
Example queries for parsing mysql slow query logs

Using AWS RDS we can export default MySQL logs to CloudWatch. This can include the slow query log.

As standard, CloudWatch logs will just show the log message, which allows reading the log, but not doing useful analysis, such as finding the slowest queries over a time range, or the slow query which repeats the most often.

Using CloudWatch Insights we can write custom log search queries to try and extract more information. It starts with a parse step, where the "glob" parser can be used to take a single block log message and pull out individual data points:

PARSE @message '# Time: * *\n# User@Host: *[*] @ * Id: *\n# Query_time: * Lock_time: * Rows_sent: * Rows_examined: *\n*' as date,time,user,host,ip,id,duration,lock,rows,examined,query
@M1ke
M1ke / interface-trait-inheritance.php
Created March 8, 2021 12:24
Demonstrates the use of traits and interfaces to "mock" multiple inheritance in PHP
interface AsNumber {
public function asNumber(): int;
}
interface CanBeAdded {
public function add(AsNumber $b): int;
}
interface CanBeMultiplied {
public function multiply(AsNumber $b): int;
@M1ke
M1ke / bash.md
Last active September 7, 2020 14:37
Generally useful stuff for bash

Felt I should collate useful stuff I constantly bounce between files to look up

Expand alias (when in interactive terminal)

Ctrl + Alt + e

(Ubuntu)

Exit if variable (e.g. envvar) isn't set