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 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"
@magnetikonline
magnetikonline / README.md
Last active December 16, 2019 01:09
JavaScript implementation of binary insertion sort.
@magnetikonline
magnetikonline / README.md
Last active March 25, 2024 12:48
Linux umask table.

Linux umask table

Umask is determined by subtracting (binary NOT) from the initial masks of:

  • File: 666 rw-rw-rw
  • Directory: 777 rwxrwxrwx

Therefore:

| Umask | File result | Directory result |

@magnetikonline
magnetikonline / README.md
Last active January 29, 2024 23:26
An example of recursion with Promises - reading recursive directories.

An example of recursion with Promises

A pattern for recursion with Promises - in this example, walking a directory structure.

Function flow

  • readDirRecursive() is called with a starting directory and will itself return a Promise.
  • Internally readDir() is called and passed starting directory to read from.
  • A list of directory items is returned by getItemList() as a Promise, which in turn is chained to getItemListStat() to stat each item to determine if file or directory.
  • Finalised list then passed to processItemList():
@magnetikonline
magnetikonline / README.md
Last active April 7, 2024 23:38
Bash internal field separator (IFS) usage.

Bash internal field separator (IFS) usage

The IFS internal variable is used to determine what characters Bash defines as word/item boundaries when processing character strings. By default set to whitespace characters of space, tab, and newline.

Running the example ifs.sh, comparing the difference between the default and setting only newline as a boundary we get the following output:

/path/to/first
file
/path/to/second
@magnetikonline
magnetikonline / README.md
Last active July 3, 2026 06:09
Install Git on macOS from source.

Install Git on macOS from source

A quick n' dirty Bash script to install the following:

  • autoconf, needed by Git configure.
  • git - from source.

Tested successfully under both Intel and M1 (ARM64) based architectures.

Requires as a minimum Xcode CLI tools (no need for a full install). Can be installed via the following:

@magnetikonline
magnetikonline / README.md
Last active March 5, 2017 23:31
NetScaler rewrite action to update a cookie key value.

NetScaler rewrite action to update a cookie key value

Making a note of this because NetScalers at just awful at anything when it comes to messing with HTTP header cookie values.

So I wish to update the value of a Cookie key of mykey= to mykey=new_value. I can do so with the following rewrite action:

  • Type: REPLACE

  • Expression to choose target location: HTTP.REQ.HEADER("Cookie")

  • Expression: