Skip to content

Instantly share code, notes, and snippets.

View fernandoacorreia's full-sized avatar

Fernando Correia fernandoacorreia

View GitHub Profile
@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 git@github.com:jumpstart-pro/jumpstart-pro-rails.git
#!/bin/bash
#
# Outputs JSON paths.
#
# Based on https://news.ycombinator.com/item?id=20264654
#
# Usage:
# curl -s https://raw.githubusercontent.com/sitepoint-editors/json-examples/master/src/db.json | ./jsonpaths
jq -r --stream '
@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 / restore-wallpaper-rights.ps1
Created November 1, 2012 22:43
Windows PowerShell script to restore the right to set your desktop wallpaper when a group policy blocked it.
# Windows PowerShell script to restore the right to set your desktop wallpaper when a group policy blocked it.
# Must be executed as administrator.
# Automates the steps described at http://neuralfibre.com/paul/it/how-to-block-your-corporate-wallpaper-in-windows
Set-StrictMode -Version 2.0
function enable-privilege {
param(
## The privilege to adjust. This set is taken from
@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/