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 / search_n_replace_directory.sh
Created April 14, 2017 10:14
SED search and replace in directory
find ./ -type f -exec sed -i -e 's/search/replace/g' {} \;
@murarisumit
murarisumit / grep_awk_search.sh
Last active April 3, 2017 10:44
Use AWK for multiple filtering of output generated #awk #bash #gnu/linux
grep search-term file_name | awk '/filter1/ && !/filter2/ && $3!="filter3" { print $1 }'

Keybase proof

I hereby claim:

  • I am murarisumit on github.
  • I am murarisumit (https://keybase.io/murarisumit) on keybase.
  • I have a public key whose fingerprint is 1FDF CF05 7A84 D426 E99E F8C8 D921 BB76 883B A21F

To claim this, I am signing this object:

@murarisumit
murarisumit / subprocess_piping_external_command.py
Last active September 9, 2022 18:27
Piping command using subprocess #subprocess #python
#!/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)
# Pipe output of dpkg to grep
grep_process = subprocess.Popen(['grep', 'lsof'], stdin=dpkg_process.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@murarisumit
murarisumit / subprocess_external_command.py
Last active August 3, 2021 07:07
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()
@murarisumit
murarisumit / basic_python_with_logging.py
Last active April 3, 2017 13:46
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 / everyday_python_logging.py
Last active May 4, 2019 01:46
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 / 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 / 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 / gettingstarted.bash
Last active October 18, 2016 06:57
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 "
}