Skip to content

Instantly share code, notes, and snippets.

@csghone
csghone / matplotlib_helper.py
Last active February 18, 2025 05:05
Matplotlib helpers
# Refs:
# https://matplotlib.org/3.9.3/users/explain/quick_start.html
# https://stackoverflow.com/questions/7908636/how-to-add-hovering-annotations-to-a-plot
# https://www.geeksforgeeks.org/how-to-draw-a-line-inside-a-scatter-plot/
# https://python-graph-gallery.com/scatterplot-with-regression-fit-in-matplotlib/
# https://stackoverflow.com/questions/22239691/code-for-best-fit-straight-line-of-a-scatter-plot
# https://stackoverflow.com/questions/27878217/how-do-i-extend-the-margin-at-the-bottom-of-a-figure-in-matplotlib
# https://stackoverflow.com/questions/51473993/plot-an-histogram-with-y-axis-as-percentage-using-funcformatter
def plot_cols(inp_df: pandas.DataFrame, *args):
@csghone
csghone / setup_lvm.sh
Created September 6, 2024 03:12
New LVM
fdisk -l # To get diskname - '/dev/nvme1n1' in example below and mount at /local/mnt2/
# DISK_NAME=/dev/nvme1n1
# VG_NAME=vg10
# LV_NAME=lv_local_mnt2
# MOUNT_TARGET=/local/mnt2
pvcreate /dev/nvme1n1 # You might have to wipe GPT signatures if this was partitioned by Windows
vgcreate vg10 /dev/nvme1n1
lvcreate -n lv_local_mnt2 -l +100%FREE vg10
@csghone
csghone / lvm_resize.sh
Created September 6, 2024 03:09
LVM resizing
exit 1 # DONT RUN DIRECTLY
# Original system: "/" and "/local/mnt" with 20 GB and 2000 GB
# Target: Increase "/" to 200 GB
# Do reboot since some random processes keep accessing /local/mnt
# Run following as root as soon as you reboot
df -h # Note down / and /local/mnt partition sizes
umount /local/mnt
@csghone
csghone / create_cli_args_from_dict.py
Last active September 6, 2024 03:03
Create cli args using Dict and ArgumentParser
import argparse
from typing import Any, Dict
def create_cli_args_from_dict(parser: argparse.ArgumentParser, inp_args_dict: Dict[str, Any]):
ret_val_list = []
for action in parser._actions:
if action.dest not in inp_args_dict: continue
val = inp_args_dict[action.dest]
if isinstance(action, argparse._StoreTrueAction):
assert isinstance(val, bool)
@csghone
csghone / dot_viewer.html
Created December 4, 2023 18:31
Dot Viewer
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>Dot Viewer</title>
<meta property="og:title" content="Dot Viewer">
</head>
<body>
@csghone
csghone / graphviz_html_label_graph.py
Created December 4, 2023 18:29
Create GraphViz graph with HTML-like labels
#!/usr/bin/env python
import argparse
import logging
import logging.handlers
import os
import sys
import textwrap
import traceback
from dataclasses import dataclass
@csghone
csghone / netron_build.sh
Created September 26, 2023 08:45
Netron build
git clone https://github.com/lutzroeder/netron.git
cd netron
npm install
npx electron-builder --linux appimage --x64 --publish never
ls $PWD/dist/Netron*AppImage -ltr | awk '{print $NF}' | tail -n 1 | xargs -IXX sudo cp XX /usr/bin/netron
@csghone
csghone / vscode.sh
Last active September 26, 2023 09:15
VSCODE reconnect
vscode_reconnect_insiders ()
{
BIN_DIR=$(ls ~/.vscode-server-insiders/cli/servers/*/server/bin/remote-cli/code-insiders -altr | awk '{print $NF}' | tail -n 1 | sed 's:.code.insiders$::')
export PATH=$PATH:$BIN_DIR
export VSCODE_IPC_HOOK_CLI=$(ls /run/user/${UID}/vscode-ipc-*.sock -ltr | awk '{print $NF}' | tail -n 1)
}
vscode_reconnect ()
{
BIN_DIR=$(ls ~/.vscode-server/cli/servers/*/server/bin/remote-cli/code -altr | awk '{print $NF}' | tail -n 1 | sed 's:.code$::')