Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Marco Massenzio massenz

🏠
Working from home
View GitHub Profile
@massenz
massenz / fizzbuzz.py
Created Mar 26, 2022
FizzBuzz in less than 5 minutes, as described at http://codetrips.com
View fizzbuzz.py
#!/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 / babies.go
Last active Mar 20, 2022
Serialize data to/from Redis in a custom type
View babies.go
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/go-redis/redis/v8"
"os"
"time"
)
@massenz
massenz / contains.go
Created Mar 20, 2022
Go does not have a built-in `in` operator for slices
View contains.go
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 / UserController.java
Last active Aug 25, 2021
OpenAPI Codex-generated Rest Controller for Spring Data
View UserController.java
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserRepository userRepository;
@Autowired
private UserService userService;
@massenz
massenz / ErrorStateMachine.json
Last active Aug 19, 2021
Demonstrates how to generate different types of errors for AWS Lambda Step Functions, so that Retry/Catch can distinguish between different kinds of errors.
View ErrorStateMachine.json
{
"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 / delete-iam-role
Last active Jul 25, 2021
To delete an AWS IAM Role, Policies need to be detached first: this script automates the tedious necessary steps.
View delete-iam-role
#!/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 / font.py
Last active Sep 10, 2019
How to load fonts via Python PIL.
View font.py
# How to load fonts via Python PIL.
# See Stack OF question: https://stackoverflow.com/questions/24085996/how-i-can-load-a-font-file-with-pil-imagefont-truetype-without-specifying-the-ab/41887497#41887497
from PIL import Image, ImageDraw, ImageFont
# sample text and font
unicode_text = u"Arial Font, size 28px"
font = ImageFont.truetype("/Library/Fonts/Arial.ttf", 28, encoding="unic")
# get the line size
@massenz
massenz / minikube-install.sh
Created Sep 29, 2018
Kubernetes Minikube install on MacOS
View minikube-install.sh
#!/bin/bash
#
# Installs minikube on MacOS
# See: https://github.com/kubernetes/minikube/releases
declare -r VERSION=${1:-}
if [[ -z ${VERSION} ]]; then
echo "Please specify a version"
exit 1
@massenz
massenz / hiddenToggle
Created Sep 27, 2018
MacOS Finder - toggle Hidden Files in Finder
View hiddenToggle
#!/bin/bash
ENABLE=${1:-TRUE}
defaults write com.apple.finder AppleShowAllFiles ${ENABLE}
killall Finder
@massenz
massenz / install_jdk_10.sh
Last active Dec 12, 2019
Install OpenJDK 10 on MacOS
View install_jdk_10.sh
#!/bin/bash
#
# Installs the OpenJDK 10 from java.net.
VERSION=10.0.2
DOWNLOAD_URL="download.java.net/java/GA/jdk10"
JDK="openjdk-${VERSION}_osx-x64_bin.tar.gz"
INSTALL_DIR="/Library/Java/JavaVirtualMachines"
wget https://${DOWNLOAD_URL}/${VERSION}/19aef61b38124481863b1413dce1855f/13/${JDK} -O /tmp/${JDK}