Skip to content

Instantly share code, notes, and snippets.


Abhijit Mamarde abhijitmamarde

View GitHub Profile
abhijitmamarde /
Created Dec 28, 2020
Get json object from string with an embedded json string
import regex
import json
input_string = '''2020-12-23T07:23:18.000000+05:30 {"hostname":"","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":["","2400:8904::f03c:92ff:fed4:e4f0","fe80::f03c:92ff:fed4:e4f0"],"name":"","cpu":{"pct":0.062},"id":"c29d751565e74afdbaade6c8a36dd2ef","mac":["f2:3c:92:d4:e4:f0"],"architecture":"x86_64"} LOGSTASH[-]: 2020-12-23T07:23:18.995Z {, 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=[, 2400:8904::f03c:92ff:fed4:e4f0, fe80::f03c:92ff:fed4:e4f0],, 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 /
Created Nov 22, 2020 — forked from wshayes/
[Websocket demo for fastapi] example of broadcast using websockets for fastapi #fastapi #websockets
# From
from typing import List
from fastapi import FastAPI
from starlette.responses import HTMLResponse
from starlette.websockets import WebSocket, WebSocketDisconnect
app = FastAPI()
abhijitmamarde /
Created Oct 1, 2019
server side events using flask
# ref:
import datetime
import time
import json
from flask import Flask, Response
app = Flask(__name__)
def event_stream():
abhijitmamarde /
Created Sep 5, 2019
list of good online courses
abhijitmamarde /
Last active Aug 28, 2019
common set of aliases
alias via="vim ~/"
alias reload="source ~/"
# common
alias c="clear"
alias lk="ls -lrt"
alias lka="ls -lrta"
alias cdd="cd .."
alias rmf="rm -rf"
abhijitmamarde /
Last active Sep 10, 2019
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
View useful vs code extensions
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
REST Client
abhijitmamarde / linode setting
Created Feb 12, 2019
linode setting useful commands
View linode setting

to get system public IP


install virtualenv

apt install virtualenv

change hostname:

abhijitmamarde /
Created Jan 31, 2019
pub-sub using zmq and multiprocess module
import zmq
import baker
from multiprocessing import Process
def start(name, topicfilter="10001", port="5566"):
print(f"listening pub-server at port:{int(port)}; topic:{topicfilter}")
# Socket to talk to server
context = zmq.Context()
abhijitmamarde /
Created Nov 30, 2018
mock method from standard package
from os.path import exists as orig_exists
from unittest.mock import Mock
exists = orig_exists
def new_exists(file):
print(f"new_exists: checking if '{file}' exists:", orig_exists(file))
print("but will send exists = True")
return True