Skip to content

Instantly share code, notes, and snippets.

View wllmsash's full-sized avatar

Ashley Williams wllmsash

  • Sentiment Search
  • United Kingdom
View GitHub Profile
@wllmsash
wllmsash / uuidv7-get-timestamp.ts
Created October 7, 2023 21:22
UUIDv7 Get Timestamp
import { uuidv7, UUID } from "uuidv7";
const uuid = uuidv7();
const timestampBytes = new Uint8Array(8);
timestampBytes.set(new Uint8Array(UUID.parse(uuid).bytes.buffer.slice(0, 6)), 2);
const timestampMs = new DataView(timestampBytes.buffer).getBigUint64();
console.log(new Date(Number(timestampMs)));
@wllmsash
wllmsash / remove-images-from-docker-registry.sh
Created August 20, 2023 18:31
Remove Images From Docker Registry
echo "Removing images from daemon..."
docker image ls | grep "$IMAGE_NAME" | awk '{print $1":"$2}' | xargs -I {} docker image rm {}
echo "Removed images from daemon."
echo "Pruning images from daemon..."
docker image prune --force
echo "Pruned images from daemon."
echo "Removing images from registry..."
if curl --silent "$DOCKER_REGISTRY_BASE_URL/v2/_catalog" | jq --raw-output '.repositories[]' | grep -q "$IMAGE_NAME"; then
@wllmsash
wllmsash / google-cloud-storage-rotating-backups.sh
Created May 21, 2023 23:42
Google Cloud Storage Rotating Backups
#!/bin/sh
set -e
if test -z "$GOOGLE_CLOUD_STORAGE_BUCKET_URI"; then >&2 echo "GOOGLE_CLOUD_STORAGE_BUCKET_URI not specified, exiting"; exit 1; fi
# In some environments, such as a local development container, it might be necessary to provide the Application Default
# Credentials via the GOOGLE_APPLICATION_CREDENTIALS environment variable.
# The gcloud CLI won't authorize requests using the GOOGLE_APPLICATION_CREDENTIALS environment variable, however it can
# use them to generate an access token. The access token can authorize the gcloud CLI through the
@wllmsash
wllmsash / google-cloud-in-development-environments.md
Created February 11, 2023 16:06
Google Cloud in Development Environments

Google Cloud in Development Environments

Connecting to a Google Cloud VM Behind IAP From a Windows Machine Using a *nix/WSL Development Machine

Establishing an SSH connection transparently is useful for connecting to a Google Cloud VM using the ms-vscode-remote.remote-ssh (Remote - SSH) extension in VSCode, for example, allowing us to avoid manual port-forwarding or setting up a dedicated tunnel.

Requirements

  • An SSH agent must be running on the on the client machine. On Windows, enable and start the OpenSSH Authentication Agent service.
@wllmsash
wllmsash / publish-solution.ps1
Last active September 3, 2021 16:24
Publish a dotnet solution to an output directory
#Requires -Version 7
$configuration = "Release"
$output_directory_name = "publish"
$target_projects = "Project1","Project2","Project3"
$dotnet_version_directory = "netcoreapp3.1"
# Publish a clean build for every project in the solution
dotnet clean --configuration "$configuration"
If ($LastExitCode -ne 0)
@wllmsash
wllmsash / assigning-static-ip-addresses-in-wsl2.md
Last active May 16, 2024 06:21
Assigning Static IP Addresses in WSL2

Assigning Static IP Addresses in WSL2

WSL2 uses Hyper-V for networking. The WSL2 network settings are ephemeral and configured on demand when any WSL2 instance is first started in a Windows session. The configuration is reset on each Windows restart and the IP addresses change each time. The Windows host creates a hidden switch named "WSL" and a network adapter named "WSL" (appears as "vEthernet (WSL)" in the "Network Connections" panel). The Ubuntu instance creates a corresponding network interface named "eth0".

Assigning static IP addresses to the network interfaces on the Windows host or the WSL2 Ubuntu instance enables support for the following scenarios:

@wllmsash
wllmsash / useful-commands.sh
Last active January 1, 2024 11:08
Useful commands
# Show free and used disk space
# -a: Include all non-standard file systems
# -h: Human readable sizes
df -ah
# Show disk usage of a file or directory (recursive)
# -h: Human readable sizes
# -s: Summarize results
du -hs /path/to/directory
@wllmsash
wllmsash / systemd-nvm.md
Created June 30, 2019 19:59
Install a systemd service for a node app using nvm
[Unit]
Description={description}

[Service]
ExecStart=/home/{user}/.nvm/nvm-exec npm start
Restart=always
User=nobody
Group=nogroup
Environment=NODE_VERSION={node-version}