Skip to content

Instantly share code, notes, and snippets.

@s1moe2
s1moe2 / delete_repo.sh
Created July 28, 2025 15:36
Stale branch cleanup script
#!/bin/bash
# Script to delete merged remote branches except those in the no-delete list
# Usage:
# ./delete_merged_git.sh [target-branch] [--delete] [--old-days N]
# Default target branch is "develop"
# Use --delete to actually delete branches; otherwise it's a dry run
# Use --old-days N to also delete branches older than N days
@s1moe2
s1moe2 / IAMRoleManager.json
Created March 28, 2025 11:02
IAMRolePolicyManager
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:DeleteRole",
"iam:UpdateRole",
"iam:GetRole",
@s1moe2
s1moe2 / bresenham.go
Last active May 25, 2022 14:20
Golang implementation of Bresenham's line algorithm
package main
import (
"fmt"
"math"
"os"
"strconv"
)
func main() {
@s1moe2
s1moe2 / test.sh
Created April 23, 2022 14:29
Run Go tests in ephemeral Docker container
docker run --rm \
--name test-acme \
-v "$(pwd)":/usr/app \
golang:1.18 \
bash -c "cd /usr/app && go test -v ./..."
@s1moe2
s1moe2 / pool.yaml
Created February 4, 2022 11:05
CloudFormation - user pool & client setup sample
AWSTemplateFormatVersion: 2010-09-09
Parameters:
PoolName:
Type: String
PoolClientName:
Type: string
Resources:
Pool:
@s1moe2
s1moe2 / index.js
Created November 26, 2021 15:57
Basic usage of sessions in Express.js
const express = require("express")
const sessions = require("express-session")
const FileStore = require("session-file-store")(sessions)
const app = express()
app.use(sessions({
secret: "whatasecret",
saveUninitialized: false,
resave: false,
store: new FileStore({}),
@s1moe2
s1moe2 / replaceLines.go
Created March 21, 2021 18:03
Replace lines that start with a prefix in a file
func replaceImageInTemplate(filepath string, prefix string, newString string) error {
input, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
r, err := regexp.Compile(fmt.Sprintf("(?m)^%s(.*?)$", prefix))
if err != nil {
return err
}
@s1moe2
s1moe2 / replace.go
Created March 21, 2021 16:57
Replace placeholders in text file with Go
func ReplaceInTemplate(filepath string, origString string, replaceString string) error {
input, err := ioutil.ReadFile(filepath)
if err != nil {
return err
}
output := bytes.Replace(input, []byte(origString), []byte(replaceString), -1)
if err = ioutil.WriteFile(filepath, output, 0666); err != nil {
return err
@s1moe2
s1moe2 / removeFiles.go
Created March 21, 2021 16:57
Remove all files/directories from a directory 'dir'
func RemoveFiles(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
@s1moe2
s1moe2 / findTag.go
Created February 9, 2021 16:51
Find commit hash tag by "latest" tag on same image
package main
import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"net/http"
"os"