#Snippets

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

#How to emulate the x86_64 architecture for development environments on an Apple M1

First of all, let’s get some terminology out of the way. In the wild, the terms x86, x86_64, x64, and amd64 can be used to refer to the same very common Intel-based architecture we find on most PCs and servers. In the same vein, the architecture used on Apple M1 processors may be referred to as ARM, ARM64, ARMv8 64, and aarch64. It’s kind of a mess, but don’t think too much about it. Just remember the names.

Read more →
Section break
October 23, 2022

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

For the purposes of this example, we’ll be using Raspberry Pi OS 64-bit as the base filesystem for our new Docker image. Since this operating system lacks an official one on Docker Hub, it feels like a good fit. However, the principles described here should work well enough for 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’s important to take note of which network each container is connected to and which network mode it’s using. The default network mode for a Docker installation is bridge, so I’ll assume you’re using it too.

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
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 usage

# 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 the /etc/fstab to mount 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 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 →