Skip to content

Instantly share code, notes, and snippets.

@kchawla-pi
kchawla-pi / client.py
Created October 26, 2023 20:51 — forked from vsajip/client.py
Run a logging socket receiver in a production setting with logging from an example webapp
from concurrent.futures import ThreadPoolExecutor, as_completed
import json
import urllib.request
with open('webapp.json', encoding='utf-8') as f:
config = json.loads(f.read())
URLS = [
'http://localhost:%d/?ident=%d' % (config['port'], ident)
for ident in range(1, 1001)
@kchawla-pi
kchawla-pi / nvidia-xfce-desktop-container-popos-22.04
Created October 26, 2023 02:45 — forked from sandman/nvidia-xfce-desktop-container-popos-22.04
Installing and running a Dockerized NVIDIA Xfce desktop with ROS2 Foxy
# Install latest version nvidia-docker2 on PopOS 22.04
## PopOS does not take the latest upstream NVIDIA Container runtime which is needed to run the container
## Run the below steps
### Add a new preference entry in /etc/apt/preferences.d/pop-default-settings
Package: *
Pin: origin nvidia.github.io
Pin-Priority: 1002
@kchawla-pi
kchawla-pi / git-credential-helper-libsecret.sh
Created October 26, 2023 02:45 — forked from P403n1x87/git-credential-helper-libsecret.sh
Store git credentials securely on Ubuntu
#!/bin/bash
set -e
sudo apt-get -y install libsecret-1-0 libsecret-1-dev libglib2.0-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
@kchawla-pi
kchawla-pi / docker_gpu_support_ubuntu.txt
Last active October 24, 2023 19:54
Making GPUs available in Docker on Ubuntu 22.04
sudo apt update
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt install nvidia-driver-535-server
sudo apt install linux-modules-nvidia-535-server-generic
sudo apt-cache policy linux-modules-nvidia-535-server-$(uname -r)
sudo apt install linux-modules-nvidia-535-server-generic
sudo reboot
sudo apt update
sudo lsmod | grep nouveau
sudo lsmod | grep nvidia
@kchawla-pi
kchawla-pi / plugin_architecture.md
Created February 23, 2023 22:53 — forked from dorneanu/plugin_architecture.md
Python: Implement basic plugin architecture with Python and importlib

Implementing a basic plugin architecture shouldn't be a complicated task. The solution described here is working but you still have to import every plugin (inheriting from the base class).

This is my solution:

Basic project structure

$ tree
@kchawla-pi
kchawla-pi / error_traceback.log
Created January 17, 2023 21:05
Errors encountered while using Memphis-Broker
nats: encountered error
Traceback (most recent call last):
File "/root/.local/lib/python3.10/site-packages/nats/aio/client.py", line 1301, in _select_next_server
await self._transport.connect(
File "/root/.local/lib/python3.10/site-packages/nats/aio/transport.py", line 118, in connect
r, w = await asyncio.wait_for(
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
return fut.result()
File "/usr/local/lib/python3.10/asyncio/streams.py", line 48, in open_connection
transport, _ = await loop.create_connection(
@kchawla-pi
kchawla-pi / clean_code__accessing_resources_best.py
Last active August 3, 2022 16:19
Clean Code Python: Code snippets for blog post "Writing Appreciable Python Code"
from pathlib import Path
text = Path(text_filepath).read_text()
image_data = Path(binary_filepath).read_bytes()
@kchawla-pi
kchawla-pi / first_base_price.py
Created June 16, 2022 21:14
Coworking with Himja,
from pprint import pprint
import numpy as np
import pandas as pd
def fill_first_base_price_of_above_one_window(df, indices):
df["window_base_price"].at[indices[-1]] = df["base_price"].at[indices[0]]
@kchawla-pi
kchawla-pi / first_iteration_0.py
Last active December 28, 2021 13:14
Code snippets used in article "Code. Changing it without breaking it, using a Decorator."
import warnings
def view_connectome(adjacency_matrix,
node_coords,
edge_threshold=None,
edge_cmap=cm.cyan_orange,
symmetric_cmap=True,
linewidth=6.,
node_size=3.,
# each library should be imported in a separate line and arranged alphabetically.
import csv
import glob
import hashlib
import os
# replace with file location
r'''
path = r'/mnt/chromeos/MyFiles/Downloads/CSVs/'
files = glob.glob(path + r"/*.csv")