Skip to content

Instantly share code, notes, and snippets.

-- Create database assignment
SELECT 'CREATE DATABASE assignment'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'assignment')\gexec
-- Switch DATABASE
\c assignment
--
-- Name: categories; Type: TABLE; Owner: -; Tablespace:
#!/bin/bash
# This script will run from ec2 user data
# and it will deattach secondary network interface(ENI)
# from previous instance if any old instance found
# If ENI is not attach then it will not run deattach command
# at the last it will run eni attach command to add eni in current instance
#
# Note: Make sure to update ENI Name Tag in variable NAME_TAG
@rahulinux
rahulinux / notify-sns.md
Last active April 4, 2019 11:18
notify-sns

Following client script will help to publish message in sns topic

#!/usr/bin/env python

import boto3
import json

REGION = "eu-west-1"

Keybase proof

I hereby claim:

  • I am rahulinux on github.
  • I am rahul_patil (https://keybase.io/rahul_patil) on keybase.
  • I have a public key ASCJYTflGlhZaX8903s0sC9eI98XTDuKu5EYFb5KiV8DGAo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am rahulinux on github.
  • I am rahulinux (https://keybase.io/rahulinux) on keybase.
  • I have a public key ASBGGgzWFj8jc1Nn8cffGWu-su-04uiAVssFCEKqe9ubvAo

To claim this, I am signing this object:

@rahulinux
rahulinux / YesOrNo.sh
Last active September 11, 2016 06:56
User Confirmation function, this function will prompt again if user has hit blank enter,
YesOrNo() {
while :
do
read -p 'Do you want to Continue (yes/no?): ' answer
case "${answer}" in
[yY]|[yY][eE][sS]) exit 0 ;;
[nN]|[nN][oO]) exit 1 ;;
esac
done
}
@rahulinux
rahulinux / flotToint.sh
Created September 5, 2013 14:24
Convert float to integer in bash
flotToint() {
printf "%.0f\n" "$@"
}
@rahulinux
rahulinux / status_msg.sh
Last active December 22, 2015 04:09
Status Msg
status_msg() {
local status=$?
local failed="$(tput bold)$(tput setf 4)[failed]$(tput sgr0)"
local succeeded="$(tput bold)$(tput setf 2)[succeeded]$(tput sgr0)"
(( $status == 0 )) &&
echo $succeeded ||
echo $failed
}
@rahulinux
rahulinux / GetTopProcess.sh
Created September 2, 2013 15:38
Print Top 10 Process using high %CPU
GetTopProcess() {
ps --no-headers -eo "%cpu,%mem,cmd,etime" |
sort -t. -k1 -r |
head -10
}
@rahulinux
rahulinux / CheckLoadavg.sh
Created September 2, 2013 15:18
check load average of server and return if load more than 6 or passed threshold to the function
CheckLoadadv() {
# Set threshold value
local Threshold=$1
# if threshold not specify then take deafault 6
(( $Threshold )) || Threshold=6
# get input values from /proc/loadavg file
local Current_loadadv="$(cut -d" " -f1 /proc/loadavg )"
# take first value from inputdata
local Cur_int_loadadv="${Current_loadadv/.*}"