Skip to content

Instantly share code, notes, and snippets.

View dserodio's full-sized avatar
🐕

Daniel Serodio dserodio

🐕
View GitHub Profile
@dserodio
dserodio / history.sh
Last active January 11, 2023 13:34
Misc bash snippets
# Show timestamp for history output
export HISTTIMEFORMAT="%d/%m/%y %T "
@dserodio
dserodio / README.md
Created September 24, 2018 21:06
Config. AWS PostgreSQL RDS to use pgbadger

Set the following properties in RDS:

log_min_duration_statement = 250
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
log_autovacuum_min_duration = 0
@dserodio
dserodio / dropdown.md
Created August 9, 2018 16:57 — forked from citrusui/dropdown.md
"Dropdowns" in Markdown
How do I dropdown?
This is how you dropdown.

<details>
<summary>How do I dropdown?</summary>
<br>
This is how you dropdown.
// https://github.com/isaacs/github/issues/514#issuecomment-408216389
Array.from(document.getElementsByClassName('js-details-target')).forEach(function(element){element.click()})
@dserodio
dserodio / date.py
Last active February 27, 2023 17:29
Python snippets
# Parse date
# $ pip install python-dateutil
from dateutil import parser
begin = parser.parse("Aug 28 1999 12:00AM")
end = parser.parse("2013-09-11")
# Print duration
delta = end - begin
print str(delta)
@dserodio
dserodio / aws.sh
Last active June 21, 2022 17:50
AWS snippets
# find the owner of an AWS access key
# https://stackoverflow.com/a/31275655
for user in $(aws iam list-users --output text | awk '{print $NF}'); do
aws iam list-access-keys --user $user --output text
done
# alternative that uses jq(1) insteaed of awk(1)
for user in $(aws iam list-users --query 'Users[*].UserName' --output text); do
@dserodio
dserodio / get-tags.sh
Created June 26, 2018 22:31
Get EC2 instance tags
# See https://stackoverflow.com/a/24549602/31493 and
# https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-tags.html
TAG_NAME="Name"
INSTANCE_ID=$(wget -qO- http://instance-data/latest/meta-data/instance-id)
REGION=$(wget -qO- http://instance-data/latest/meta-data/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:')
TAG_VALUE="`aws ec2 describe-tags --filters "Name=resource-id,Values=$INSTANCE_ID" "Name=key,Values=$TAG_NAME" --region $REGION --output=text | cut -f5`"
@dserodio
dserodio / script.sh
Last active January 11, 2024 22:14
Template for creating shell scripts in Bash
#!/bin/bash
# "Bash strict mode" (see http://redsymbol.net/articles/unofficial-bash-strict-mode/)
set -euo pipefail
IFS=$'\n\t'
# Improved "strict mode" (see https://olivergondza.github.io/2019/10/01/bash-strict-mode.html)
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
debug() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
@dserodio
dserodio / snippets.sh
Last active July 23, 2018 13:24
apt and dpkg snippets
# which package owns a file
dpkg-query -S /path/to/file
# list files in an installed package
dpkg-query -L $PACKAGE
# list files in a deb file
dpkg-deb -c <package_name.deb>
# see also apt-file(1)
@dserodio
dserodio / install_phpbrew.md
Last active November 29, 2018 15:23
Using phpbrew

Install phpbrew

# Download phpbrew
cd ~/.local/bin
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew

# Install PHP build dependencies
sudo apt install libssl-dev libbz2-dev libcurl4-openssl-dev