Skip to content

Instantly share code, notes, and snippets.

View massenz's full-sized avatar
🏠
Working from home

Marco Massenzio massenz

🏠
Working from home
View GitHub Profile
@massenz
massenz / delete-iam-role
Last active July 25, 2021 20:44
To delete an AWS IAM Role, Policies need to be detached first: this script automates the tedious necessary steps.
#!/usr/bin/env bash
#
set -eu
ROLE=${1:-}
if [[ -z ${ROLE} ]]; then
printf "Usage: delete-iam-role ROLE\n\nERROR: ROLE must be specified\n"
exit 1
fi
@massenz
massenz / ErrorStateMachine.json
Last active April 5, 2023 19:47
Demonstrates how to generate different types of errors for AWS Lambda Step Functions, so that Retry/Catch can distinguish between different kinds of errors.
{
"Comment": "A state machine to experiment with errors",
"StartAt": "Error Handler",
"States": {
"Error Handler": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"Parameters": {
"Payload.$": "$",
@massenz
massenz / UserController.java
Last active August 25, 2021 17:25
OpenAPI Codex-generated Rest Controller for Spring Data
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserRepository userRepository;
@Autowired
private UserService userService;
@massenz
massenz / contains.go
Created March 20, 2022 18:43
Go does not have a built-in `in` operator for slices
package main
import "fmt"
// Tempting, but this will NOT compile
//
//func (arr []interface{}) Has(x interface{}) bool {
// for _, val := range arr {
// if val == x {
// return true
@massenz
massenz / babies.go
Last active March 20, 2022 19:38
Serialize data to/from Redis in a custom type
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/go-redis/redis/v8"
"os"
"time"
)
@massenz
massenz / fizzbuzz.py
Created March 26, 2022 08:02
FizzBuzz in less than 5 minutes, as described at http://codetrips.com
#!/usr/bin/env python
#
# FizzBuzz -- created by M. Massenzio, 2022-03-26
import sys
n = sys.argv[1]
for i in range(3, int(n) + 1):
out = ""
if i % 3 == 0:
@massenz
massenz / snapshot.sh
Created November 3, 2023 06:54
Shell script to archive & encrypt folders
#!/usr/bin/env zsh
#
# Snapshot archive of all contents in the folder defined in a variable
# called $SOURCE, using $TAR_OPTS tar options.
#
# Created MM, 2012-01-21
# Revised MM, 2023-11-03
set -eu
source ${COMMON_UTILS}/utils