Skip to content

Instantly share code, notes, and snippets.

View organom's full-sized avatar
👨‍💻
Fixing the world, one issue at a time

Ricardo Gomes organom

👨‍💻
Fixing the world, one issue at a time
View GitHub Profile
@organom
organom / ListLambdaRuntimesInAllRegions.sh
Last active February 20, 2024 12:18
List all lambdas and its runtimes in all regions for AWS account
#!/bin/bash
for region in `aws ec2 describe-regions --query "Regions[].RegionName" --region us-west-1 --output text`
do
echo "[${region}]"
aws lambda list-functions --region ${region} --output text --query "Functions[].{ARN:FunctionArn, Runtime:Runtime}"
done
@organom
organom / Organize_pictures_in_folder_by_date.sh
Last active April 10, 2024 23:17
Organize pictures in folder by date
# All photos and videos are in a folder, from here on called ORIGINALS
# Parallel command can speed up some tasks, specially the conversion ones, check -j for the number of processes to run in parallel
# Before starting, lets clean temporary files to make sure we dont have to deal with them later
find ORIGINALS -maxdepth 9999 -noleaf -type f \( -iname ".DS_Store" -o -name "._*" -o -iname "thumbs.db" -o -iname ".picasa.ini" \) -exec rm -v "{}" \;
# Before continue, maybe search for some file types for some extra cleanup (for quick cleanup copy the -exec part above)
find ORIGINALS -maxdepth 9999 -noleaf -iregex '.*\.\(exe\|tcb\|tcpmd\|txt\|doc\|docx\|xls\|xlsx\|ptp\|7z\|rar\|zip\|iso\|mp3\|m3u\|amr\|xmp\|epp\|xcf\)$'
@organom
organom / Sequential file renamer in folder
Created January 13, 2024 22:25
Renames files in folder (argument) to a sequantial name (ex: 01.mkv). Improve printf in case more than 100 files are required
!#/bin/bash
cd $1
ls | cat -n | while read n f; do ext=${f##*.}; mv "$f" `printf "%02d.$ext" $n`; done
@organom
organom / tag_with_folder_hierarchy.sh
Last active January 6, 2024 21:42
Tags recursivelly all images with the folder hierarchy as subject (starting from current folder)
for i in *; do echo "== $i"; exiftool "-subject<directory" -overwrite_original -sep "/" -P -r "$i"; echo ""; done;
@organom
organom / git-rename.sh
Created October 4, 2023 18:47
Renames a git branch
!#/bin/bash
function git-rename() {
if [ $# -lt 2 ]
then
echo "Usage: $0 old_branch_name new_branch_name";
else
git branch -m $1 $2
git push origin :$1 $2
fi
@organom
organom / git-reset-and-clean.sh
Created October 4, 2023 18:45
Resets and cleans git changes
!#/bin/bash
function git-reset-and-clean() {
git fetch origin
git reset --hard origin/$(git branch --show-current)
git clean -xdf
}
git-reset-and-clean
@organom
organom / git-branch-cleanup.sh
Created October 4, 2023 18:44
Cleanup all git local branches that are not in remote
!#/bin/bash
function git-branch-cleanup() {
git remote prune origin
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -d
}
git-branch-cleanup
@organom
organom / git-status.sh
Created October 4, 2023 18:43
Recursivelly display the status of all git repositories in a folder
!#/bin/bash
function git-status() {
find . -name .git -type d -exec sh -c '(cd {}; cd ..; git_temp=`git status -s`; if [ -n "${git_temp}" ]; then (echo $PWD && git status -s && echo); fi;)' \;
}
git-status
@organom
organom / aws_remove_s3_buckets.sh
Last active October 4, 2023 18:36
Removes all AWS S3 empty buckets (add --force to remove all even if not empty)
aws s3 ls | cut -d" " -f 3 | xargs -I{} aws s3 rb s3://{}
@organom
organom / aws_test_ebs_creation.ngs
Last active October 4, 2023 18:36
Test volume creation times in AWS (NGS)
#!/usr/bin/env ngs
F ebs(volumeSize: Int) {
volumeId = null
took = time({
volumeId = ``log:'Creating volume' aws ec2 create-volume --availability-zone eu-central-1a --size ${volumeSize}``.VolumeId
retry(
times = 100
sleep = 0