Skip to content

Instantly share code, notes, and snippets.

View murarisumit's full-sized avatar
🎩
Welcome here

Sumit Murari murarisumit

🎩
Welcome here
View GitHub Profile
@murarisumit
murarisumit / stop_and_wait_till_stopped_state.sh
Created March 31, 2016 02:47
Stop instance and wait till it's in stopped state.
#!/bin/bash
profile=your_creds_profile
output=your_output_fomat['text' or 'json' ...]
instance_id=i-454645644744 #yourinstance_id here
cmd='aws ec2 describe-instances --instance-ids $instance_id --profile $profile'
aws ec2 stop-instances --instance-ids $instance_id --profile zeus
COUNTER=0
while [ $COUNTER -lt 60 ]; do
@murarisumit
murarisumit / xml_json_vim
Created June 17, 2016 05:53
Preety print xml and json in vim #vim #json #pretty
Preety print xml and json in vim
XML:
1. Install xmllint : `sudo apt-get install libxml2-utils`
2. Use xmllint to format the xml
3. Add this to vimrc: `nmap =x :%!xmllint % --format<CR>`
JSON:
@murarisumit
murarisumit / vidle.sh
Last active November 8, 2017 07:23
Idle in vitualenv #python #idle
#!/bin/bash
#Opening idle in virtualenv
LOCAL_BIN_HOME="$HOME/.local/bin"
mkdir -p $LOCAL_BIN_HOME
echo "python -m idlelib.idle" > $LOCAL_BIN_HOME/vidle
chmod +x $LOCAL_BIN_HOME/vidle
#Add the local bin path to PATH
export PATH=$PATH:$LOCAL_BIN_HOME
#Execute $ vidle
@murarisumit
murarisumit / Nginx grok format
Created September 16, 2016 06:44
NGinx grok format logstash.
# Nginx
NGUSERNAME [a-zA-Z\.\@\-\+_%]+
NGUSER %{NGUSERNAME}
NGINXACCESS %{IPORHOST:clientip} %{NGUSER:ident} %{NGUSER:auth} \[%{HTTPDATE:timestamp}\] "%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:response} (?:%{NUMBER:bytes}|-) (?:"(?:%{URI:referrer}|-)"|%{QS:referrer}) %{QS:agent}
# Nginx error formats
NGINXERROR0 (?<timestamp>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[%{DATA:err_severity}\] (%{NUMBER:pid:int}#%{NUMBER}: \*%{NUMBER}|\*%{NUMBER}) %{DATA:err_message}(?:, client: (?<client_ip>%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server})(?:, request: %{QS:request})?(?:, host: %{QS:clientip})?(?:, referrer: \"%{URI:referrer})
NGINXERROR1 %{DATESTAMP:timestamp} \[%{DATA:err_severity}\] %{GREEDYDATA:err_message}
@murarisumit
murarisumit / gettingstarted.bash
Last active May 3, 2025 02:49
Bash basic template for argument parsing and basic exit handling
#!/bin/bash
##
# the handle_argument function receives all the non-option argument or non-flag argument
##
handle_argument() {
# the first argumeent without any flag
echo " Argument is : $1 "
}
@murarisumit
murarisumit / configparser.py
Last active May 4, 2019 01:37
Python configparser example #python
# definations.py
import os
import configparser
# Environment defination variable, this environment variable will use used to pick config file
ENV = os.environ["ENVIRONMENT"]
# settings
settings = configparser.ConfigParser()
BASEDIR = os.path.dirname(os.path.realpath(__file__))
@murarisumit
murarisumit / package_vs_module_python.md
Last active April 3, 2017 13:45
Package vs module python #python

A Python module is simply a Python source file, which can expose classes, functions and global variables.

When imported from another Python source file, the file name is treated as a namespace. namespace.Globalvar

A Python package is simply a directory of Python module(s).


@murarisumit
murarisumit / everyday_python_logging.py
Last active May 3, 2025 02:49
basic logging python #python #logging
# `ref: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('hello.log')
@murarisumit
murarisumit / basic_python_with_logging.py
Last active May 3, 2025 02:49
Python logging instead of print #python #logging
import sys
import logging
# We don't need to use print statement, using logger removes many python compatibilit
# and need to modify code later, we can just configure logger and rest code remains as it is. #
# logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger("LOGGER_NAME")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
@murarisumit
murarisumit / subprocess_external_command.py
Last active May 3, 2025 02:49
Execute command using python subprocess #python #subprocess #external-commands
#!/bin/bin/env python
import subprocess
#Exeternal Command with args
DPKG = ['dpkg', '-l']
# Execute the command
dpkg_process = subprocess.Popen(DPKG, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait till process to exit
out, error = dpkg_process.communicate()