Skip to content

Instantly share code, notes, and snippets.

View prrao87's full-sized avatar

Prashanth Rao prrao87

View GitHub Profile
@prrao87
prrao87 / gen_data.py
Last active January 27, 2024 00:04
gen_fake_persons.py
"""
Generate a fake dataset (csv or parquet) of persons
Two columns: name (str) and age (int)
Ensure the faker library and polars are installed:
pip install faker polars
Usage:
python gen_data.py -n 1000000 -f csv
python gen_data.py -n 1000000 -f parquet
# Git branch in prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\h \[\e[32m\]\w \[\e[91m\]\$(parse_git_branch)\[\e[00m\]$ "
@prrao87
prrao87 / docker_enable_non_root_user.sh
Created March 28, 2023 17:15
Allow non root/sudo user to run docker containers on Ubuntu
sudo chmod 666 /var/run/docker.sock
# 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 April 29, 2024 15:34
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 March 25, 2024 07:14
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);