Skip to content

Instantly share code, notes, and snippets.

cloudformation-templates: ## Find all Cloudformation Templates e.g. for yamlint, cfnlint, cfnnag, etc...
@find -E $(CURDIR) \
-regex ".*(yaml|yml|json|template)" \
-not -path "*/node_modules/*" \
-exec grep -il AWSTemplate {} \; \
| grep -v ".aws-sam"
# apologies, forgotten the book I got this from... but very useful :O
# see origin function at https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
dump-var-origin: ## useful for debugging
@$(foreach V,$(sort $(.VARIABLES)), \
$(if $(filter-out environ% default automatic, \
$(origin $V)), $(info $V=$($V) ($(value $V)))))
# Usage - make dump-var-origin
## Dump a prettified version of given var, with a column width of 40,
##e.g.
##
## MY_STACK - micks-stack
## MY_BUCKET - micks-bucket
## nb: 033 is yellow
##
define dump_var
@echo $(1) $(2) | awk -v width=40 '{printf "\033[33m%-*s\033[0m - %s\n", width, $$1, $$2}'
endef
# HELP - will output the help for each task in the Makefile
# In sorted order.
# The width of the first column can be determined by the `width` value passed to awk
#
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html for the initial version.
#
help: ## This help.
@grep -E -h "^[a-zA-Z_-]+:.*?## " $(MAKEFILE_LIST) \
| sort \
| awk -v width=36 'BEGIN {FS = ":.*?## "} {printf "\033[36m%-*s\033[0m %s\n", width, $$1, $$2}'
@micklove
micklove / Makefile
Created February 9, 2020 10:58
make for executing npm scripts
# Use jq to grab the various scripts from package.json and expose them as a make targets
# Based on the awesome script from https://gist.github.com/kvz/79554af7f2d1b1379536
# (but with jq... for something different)
# can use autocomplete (make <TAB><TAB> )
TARGETS:=$(shell jq -r ".scripts | keys | .[]" package.json | sed 's/:/-/g')
define npm_script_targets
$$(TARGETS):
npm run $(subst -,:,$(MAKECMDGOALS))
.PHONY: $$(TARGETS)
@micklove
micklove / gdiff
Created February 9, 2020 02:05
git diff file in column mode
#!/usr/bin/env bash
# diff file at given path to committed version.
# Use colordiff, if installed
# e.g. gdiff my-file.c
PREFERRED_DIFFER="colordiff"
command -v ${PREFERRED_DIFFER} >/dev/null 2>&1 || PREFERRED_DIFFER="diff"
if [[ -z "${1}" ]]; then
@micklove
micklove / cli.md
Last active March 28, 2020 16:06
@micklove
micklove / running-instances-by-tag
Last active July 11, 2018 08:35
Filter ec2 instances by state 'running' and Tag Name / Value
# Add this to your ~/.aws/cli/alias file
#
# rit == (R)unning (I)nstances by (T)ag
# (Name and Value)
#
# Allows users to filter their AWS instances, which are running, by Tag Name / Value and see a summarised view.
#
# Pre-requisite - Expects one tag to be 'Name'
#
# e.g. With 1 Tag Match the Instance tagged with "branch" of "develop"