Skip to content

Instantly share code, notes, and snippets.

View magnetikonline's full-sized avatar
💡
I have an idea!

Peter Mescalchin magnetikonline

💡
I have an idea!
View GitHub Profile
@magnetikonline
magnetikonline / README.md
Last active October 27, 2020 02:56
Gmail message retention/purge by label Google script.

Gmail retention/purge by label Google script

A Google Apps Script which adds pseudo message retention-like policies against specific labels for a Gmail account.

How it works

  • Apps Script function is called automatically on a regular schedule.
  • Script iterates over a set of predefined message labels.
@magnetikonline
magnetikonline / README.md
Last active March 14, 2025 10:02
Add user ssh-agent as daemon to Ubuntu 18.04LTS server.

Add user ssh-agent as daemon to Ubuntu 18.04LTS server

Create a new systemd user unit, which starts ssh-agent upon login to server. Will remain resident until the final session for the user has logged out.

Steps

  • Create /etc/systemd/user/ssh-agent.service.

  • Run the following commands (under your user account, not root) to install the systemd unit and start:

@magnetikonline
magnetikonline / README.md
Last active August 28, 2018 00:03
Bash shift quirks.

Bash shift quirks

When using the shift built-in, have noted this interesting behavior which I have been unable to find documentation for.

Update: the answer was right in front of me, if shift is called with a value greater than arguments available in $1 - $x then it will return with a non zero status - hence the script will halt (since I'm using set -e)!

Using the script test.sh, executed using arguments:

./test.sh apple orange banana
apple
@magnetikonline
magnetikonline / README.md
Last active September 16, 2024 14:23
CloudFormation API Gateway endpoint calling a Lambda function using proxy integration example.

CloudFormation API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway:
    • Deployed as a REGIONAL endpoint.
    • Single root method, accepting POST requests only, with Lambda proxy integration to a target function.
  • In-line Python Lambda function echoing back requesting users IP address to API Gateway requests:
    • IAM role for Lambda allowing CloudWatch logs access.
    • Permissions for Lambda that allow API Gateway endpoint to successfully invoke function.
@magnetikonline
magnetikonline / README.md
Last active October 19, 2023 11:22
List AWS AMI IDs for a given marketplace product URL.

List AWS AMI IDs for a given marketplace product

Script to return AMI IDs for a given AWS region associated to a marketplace product page. Requires AWS CLI and a valid set of credentials for the aws ec2 describe-images call.

Usage

  • Browse the AWS marketplace to locate the product of interest.
  • Note the URL of the product page.
  • Execute script for the desired region:
@magnetikonline
magnetikonline / README.md
Last active January 1, 2023 22:00
Extract all files at every commit of a Git repository.

Extract all files at every commit of a Git repository

Bash script to iterate all commits of a given Git repository and extract all files within each commit.

Example

With a Git repository at /path/to/repository and an empty directory at /path/to/output we can run:

./export.sh /path/to/repository /path/to/output
@magnetikonline
magnetikonline / README.md
Last active September 25, 2023 13:57
AWS CloudFormation YAML template - appending to list parameter types.

AWS CloudFormation YAML template - appending to list parameter types

Documenting this here, as I often forget (what I have found) is the best way to do this at the moment.

For example, you have a list of two existing security groups given to a stack and wish to create (and use) a third - attaching all to an ALB:

AWSTemplateFormatVersion: '2010-09-09'
Description: Example template
@magnetikonline
magnetikonline / README.md
Last active November 24, 2024 15:55
Bash getopt long options with values usage example.

Bash getopt long options with values usage example

#!/bin/bash -e

ARGUMENT_LIST=(
  "arg-one"
  "arg-two"
  "arg-three"
)
@magnetikonline
magnetikonline / README.md
Last active October 31, 2024 10:20
Bash array usage cheatsheet.