Skip to content

Instantly share code, notes, and snippets.

View fernandoacorreia's full-sized avatar

Fernando Correia fernandoacorreia

  • San Francisco, CA
  • 10:30 (UTC -08:00)
View GitHub Profile
@fernandoacorreia
fernandoacorreia / log-pod.sh
Last active June 6, 2024 13:59
Log Kubernetes pod
#!/bin/bash
#
# Saves logs for all containers in a pod.
#
set -o nounset -o errexit -o pipefail
# Function to print the usage
usage() {
echo "Usage: $0 [-n namespace] <pod-name>"
exit 1
@fernandoacorreia
fernandoacorreia / set-mitmproxy.sh
Last active April 15, 2024 23:27
Add mitmproxy sidecar
#!/bin/bash
#
# Adds a sidecar container running mitmproxy to a deployment resource.
# See https://mitmproxy.org
#
# The goal is to make it easier to inspect service-to-service HTTP requests in a dev, staging or QA environment.
#
# Not recommended for production usage since it can reveal secrets and it is an actual man-in-the-middle
# (https://owasp.org/www-community/attacks/Manipulator-in-the-middle_attack).
#
@fernandoacorreia
fernandoacorreia / rails-cheat-sheet.md
Last active September 30, 2023 22:53
Ruby on Rails cheat sheet

Ruby on Rails cheat sheet

Creating apps

Creating a new app from Jumpstart Pro Rails Template:

take my_app
git init
git remote add upstream [email protected]:jumpstart-pro/jumpstart-pro-rails.git
@fernandoacorreia
fernandoacorreia / backup
Created March 2, 2023 18:26
Backup Mac to Google Drive
#!/bin/bash
#
# Backs up local folders to Google Drive.
#
# Run from a cron job script: ~/bin/backup-job
#
set -o nounset -o errexit -o pipefail
BACKUP_DIR="/Users/fernando.correia/Google Drive/My Drive/Backup"
@fernandoacorreia
fernandoacorreia / wait_for_200.sh
Created May 5, 2021 17:28
Wait for HTTP 200 status code
declare http_code
until [[ $http_code -eq 200 ]]; do
login_url="$HOST/login"
http_code=$(curl -I $login_url -o /dev/null -w '%{http_code}' -s)
if [[ $http_code -ne 200 ]]; then
echo "$login_url returned status code $http_code, sleeping for 10 secs"
sleep 10
fi
done
brew install libpq

gem install pg -v '1.2.3' --source 'https://rubygems.org/' -- --with-pg-config=/opt/homebrew/Cellar/libpq/13.2/bin/pg_config
@fernandoacorreia
fernandoacorreia / rsync-example.sh
Created February 24, 2021 18:32
rsync example
#!/bin/bash
#
# Copies changed files to a remote server except the .git directory.
#
rsync -razvhPu -e ssh --exclude '.git' ~/Projects/forge fernando-box:/home/fedora
@fernandoacorreia
fernandoacorreia / script-template.sh
Created December 15, 2020 22:01 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@fernandoacorreia
fernandoacorreia / kubectl-install.sh
Last active April 16, 2020 23:48
Install kubectl on Linux
#!/bin/bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
@fernandoacorreia
fernandoacorreia / run-notebook.sh
Created February 20, 2020 19:32
Runs Jupyter scipy-notebook in a container
#!/bin/bash
docker run -p 8888:8888 -v $(pwd):/home/jovyan/host jupyter/scipy-notebook