Skip to content

Instantly share code, notes, and snippets.

View mikaelvesavuori's full-sized avatar

Mikael Vesavuori mikaelvesavuori

View GitHub Profile
@mikaelvesavuori
mikaelvesavuori / dora.ts
Created June 8, 2023 13:24
Minimal DORA metrics implementation using data from GitHub, as suggested by ChatGPT
// Configuration
const owner = "your-github-username";
const repo = "your-repository-name";
interface PullRequest {
created_at: string;
merged_at: string;
}
interface Deployment {
@mikaelvesavuori
mikaelvesavuori / SheetsDestructuringFunction.sh
Created June 1, 2023 14:32
Destructure semicolon-separated strings in Google Sheets into separate items
= {"Destructure issues into separate items"; ArrayFormula(TRANSPOSE( {SPLIT( {JOIN("",{REGEXREPLACE('YOUR SHEET NAME'!W2:W,"\(.*\)","")})}, ";", FALSE, TRUE)}))}
@mikaelvesavuori
mikaelvesavuori / index.ts
Last active May 6, 2023 10:23
Repro of inability to call GitHub from Cloudflare Workers. Solution: This can be solved by adding the "User-Agent" header to calls.
/**
* @description This is the entry point for the Cloudflare Worker.
* Call it with `http://0.0.0.0:8787?endpoint=gh` or `http://0.0.0.0:8787?endpoint=swapi`
*/
export default {
async fetch(request: Request): Promise<Response> {
const { searchParams } = new URL(request.url);
let endpoint = searchParams.get("endpoint");
const result = await (async () => {
@mikaelvesavuori
mikaelvesavuori / tracing-basics-demo.ts
Last active March 11, 2023 17:26
Demo of some of the basics of manually implementing a tracing library in TypeScript. Has an AWS Lambda handler, but can work anywhere.
import { randomBytes } from 'crypto';
/**
* @description Simple demo of tracing in a manual way.
*
* Note that this demo does not actually set the duration of traces
* given that you provide them manually here.
*
* Another thing obviously missing is therefore, by logical extension,
* any way of "ending" a span.
@mikaelvesavuori
mikaelvesavuori / echo-name.sh
Last active March 6, 2023 12:11
Demonstration of Bash input values, assignment, and null checking with an "echo name" example.
#!bin/bash
set -o pipefail
# Assign first value to a named global variable
NAME="${1}"
# Exit with an error if not set
if [[ -z $NAME ]]; then echo "You need to call this with a value!" && exit 1; fi
# Echo first value coming into function
@mikaelvesavuori
mikaelvesavuori / git-diff-gh-actions.ts
Created January 20, 2023 19:52
Get git diff between the current and last commit in GitHub Actions
import { simpleGit } from 'simple-git';
diff(github.context.payload.after, github.context.payload.before);
async function diff(after: string, before: string) {
const git = simpleGit();
const diff = await git.diffSummary([after, before]);
console.log(diff);
}
@mikaelvesavuori
mikaelvesavuori / pdf-from-md.sh
Last active January 8, 2023 20:11
PDF from Markdown
#!/bin/bash
# Requires pandoc
# @see https://pandoc.org
mkdir -p pdf
for file in *.md; do
pandoc $file -s -o pdf/$file.pdf --pdf-engine=xelatex
done
@mikaelvesavuori
mikaelvesavuori / github-secret-verification.ts
Last active December 29, 2022 12:36
Verify GitHub webhook secret using Node and TypeScript
import { createHmac, timingSafeEqual } from 'crypto';
const TOKEN = 'SOME_SECRET_VALUE';
/**
* @description Verify GitHub secret from signature.
*
* There are a ton of these examples out there but some are really messy and this one tidies them up a bit.
*
* @param {string} headerValue - Pass in `headers['X-Hub-Signature-256']`. Looks something like 'sha256=3fead968c...'
@mikaelvesavuori
mikaelvesavuori / getExpiryTime.ts
Created December 27, 2022 14:55
Create and return 10-digit Unix-formatted expiration time for a DynamoDB item.
/**
* @description Create and return 10-digit Unix-formatted expiration time for a DynamoDB item.
*/
export function getExpiryTime(expirationInMinutes = 10): string {
const date = new Date();
return date
.setMinutes(date.getMinutes() + expirationInMinutes)
.toString()
.substring(0, 10);
}
@mikaelvesavuori
mikaelvesavuori / ic-metrics-gh-graphql-api.md
Last active January 14, 2025 07:25
Get Individual Contributor metrics from GitHub's GraphQL API.

Get Individual Contributor metrics from GitHub's GraphQL API

These are some handy snippets to get common metrics for checking how active a software engineer is.

  • How many pushes are made by the IC?
  • How many reviews are made by the IC?
  • How many comments are made by the IC?

Setup