Skip to content

Instantly share code, notes, and snippets.

@aleixripoll
aleixripoll / p12-cert.md
Created February 6, 2017 15:19
Strip p12 certificates

Split into certs and unencrypted keys:

openssl pkcs12 -in cert.p12 -nocerts -out cert.p12.enc_keys
openssl pkcs12 -in cert.p12 -clcerts -nokeys -out cert.p12.certs
openssl rsa -in cert.p12.enc_keys -out cert.p12.keys

Check expiry date:

# openssl x509 -enddate -noout -in key.pem
@aleixripoll
aleixripoll / git-ref.md
Last active March 3, 2017 10:27
Git reference

LIST BRANCHES

REMOTE: git remote show origin
LOCAL: git branch

SET USERNAME

git config credential.https://github.com/<org>/repo.git.username <username>

MERGE/REBASE branch-1 => branch-2

@aleixripoll
aleixripoll / mem-usage.md
Last active February 6, 2017 14:47
Linux mem usage one-liners

Processes ordered by mem usage in MB:

ps -u $USER -wo rss=,comm= --sort -rss | while read -r rss comm ; do echo $((rss/1024))"MB" $comm; done

Mem used by a process regex in KB:

ps -e -www -o pid,ppid,start_time,pmem,rsz,cmd | grep "<command>" | sort -n -k3 | awk '{print $5"KB RAM |",$6,$7,$8,$9,$10,$11; SUM+=$5} END  {print "Total RAM: "SUM" KB"}'
@aleixripoll
aleixripoll / ansible-tips.md
Last active April 1, 2017 10:46
Ansible tips

Playbook useful switches:

ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml

-C check_mode
-D show file diffs

Ad-hoc commands:

@aleixripoll
aleixripoll / list-aws-instances.md
Last active February 6, 2017 13:05
List AWS instances

Print name for running instances; cheap grep filter

aws ec2 describe-instances --output text --filters Name=instance-state-name,Values=running | grep Name | cut -f3 | sort -n

Print id, name, private ip, public ip; with column-formatting

aws ec2 describe-instances --output text --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' | sort -k 2 | column -t