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 / test-psql-connectivity.sh
Last active Sep 18, 2019
Useful for testing downtime while applying modifications in RDS
View test-psql-connectivity.sh
while true; do
date -Isec | sed -e 's/+00:00//' | tr '\n' ' '
pg_isready -h YOUR_RDS_INSTANCE.rds.amazonaws.com -U USER -d DB_NAME
sleep 1
done | tee connection-test-$(date -Imin).log
@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 / history.sh
Last active Sep 13, 2019
Misc bash snippets
View history.sh
# Show timestamp for history output
export HISTTIMEFORMAT="%d/%m/%y %T "
View rename_lambda_tags.py
"""Replace 'name' tag with 'Name' and 'application' with 'Application'
"""
import boto3
def uppercaseTagKeys(arn, name, application=None):
tags = {}
if name:
tags['Name'] = name
@dserodio
dserodio / Dockerfile
Last active Apr 12, 2019
Dockerfile for multi-stage build of a Ruby app which needs Node at build time (credits: https://github.com/gomex)
View Dockerfile
# Dockerfile for a multi-stage build of a Ruby app which needs Node at build time
#
# Thanks to https://github.com/gomex for sharing
FROM ruby:2.5.1 as builder
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - &&\
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
@dserodio
dserodio / git-tips.md
Last active Dec 17, 2018
Some git tips
View git-tips.md

Don't blame people for changing whitespaces or moving code

git blame will show the author of the last commit that modified the particular line. If whitespaces were removed or that piece of code was moved around, blame will show that commit and you might blame the wrong person.

git blame -w -M

-w will ignore whitespaces and -M will detect moved or copied lines.

Source: https://coderwall.com/p/x8xbnq/git-don-t-blame-people-for-changing-whitespaces-or-moving-code

@dserodio
dserodio / wait_for_line_in_log.sh
Last active Nov 29, 2018
Wait for some text in a log file
View wait_for_line_in_log.sh
{ tail -n +1 -f file.log & } | sed -n '/Initialization finished/q'
@dserodio
dserodio / test_trap.sh
Created Apr 22, 2016
Bash script which traps some signals and prints the name of the received signal
View test_trap.sh
#!/bin/bash
#
# http://stackoverflow.com/a/9256709/31493
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig" "$sig"
done
}
@dserodio
dserodio / scrap.sh
Last active Nov 29, 2018
ps(1) tips and tricks
View scrap.sh
# show process start time for a give PID (GNU ps)
ps -o lstart= -p $PID
# show process start time for all processes (GNU ps)
ps ax -O lstart
# show process environment variables (BSD grep)
ps -Eww -p $PID
@dserodio
dserodio / date.py
Last active Nov 29, 2018
Python snippets
View date.py
# 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)
You can’t perform that action at this time.