Skip to content

Instantly share code, notes, and snippets.

Travelling 🌴

Peter Mescalchin magnetikonline

Travelling 🌴
Block or report user

Report or block magnetikonline

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
magnetikonline /
Last active Oct 28, 2019
CloudFormation example for an API Gateway endpoint calling a Lambda function using proxy integration.

CloudFormation example for API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway endpoint:
    • A single root method, accepting POST requests only with Lambda proxy integration to a function.
  • In-line 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.
  • CloudWatch logs group for Lambda, with 90 day log retention.

After standing up the template, you should be able to curl a POST request to the URL listed as the apiGatewayInvokeURL output value.

magnetikonline /
Last active Feb 7, 2019
List AWS AMI IDs for a given marketplace product.

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.


  • Browse the AWS marketplace to locate the product of interest.

  • Note the URL of the product page.

  • Execute script for the desired region:

     $ ./ ap-southeast-2 ""
magnetikonline /
Last active Oct 9, 2018
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.


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

./ /path/to/repository /path/to/output

Export 1d9048853b8073e43e43e3250300a82f93d2f431 -> /path/to/output/1d9048853b8073e43e43e3250300a82f93d2f431
magnetikonline /
Last active Oct 28, 2019
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 /
Last active Oct 30, 2019
Bash getopt long options with values usage example.

Bash getopt long options with values usage example

#!/bin/bash -e

magnetikonline /
Last active Nov 6, 2018
Bash file templating function.

File templating with Bash

Performs the application of given key/value pairs to a source template, with generated results written to an output file.

Functions applyTemplate accepts three arguments:

  • Source template file.
  • Target output file generated.
  • List of key/value pairs as an array.


With the given source template:

magnetikonline /
Last active May 18, 2018
PowerShell calling a function quirk.

PowerShell calling a function quirk

Something that trips me up often and a handy note to others. When calling a PowerShell function and storing the returned value, all output and the return value will be stored.


Some code:

function myFunction() {
magnetikonline /
Last active Aug 15, 2017
Unicode and the Byte order mark (BOM).

Unicode and the Byte order mark (BOM)

The byte order mark (BOM) is a Unicode character(U+FEFF) at the start of a text stream/file to signify the endianness and encoding used to a high level of confidence.


# utf-8
$ hexdump -C utf-8-bom.txt
00000000  ef bb bf 54 65 73 74 20  73 74 72 69 6e 67 20 e2  |...Test string .|
00000010  98 ba 0a                                          |...|
You can’t perform that action at this time.