Skip to content

Instantly share code, notes, and snippets.

View kirankotari's full-sized avatar
:octocat:
Coming back up-to speed, need a bit more time.

Kiran Kumar Kotari kirankotari

:octocat:
Coming back up-to speed, need a bit more time.
View GitHub Profile
@kirankotari
kirankotari / NewMac.md
Last active January 12, 2023 19:27
How to use Mac M1/M2 (arm64) to x86_64 (like Intel)

How to use Mac M1/M2 (arm64) to x86_64 (like Intel)

  1. Uninstall all previous installation and its dependencies, e.g. ant, Java,..
brew remove java
brew remove ant
brew remove zlib
# python, etc
@kirankotari
kirankotari / cronjob_running_shell_script.md
Created August 4, 2022 09:23
cronjob running a shell script from it
  1. Need to change relative paths to absolute paths
  2. Need to replace /bin/bash to absolute reference ie. /usr/bin/bash
  3. In the crontab -e need to add following PATH to run a script
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  4. Add the PATH at the top of the shell script
  5. Now set the timer, we should be good to go.
@kirankotari
kirankotari / dynamic_proxy.sh
Created July 31, 2022 17:11
setting and unsetting proxy from .bash_profile
alias proxy="export https_proxy=http://<url>:<port>;export http_proxy=http://<url>:<port>"
alias noproxy="export https_proxy='';export http_proxy='';"
# How to use
# call `proxy` command in terminal to setup
# call `noproxy` to unset
# by defalt we are setting the proxy
proxy
<!DOCTYPE html>
<html>
<head>
<title>CNPM Binaries Mirror</title>
</head>
<body>
<script>
// Forked from https://chromedriver.storage.googleapis.com/index.html
// Split a string in 2 parts. The first is the leading number, if any,
// the second is the string following the numbers.
import argparse
# Create the parser and add arguments
# parser = argparse.ArgumentParser()
# # 1) init arg
# parser.add_argument(dest='argument1', help="This is the first argument")
# # Parse and print the results
# args = parser.parse_args()
from distutils import util
def _msg(args, msg=None):
msg = "input value error, please check your inputs." if msg is None else msg
return (f"{msg} {args[-1]}",)
def _try(func):
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
@kirankotari
kirankotari / input_typecast.py
Last active January 11, 2022 00:28
python input typecasting for major data types
from distutils import util
def _msg(args, msg=None):
msg = "input value error, please check your inputs." if msg is None else msg
return (f"{msg} {args[-1]}",)
def _try(func):
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
@kirankotari
kirankotari / class_instance_decorator.py
Last active July 12, 2021 16:09
Python Decorator dependent on Class Instance variables
def myDecorator(arg1, arg2, arg3=None):
def wrap(f):
def fun_wrap(self, *args, **kwargs):
# TODO: before calling function
print(f"before method call, {self.arg1}")
f(self, *args, **kwargs)
# TODO: after calling function
print(f"after method call, {self.arg1}")
return fun_wrap
return wrap
@kirankotari
kirankotari / decorator.py
Created July 3, 2021 09:39
Class Decorators
class Decorator:
profile = None
workspace_id = None
def __init__(self, profile="default"):
self.profile = profile
def make_pretty(func):
def inner(self):
print("I got decorated")
func(self, self.profile)
@kirankotari
kirankotari / pyang python3 support
Last active April 6, 2021 16:13
NSO Pyang Python3 support changes
# If you want to use Python 3 alonge with old NSO version which contains pyang issue to support python3 here are few steps
# 1. we are convering the python syntax to support Python2 and Python3
# a. PEP 3113
# b. importing StringIO
# 2. we are not planning to correct any ned's, we request to collect latest neds to support python3
File: NSO-<version>/lib/pyang/pyang/plugins/html.py
# Existing:
from cStringIO import StringIO
# Updates: