#Snippets

Read more →
Section break
Read more →
Section break
Read more →
Section break
October 30, 2022

#Emulate the x86_64 architecture for development environments on an Apple M1

First, let’s clarify some terminology. The terms x86, x86_64, x64, and amd64 often refer to the same common Intel-based architecture found in most PCs and servers. In the same vein, the architecture used in Apple M1 processors may be referred to as ARM, ARM64, ARMv8 64, or aarch64. It can be confusing, but these terms are often used interchangeably.

Read more →
Section break
October 23, 2022

#Create a Docker image from scratch using an OS as base

For this example, we will use Raspberry Pi OS 64-bit as the base filesystem for our new Docker image. Since this operating system lacks an official image on Docker Hub, it is a good candidate. However, the principles described here apply to any OS.

Read more →
Section break
October 12, 2022

#Troubleshoot CORS related issues on API requests

Cross Origin Resource Sharing (a.k.a. CORS) is a powerful, and yet misunderstood, web standard for protecting web APIs from abuse. If you’re anything like me, however, you had your fair share of wasted work hours trying to deal with it from time to time. The concept seems deceptively simple, but the devil is in the details.

Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
November 24, 2021

#Pull and push container images from and to AWS ECR repositories via Docker CLI

To use the regular Docker CLI with Amazon Elastic Container Registry (Amazon ECR), you have to acquire specific login credentials for it first. Assuming you already got basic AWS credentials, run the following to pass those on to Docker. Just note that, below, AWS_ACCOUNT_ID refers to the repository owner, which may not be your own AWS account.

Read more →
Section break
November 14, 2020

#Get a Docker container's IP from the command line

When dealing with container IPs, it is important to note which network each container is connected to and which network mode it is using. The default network mode for a Docker installation is bridge, so we will assume you are using it.

Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
August 26, 2020

#Combine kubectl and JSONPath to read data from a Kubernetes cluster

To customize how data about cluster objects is presented in the terminal, it is possible to use JSONPath syntax. Keep in mind that, under the hood, Kubernetes’ API already sends and receives data in JSON format (the YAML files we are used to seeing are an abstraction to ease reading and editing).

Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
Read more →
Section break
March 02, 2020

#Format a new SSD/HD drive for use

# Create the partition
parted --align optimal <raw_device>
mklabel msdos
mkpart primary ext4 0% 100%
quit

# Get the new partition device path
lsblk

# Make the filesystem
mkfs.ext4 <new_partition_device_path>

# Test the partition
mkdir /tmp/partition-test
mount -t ext4 <new_partition_device_path> /tmp/partition-test

# Get the UUID
blkid

# Edit /etc/fstab to mount the partition during boot
UUID=<uuid>     /storage        ext4    defaults,discard        0       2
## OR, if using XFS
UUID=<uuid>     /storage       xfs     defaults        1       2

Read more →
Section break
March 01, 2020 (updated at: December 17, 2024)

#Basic shortcuts for navigating the psql command line (PostgreSQL)

psql -h $POSTGRES_HOST -U $POSTGRES_USER $POSTGRES_DB
\du  # list all users
\l  # list databases
\c  # select a database
\d  # list tables
\d+ <table_name>  # describe table
\dx  # list installed extensions
SELECT * FROM pg_available_extensions;  # list extensions available on the server
CREATE EXTENSION IF NOT EXISTS <ext_name>;  # install an extension
ALTER EXTENSION <ext_name> UPDATE TO 'new_version';  # upgrade an extension

Read more →
Section break
July 01, 2019

#Dump and restore data from MongoDB in Docker

# Create the database dump on your server
docker exec <my_mongodb_container> mongodump --archive=/backups/mongodb-`date +%Y%m%d`.gz --gzip --db <database_name>

# Copy it to your local machine, if needed
scp -r <server_user>@<server_ip>:<remote_backup_path> <local_backup_path>

# Restore it directly into a running Docker container
zcat <backup_path> | docker exec -i <my_mongodb_container> mongorestore --archive --drop

Read more →
Section break
Read more →
Section break
Read more →
Section break
September 01, 2017

#Some useful Vagrant commands

# Bring up the system
vagrant up

# Get into the running virtual machine
vagrant ssh

# Bring the machine down and up again
# (equivalent of running a halt followed by an up)
vagrant reload

# Destroy the current created virtual machines
vagrant destroy

Read more →