Skip to content

Instantly share code, notes, and snippets.

View massenz's full-sized avatar
💻
Building AI Agents

Marco Massenzio massenz

💻
Building AI Agents
View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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 / 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 / font.py
Last active September 10, 2019 21:06
How to load fonts via Python PIL.
# 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 September 29, 2018 21:37
Kubernetes Minikube install on MacOS
#!/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 September 27, 2018 20:56
MacOS Finder - toggle Hidden Files in Finder
#!/bin/bash
ENABLE=${1:-TRUE}
defaults write com.apple.finder AppleShowAllFiles ${ENABLE}
killall Finder