Skip to content

Instantly share code, notes, and snippets.

@abhijitmamarde
abhijitmamarde / process_completed_watcher.py
Created September 28, 2022 12:49
Simple script to watch for specific process is over, and trigger action once it is over
"""Simple script to watch for specific process is over, and trigger action once it is over
- Waits for some start time (the process is expected to start within this time)
- Fetches all the running processes, exiting for below-mentioned conditions
- Waits for next run
- The watcher exits if:
- process is not found running for max watcher timeout, from starting
- current time is over max watcher timeout, from last process found time
Requirements:
@abhijitmamarde
abhijitmamarde / ntptime.py
Last active February 23, 2021 13:30
get correct unix timestamp from ntp server
"""
Original source:
https://www.mattcrampton.com/blog/query_an_ntp_server_from_python/
"""
from socket import AF_INET, SOCK_DGRAM
import socket
import struct
@abhijitmamarde
abhijitmamarde / main.py
Created December 28, 2020 04:59
Get json object from string with an embedded json string
import regex
import json
input_string = '''2020-12-23T07:23:18.000000+05:30 45.79.121.190 {"hostname":"abc.members.linode.com","os":{"name":"CentOS Linux","family":"redhat","version":"7 (Core)","platform":"centos","kernel":"3.10.0-1127.13.1.el7.x86_64","codename":"Core"},"containerized":false,"ip":["44.75.121.190","2400:8904::f03c:92ff:fed4:e4f0","fe80::f03c:92ff:fed4:e4f0"],"name":"abc.members.linode.com","cpu":{"pct":0.062},"id":"c29d751565e74afdbaade6c8a36dd2ef","mac":["f2:3c:92:d4:e4:f0"],"architecture":"x86_64"} LOGSTASH[-]: 2020-12-23T07:23:18.995Z {hostname=abc.members.linode.com, os={name=CentOS Linux, family=redhat, version=7 (Core), platform=centos, kernel=3.10.0-1127.13.1.el7.x86_64, codename=Core}, containerized=false, ip=[44.75.121.190, 2400:8904::f03c:92ff:fed4:e4f0, fe80::f03c:92ff:fed4:e4f0], name=abc.members.linode.com, cpu={pct=0.062}, id=c29d751565e74afdbaade6c8a36dd2ef, mac=[f2:3c:92:d4:e4:f0], architecture=x86_64} %{message}'''
# def get_json2(input_str):
# start = input_str.find('{
@abhijitmamarde
abhijitmamarde / demo.py
Created November 22, 2020 17:30 — forked from wshayes/demo.py
[Websocket demo for fastapi] example of broadcast using websockets for fastapi #fastapi #websockets
# From https://github.com/tiangolo/fastapi/issues/258
from typing import List
from fastapi import FastAPI
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
@abhijitmamarde
abhijitmamarde / main.py
Created October 1, 2019 14:43
server side events using flask
# ref: https://stackoverflow.com/questions/12232304/how-to-implement-server-push-in-flask-framework
import datetime
import time
import json
from flask import Flask, Response
app = Flask(__name__)
def event_stream():
@abhijitmamarde
abhijitmamarde / plularsight.md
Created September 5, 2019 11:53
list of good online courses
@abhijitmamarde
abhijitmamarde / .my_aliases.sh
Last active August 28, 2019 10:07
common set of aliases
alias via="vim ~/.my_aliases.sh"
alias reload="source ~/.my_aliases.sh"
# common
alias c="clear"
alias lk="ls -lrt"
alias lka="ls -lrta"
alias cdd="cd .."
alias rmf="rm -rf"
@abhijitmamarde
abhijitmamarde / install_python3.md
Last active September 10, 2019 10:45
installing python3 on ubuntu18.04

run using user with root access or append sudo before each command:

$ apt update
$ apt install software-properties-common
# optional: required for installing pip packages which needs compiler. ex: uwsgi
$ apt-get install build-essential
$ add-apt-repository ppa:deadsnakes/ppa

$ apt install python3.7
Bracket Pair Colorizer
Excel Viewer
Git Blame
GitLens — Git supercharged
IntelliSense for CSS class names in HTML
JSON Parse & Stringify
JSON Tools
Markdown All in One
Python
REST Client
@abhijitmamarde
abhijitmamarde / linode setting commands.md
Created February 12, 2019 14:50
linode setting useful commands

to get system public IP

curl ifconfig.me

install virtualenv

apt install virtualenv

change hostname: