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 April 21, 2024 20:08
Install VirtualBox 6.1/6.0/5.2/5.1 guest additions on Ubuntu server guest.

Install VirtualBox guest additions onto Ubuntu server guests

Have tested these steps successfully with Ubuntu guest of:

  • 22.04LTS
  • 18.04LTS
  • 16.04LTS

using VirtualBox editions of 6.1, 6.0, 5.2 and 5.1 as host.

@magnetikonline
magnetikonline / README.md
Last active April 20, 2024 04:18
npm wrapper script to ensure `npm publish` from a clean Git repository.

npm wrapper to ensure npm publish from clean Git repository

Tip

By default npm publish will publish all files within a working directory - excluding .gitignore / .npmignore / package-lock.json.

This is typically fine, but often I find myself leaving un-staged files (e.g. TODO.txt files) in a repository root and these of course get accidently taken along for the publish ride.

Helper script npm-publish-wrap.sh will catch calls to npm publish and:

  • Ensure I'm at the root of a repository (.git directory) found.
@magnetikonline
magnetikonline / README.md
Last active April 19, 2024 19:59
Enable LDAP over SSL (LDAPS) for Microsoft Active Directory servers.

Enable LDAP over SSL (LDAPS) for Microsoft Active Directory servers

Microsoft active directory servers will default to offer LDAP connections over unencrypted connections (boo!).

The steps below will create a new self signed certificate appropriate for use with and thus enabling LDAPS for an AD server. Of course the "self-signed" portion of this guide can be swapped out with a real vendor purchased certificate if required.

Steps have been tested successfully with Windows Server 2012R2, but should work with Windows Server 2008 without modification. Requires a working OpenSSL install (ideally Linux/OSX) and (obviously) a Windows Active Directory server.

@magnetikonline
magnetikonline / dumprequest.php
Last active April 19, 2024 05:50
PHP script to dump full HTTP request to file (method, HTTP headers and body).
<?php
// https://gist.github.com/magnetikonline/650e30e485c0f91f2f40
class DumpHTTPRequestToFile {
public function execute($targetFile) {
$data = sprintf(
"%s %s %s\n\nHTTP headers:\n",
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$_SERVER['SERVER_PROTOCOL']
@magnetikonline
magnetikonline / README.md
Last active April 18, 2024 23:50
Docker volume backup and restore scripts.

Docker volume backup and restore scripts

Backup a Docker volume to tar archive:

$ ./docker-volume-backup.sh \
  DOCKER_VOLUME_NAME \
  ARCHIVE_NAME.tgz
@magnetikonline
magnetikonline / README.md
Last active April 17, 2024 22:49
GitHub Markdown cheatsheet.
@magnetikonline
magnetikonline / README.md
Created April 16, 2024 03:04
Using curl to make an AWS V4 signed request to an AWS_IAM API Gateway endpoint.

Using curl to AWS V4 sign request to AWS_IAM API Gateway endpoint

Small Bash script, calling curl with the --aws-sigv4 option to AWS V4 sign a given request for use with an IAM authorized API Gateway endpoint.

Usage

./aws-api-gateway-iam.sh \
  --request GET \
 "https://api-gateway.mydomain.com/this/route/aws-iam-authz"
@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 March 30, 2024 06:24
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.