Skip to content

Instantly share code, notes, and snippets.

View acsrujan's full-sized avatar

Srujan acsrujan

View GitHub Profile
acsrujan /
Last active November 27, 2015 07:08
Resume of Srujan Akumarthi (Myself). Python program readable by layman, and also, executable through command line.
If you're viewing it from pdf, original program can be found at:
To run download the file as it is.
Make sure you've python installed. (run python --version in terminal)
python -h will show the help line. (Make sure to change the file name.)
python -c will show contacts. and so on.
acsrujan /
Last active December 10, 2015 10:05
Installs postgres 9.3
sudo touch /etc/apt/sources.list.d/pgdg.list
echo "deb precise-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-9.3 libpq-dev postgresql-contrib-9.3
sudo apt-get autoremove
sudo pg_dropcluster --stop 9.3 main
sudo pg_createcluster --start -e UTF-8 9.3 main
acsrujan /
Created January 21, 2016 07:42
Bash script to find large files in your github.
#set -x
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
acsrujan /
Last active March 17, 2016 14:09
Parses rails log file from bash to find out requests which took more than 75sec
arr=```grep -o "in.*ms" $LOG_FILE_NAME | awk '{if ($2-75000ms > 0) print $2}' | sort -r -n``` | for i in $arr; do grep -B 1 $i $LOG_FILE_NAME |awk '{print $2 FS $3}'; echo $i; done
acsrujan /
Last active March 30, 2016 08:35
Schedule AMI creation and delete 3 days older images.
#---The following is to create AMI of server daily---#
echo "instance-`date +%d%b%y`" > /tmp/ami-name.txt
INSTANCE_ID=$1 #Pass instance id as arguement or change hardcode it here.
aws ec2 create-image --instance-id $INSTANCE_ID --name "`cat /tmp/ami-name.txt`" --description "This is daily auto AMI by Cron" --no-reboot | grep -i ami | awk '{print $2}' > /tmp/ami-id.txt
#---The following is to remove AMIs older than 3 days---#
echo "instance-`date +%d%b%y --date '3 days ago'`" > /tmp/ami-delete.txt
aws ec2 describe-images --filters "Name=name,Values=`cat /tmp/ami-delete.txt`" | grep -i imageid | awk '{ print $2 }' > /tmp/image-id.txt
acsrujan /
Last active June 2, 2016 01:34
nginx load balancing nodejs

Download Repo in /var/www/ folder.

acsrujan /
Last active July 18, 2016 09:18
Script to test connection of a host, port and print time taken for each connection. Output is STDOUT.
START=`date +%s`
while [ $(( $(date +%s) - 30 )) -lt $START ]; do
{ time nc -zw30 <host ip> <port>;} |& grep real | awk '{print $2}'
To find largest inode directory.
```for i in /*; do echo $i; find $i |wc -l; done```
acsrujan /
Last active September 2, 2016 06:51
Detach and Attach a random instance to an ELB.
Instance_ids_str=`aws elb describe-load-balancers --load-balancer-name $LOAD_BALANCER_NAME --query "LoadBalancerDescriptions[*].{ID:LoadBalancerName,InstanceId:Instances[*].InstanceId}[*]. {ELB:ID,InstanceId:InstanceId[*]}" --output=json |jq -r ".[].InstanceId|@csv" |sed 's/\"//g'`
IFS=',' read -a Instance_ids_array <<< "$Instance_ids_str"
for INSTANCE_ID in ${Instance_ids_array[$RANDOM % ${#Instance_ids_array[@]}]}
aws elb deregister-instances-from-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
aws elb register-instances-with-load-balancer --load-balancer-name $LOAD_BALANCER_NAME --instances $INSTANCE_ID
import platform
import os
import multiprocessing
os_name = platform.system()
print ("os_name:"+os_name)
os_version = platform.version()
print ("os_version:"+os_version)
cpu_architecture = platform.architecture()[0]