Skip to content

Instantly share code, notes, and snippets.

View nitesh8860's full-sized avatar

Nitesh Chauhan nitesh8860

View GitHub Profile
@nitesh8860
nitesh8860 / timeit-list.py
Last active June 15, 2020 05:57
calculating time taken for list growth with different methods using timeit
# List comprehensions are the fastest.
def test1():
l = []
for i in range(1000):
l = l + [i]
def test2():
l = []
for i in range(1000):
@nitesh8860
nitesh8860 / awscli-deleteLogGroupPatterns.sh
Created May 23, 2021 03:26
deletes log groups in bulk from cloudwatch
export AWS_DEFAULT_REGION=eu-west-1
aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | \
awk '{print $2}' | grep ^/aws/rds | while read x; do echo "deleting $x" ; aws logs delete-log-group --log-group-name $x; done
@nitesh8860
nitesh8860 / random-awscli.sh
Created May 23, 2021 03:59
creating inventory with tag values, filter.json
aws2 ec2 create-tags --resources $i --tags Key=SSM,Value=yes
aws2 ec2 associate-iam-instance-profile --instance-id $i --iam-instance-profile Name=SSMec2-Instance-Profile
aws ec2 associate-iam-instance-profile --instance-id i-0xxxxxxxxxx --iam-instance-profile Name=SSMec2-Instance-Profile
aws iam add-role-to-instance-profile --role-name AmazonEC2RoleforSSM --instance-profile-name SSMec2-Instance-Profile
aws iam remove-role-from-instance-profile --instance-profile-name SSMec2-Instance-Profile --role-name AmazonSSMRoleForInstancesQuickSetup
aws iam add-role-to-instance-profile --role-name AmazonEC2RoleforSSM --instance-profile-name SSMec2-Instance-Profile
aws2 ec2 describe-instances --filters Name=network-interface.addresses.private-ip-address,Values=[$i] \
--query 'Reservations[*].Instances[*].{IP:PrivateIpAddress,Name:Tags[?Key==`Name`]|[0].Value}' \
--output text