Skip to content

Instantly share code, notes, and snippets.

View nashjain's full-sized avatar
🎯
Focusing

Naresh Jain nashjain

🎯
Focusing
View GitHub Profile
@nashjain
nashjain / delete_all_aws_s3_object_versions.sh
Last active July 25, 2022 21:09
Let's assume you backup a file every hour on AWS S3 and you want to clean up versions that are older than a week. However for the older versions, you want to leave one version per day just in case if you need them. Following script does that for you.
#!/bin/bash
deleteBefore=`date --date="1 week ago" +%F`
bucket=$1
fileToDelete=$2
fileName='aws_delete.json'
rm $fileName
echo "Removing all versions of $fileToDelete from $bucket"
versionsToDelete=`aws s3api list-object-versions --bucket "$bucket" --prefix "$fileToDelete" --query "Versions[?(LastModified<'$deleteBefore' && (contains(LastModified, 'T0') || contains(LastModified, 'T1') || contains(LastModified, 'T20') || contains(LastModified, 'T21') || contains(LastModified, 'T22')))].{Key: Key, VersionId: VersionId}"`
cat << EOF > $fileName
@nashjain
nashjain / Snakes_n_Ladder_Game.php
Created September 13, 2015 02:12
Simple Snakes and Ladders Game Implemented in PHP
<?php
function new_game($players, $mode = 'Easy', $board_size = 100)
{
$game_modes = ["Easy" => 5, "Medium" => 10, "Hard" => 20];
$snakes_ladders = random_board($game_modes[$mode], $board_size);
play($players, $snakes_ladders, $board_size);
}
function play($players, $snakes_ladders, $board_size)
{