Skip to content

Instantly share code, notes, and snippets.

Daniel Serodio dserodio

Block or report user

Report or block dserodio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dserodio
dserodio / aws.sh
Last active Sep 16, 2019
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/
@dserodio
dserodio / git-timestamp.sh
Created Jan 5, 2017 — forked from davidwindell/git-timestamp.sh
Set a files last modified time to match it's git commit timestamp
View git-timestamp.sh
#!/bin/bash -e
####
# based on http://www.clock.co.uk/blog/a-guide-on-how-to-cache-npm-install-with-docker
#
# Set's the last modified timestamp of a file to it's repositories commit timestamp.
#
# Particularly useful with docker when building after a new git checkout has been made,
# can improve docker build times for composer, bower, npm, etc
#
# @see https://github.com/docker/docker/issues/3556
View gist:48635d457e01de3d4134f0dcabc9390b
#!/bin/bash -e
####
# based on https://gist.github.com/jeffery/1115504
# Helper script to update the Last modified timestamp of files in a Git SCM
# Projects working Copy
#
# When you clone a Git repository, it sets the timestamp of all the files to the
# time when you cloned the repository.
#
# This becomes a problem when you want the cloned repository, which is part of a
You can’t perform that action at this time.