Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Serodio dserodio

View GitHub Profile
View collapse_all_files_in_diff.js
// https://github.com/isaacs/github/issues/514#issuecomment-408216389
Array.from(document.getElementsByClassName('js-details-target')).forEach(function(element){element.click()})
View interrupt.py
"""Handle SIGINT (aka Ctrl+C)"""
import sys
import signal
signal.signal(signal.SIGINT, lambda signal_number, current_stack_frame: sys.exit(1))
@dserodio
dserodio / aws.sh
Last active Sep 16, 2020
AWS snippets
View aws.sh
# 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 Jun 26, 2018
Get EC2 instance tags
View get-tags.sh
# 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 May 23, 2018
Template for creating shell scripts in Bash
View script.sh
#!/bin/bash
# "Bash strict mode" (see http://redsymbol.net/articles/unofficial-bash-strict-mode/)
set -euo pipefail
IFS=$'\n\t'
@dserodio
dserodio / snippets.sh
Last active Jul 23, 2018
apt and dpkg snippets
View snippets.sh
# 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)
View install_phpbrew.md

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
@dserodio
dserodio / root.sh
Last active Nov 29, 2018
Ensure that a script is executed as root
View root.sh
#!/bin/bash
if [[ "$(id -u)" -ne 0 ]]; then
sudo "$0" "$@"
exit $?
fi
@dserodio
dserodio / cleanup.sh
Created Apr 24, 2017
Cleanup temp files on Bash scripts
View cleanup.sh
#!/bin/bash
function cleanup() {
# Your cleanup code here
}
trap cleanup EXIT
# See http://redsymbol.net/articles/bash-exit-traps/
You can’t perform that action at this time.