#Snippets

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

#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 →