Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
maxpeterson / awsLambdaCodePipelineCloudfrontCreateInvalidation.js
Created April 16, 2021 13:39
AWS Lambda function to create CloudFront invalidation for CodePipeline
const AWS = require('aws-sdk');
const getDistribution = async (client, bucket) => {
const params = { MaxItems: '100' };
for (;;) {
const { DistributionList: { Items: DistributionItems, IsTruncated, NextMarker } } = await client.listDistributions(params).promise();
if (!DistributionItems) continue;
for (const distribution of DistributionItems) {
const { Origins } = distribution
if (!Origins?.Items) continue;
@maxpeterson
maxpeterson / nestToLibrary.sh
Created January 12, 2021 08:16
Alias to convert / move next project "module" to library
function nestToLibrary {
name=$1
if [ -z "$name" ]; then
echo 'No module name provided'
return 1;
fi
nest generate library "${name}"
rm libs/${name}/src/${name}.*
git mv apps/cynomi/src/${name}/* libs/${name}/src
rm -rf "apps/cynomi/src/${name}"
@maxpeterson
maxpeterson / snakeToCamel.sh
Last active November 20, 2020 10:43
Convert file contents from snake_case to camelCase
#!/bin/sh
if [[ "$@" == "" ]]; then
echo "$0: No files specified"
echo "$0 <file> [<file2>]"
exit 1
fi
@maxpeterson
maxpeterson / git-anonymise.sh
Last active December 16, 2020 11:29
Rewrite all commits to anonymise author and committer's name and email
#!/bin/sh
# Each author and committer's name and email will be replaced by an anonymous value
# Create a git alias
# git change-commits GIT_AUTHOR_NAME "old name" "new name"
git config alias.change-commits '!'"f() { VAR=\$1; OLD=\$2; NEW=\$3; shift 3; git filter-branch --env-filter \"if [[ \\\"\$\`echo \$VAR\`\\\" = '\$OLD' ]]; then export \$VAR='\$NEW'; fi\" \$@; }; f "
# Git valriables to replace with git log formats to generate a list of values toi change
declare -a formats=("GIT_AUTHOR_NAME::%aN" "GIT_AUTHOR_EMAIL::%aE" "GIT_COMMITTER_NAME::%cN" "GIT_COMMITTER_EMAIL::%cE");
sed -E -e 's/^#.*//' \
-e 's/"(.*)"/\1/' \
-e 's/\\n//' \
-e 's/(msgid_plural|msgstr|msgid)(\[[0-1]\])?//' \
locale/en-gb/LC_MESSAGES/django.po \
| awk 'NF' \
| wc -w
@maxpeterson
maxpeterson / png-to-pdf.sh
Created October 17, 2019 08:40
Convert PNGs to PDFs
#!/usr/local/bin/bash
for filename in *.png; do
convert "$filename" "${filename%.*}.pdf";
done
#!/usr/bin/env python
# -*- python -*-
# Usage: python fake_translate.py inputfile.po outputfile.po
import re
import sys
import polib
python manage.py makemessages --locale=en --no-wrap --ignore='ght' --ignore='locale' --ignore='config' --ignore='working_groups' --ignore='articles' --ignore='node_modules' --ignore='content' --ignore='blog' --ignore='search' --ignore='site_finder' --ignore='_latest' --ignore='users' --ignore='avatar' --ignore='drug_development_process_map' --ignore='site_templates' --ignore='countries' --ignore='apps' --ignore='ght_site' --ignore='process_map' &&\
python fake_translate.py locale/en/LC_MESSAGES/django.po locale/fr/LC_MESSAGES/django.po &&\
python manage.py compilemessages --locale=fr
@maxpeterson
maxpeterson / generate-email-copy.sh
Created January 24, 2019 13:08
Generate the email copy in Confluence Wiki format
rm tmp/*
make test-emails
(for file in tmp/*; do
echo "h3. $(grep Subject $file| cut -c 10-)";
echo;
echo '{quote}';
sed '

Keybase proof

I hereby claim:

  • I am maxpeterson on github.
  • I am maxpeterson (https://keybase.io/maxpeterson) on keybase.
  • I have a public key ASDZ1hI8J-Wm6XJ9YJeCkjeerXJki4iv6nOcmtANj7sQnwo

To claim this, I am signing this object: