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 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 November 6, 2018 11:54
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.

Example

With the given source template:

@magnetikonline
magnetikonline / README.md
Last active May 18, 2018 17:11
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.

Example

Some code:

function myFunction() {
@magnetikonline
magnetikonline / README.md
Last active August 15, 2017 23:00
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.

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 |...|
@magnetikonline
magnetikonline / README.md
Last active March 3, 2025 23:19
Python function - test if given file is considered binary.

Python function - is file binary?

Function which determines if a given file is binary.

Test is based on the following algorithm (similar to that implemented within Perl):

  • Empty files are considered text.
  • If not empty, read up to 512 bytes as a buffer. File will be binary if:
    • Null byte is encountered.
    • More than 30% of the buffer consists of "non text" characters.
@magnetikonline
magnetikonline / example.ps1
Created August 4, 2017 05:28
PowerShell example for an AWS Route53 record upsert.
Set-StrictMode -Version Latest
$HOSTED_ZONE_ID = "ABCDEFGHIJKLM"
$changeRequest01 = New-Object -TypeName Amazon.Route53.Model.Change
$changeRequest01.Action = "UPSERT"
$changeRequest01.ResourceRecordSet = New-Object -TypeName Amazon.Route53.Model.ResourceRecordSet
$changeRequest01.ResourceRecordSet.Name = "record01.domain.com"