Skip to content

Instantly share code, notes, and snippets.

View prrao87's full-sized avatar

Prashanth Rao prrao87

View GitHub Profile
# Create a logger with rotating file handler and formatting per loguru
def get_logger(filename: str):
import sys
from loguru import logger
from pathlib import Path
Path("logs").mkdir(parents=True, exist_ok=True)
logger.remove() # Remove base logger settings and overwrite with custom settings
fmt = "{time:HH:mm:ss:SSS} -- {level} -- {message}"
# Add rotating file handler with desired level of logging
filename = f"{filename}.log" if not filename.endswith(".log") else filename
# change normal keystroke timing on mac to make typing feel more responsive
# normal minimum is 15 (225 ms)
defaults write -g InitialKeyRepeat -int 13
# normal minimum is 2 (30 ms)
defaults write -g KeyRepeat -int 1
@prrao87
prrao87 / log.py
Created February 24, 2023 15:10 — forked from nguyenkims/log.py
Basic example on how setup a Python logger
import logging
import sys
from logging.handlers import TimedRotatingFileHandler
FORMATTER = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
LOG_FILE = "my_app.log"
def get_console_handler():
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(FORMATTER)
@prrao87
prrao87 / httpx-hackernews-async-example.py
Created February 22, 2023 03:45 — forked from danielmichaels/httpx-hackernews-async-example.py
A short realworld example of how to use HTTPX's AsyncClient in a sync class.
"""
HackerNews module.
"""
import logging
import asyncio
from operator import itemgetter
import httpx
{"lastUpload":"2022-01-28T17:29:31.646Z","extensionVersion":"v3.4.3"}
@prrao87
prrao87 / install_postman_mint_no_snap.md
Last active October 27, 2025 08:29
Install Postman on Linux Mint (without using snap)

Goal

Postman is a usefull app to build and test APIs, most commonly installed on ubuntu-like systems via snap. On recent distributions of Linux Mint (20 and above), snap installs are no longer possible. The instructions below show how to install Postman via the terminal.

Download Postman

$ wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz

Extract archive

$ sudo tar -xzf postman.tar.gz -C /opt

Make symlink

@prrao87
prrao87 / googleColabHold.js
Last active February 10, 2025 06:57
Prevent google colab from disconnecting on chrome (right mouse click -> inspect -> console tab -> insert code)
function ConnectButton(){
console.log("Connect pushed");
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click()
}
setInterval(ConnectButton,60000);
@prrao87
prrao87 / install_jupyter_venv.sh
Created March 10, 2021 21:30
Commands to manage and install virtual environment for Jupyter Notebook
# Install python ipykernel with environment name
python -m ipykernel install --user --name=<my_env_name>
# List or uninstall existing virtual envs for Jupyter
jupyter kernelspec list
jupyter kernelspec uninstall <my_env_name>
@prrao87
prrao87 / .zshrc
Last active December 21, 2023 20:19 — forked from ines/.zshrc
Command to activate / create Python virtual environmment
# Do not use the alias `python3`
# For this to work properly, explicitly specify the python version as necessary on your system
function venv {
default_envdir=".venv"
envdir=${1:-$default_envdir}
if [ ! -d $envdir ]; then
python3.12 -m venv $envdir
python3.12 -m pip install ruff
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m"
import streamlit as st
import streamlit.components.v1 as components
from lime_explainer import explainer, tokenizer, METHODS
def format_dropdown_labels(val):
return METHODS[val]['name']
# Build app
title_text = 'LIME Explainer Dashboard for Fine-grained Sentiment'
subheader_text = '''1: Strongly Negative &nbsp 2: Weakly Negative &nbsp 3: Neutral &nbsp 4: Weakly Positive &nbsp 5: Strongly Positive'''