Skip to content

Instantly share code, notes, and snippets.

View Aurora12's full-sized avatar
🔥
burning with the fires of Orc

Michael A. Aurora12

🔥
burning with the fires of Orc
  • @worldr
  • London, UK
View GitHub Profile
@Aurora12
Aurora12 / show-listen-ports.md
Last active December 1, 2021 12:33
Bash commands to show open TCP listening ports
# Debian
# Without sudo won't show pids and process names
sudo netstat -tlpn|grep LISTEN

# macOS
# Increase +c for better names visibility
# Without sudo only shows processes of the current user
sudo lsof -i -nP +c 30|grep LISTEN
@Aurora12
Aurora12 / git-latest-unpushed.md
Last active December 1, 2021 12:36
Git: undo latest unpushed commit
@Aurora12
Aurora12 / pg.sql
Last active February 23, 2021 10:40
Convert numeric date to human-readable string in PostgreSQL
to_timestamp(timestamp_in_milliseconds::numeric/1000)
@Aurora12
Aurora12 / get-db.sh
Last active March 30, 2023 13:07
Get PostgreSQL database dump from a kubernetes cluster running in Google Cloud
```bash
# Get credentials from GCP
gcloud container clusters get-credentials $CLUSTER --zone $ZONE --project $PROJECT
echo Current context: $(kubectl config current-context)
SOURCE="<POD>:/tmp/dump.sql"
TARGET="./$CLUSTER.dump.compressed.sql"
# Create a dump inside a container running in k8s
kubectl exec -n $NAMESPACE --stdin --tty $POD -c $CONTAINER -- pg_dump -f /tmp/dump.sql -F c -Z 9 -U <USER> <DATABSE>
@Aurora12
Aurora12 / basic_email_validation.go
Last active March 13, 2023 15:24
*Basic* email validation in Golang
import (
"regexp"
)
// The original W3C email regular expression taken from:
// https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email)
// It is modified to include a domain zone at the end (in JavaScript it works fine without modifications).
// This expression doesn't support addresses with UTF characters.
var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\\.[a-zA-Z]{2,}$")
@Aurora12
Aurora12 / docker-pg-dump.md
Last active December 1, 2021 12:37
Dump a PostgreSQL database running in a Docker container

Bash to a running docker container, dump Postrgres, copy the dump from the container, restore it to a local db.

# Get the name of the container
docker ps

# Bash to it
docker exec -it <DB CONTAINER NAME> /bin/bash

# Create a compressed dump
@Aurora12
Aurora12 / do-setup.md
Last active December 1, 2021 12:58
Setup DigitalOcean

Steps

  1. Dependencies
  2. Firewall
  3. Sudo user
  4. Ssh key
  5. Nginx
  6. DNS
  7. LetsEncrypt certificate
  8. Nginx configuration
@Aurora12
Aurora12 / change-node.md
Last active December 1, 2021 12:56
Change Node version on macOS

Switching between Node.js version on macOS and pinning the one installed.

# Node 12 -> 14
brew unpin node@12
brew uninstall --force --ignore-dependencies node
brew install node@14
brew pin node@14

# Node 14 -&gt; 12
@Aurora12
Aurora12 / mac-tar.md
Last active April 21, 2023 12:37
Tar/Zip without macOS rubbish

TAR

--disable-copyfile stops AppleDouble ._ files with extended OS info from being tarred.

tar --disable-copyfile -cvzf ./target.tar.gz ./something

ZIP

@Aurora12
Aurora12 / 0-get-context.sh
Last active November 12, 2021 11:19
Get context with K8s and GCP
gcloud container clusters get-credentials $CLUSTER --zone europe-west2-a --project $PROJECT
kubectl config get-clusters
echo Current context: $(kubectl config current-context)
kubectl get ns