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
magnetikonline / README.md
Last active Oct 28, 2019
CloudFormation example for an API Gateway endpoint calling a Lambda function using proxy integration.
View README.md

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
magnetikonline / README.md
Last active Feb 7, 2019
List AWS AMI IDs for a given marketplace product.
View README.md

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:

     $ ./listmarketplaceami.sh ap-southeast-2 "https://aws.amazon.com/marketplace/pp/B00UU272MM"
@magnetikonline
magnetikonline / README.md
Last active Oct 9, 2018
Extract all files at every commit of a Git repository.
View README.md

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

Export 1d9048853b8073e43e43e3250300a82f93d2f431 -> /path/to/output/1d9048853b8073e43e43e3250300a82f93d2f431
@magnetikonline
magnetikonline / README.md
Last active Oct 28, 2019
AWS CloudFormation YAML template - appending to list parameter types.
View README.md

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"

Parameters:
@magnetikonline
magnetikonline / README.md
Last active Oct 30, 2019
Bash getopt long options with values usage example.
View README.md

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 Nov 6, 2018
Bash file templating function.
View README.md

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.

Example

With the given source template:

@magnetikonline
magnetikonline / README.md
Last active May 18, 2018
PowerShell calling a function quirk.
View README.md

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.

Example

Some code:

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

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.

Examples

# 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.