Skip to content

Instantly share code, notes, and snippets.

@ecolss
ecolss / zmq_r2r.py
Last active December 9, 2023 23:43
zeromq router-to-router example code
import multiprocessing as mp
import random
import sys
import zmq
def worker_proc(worker_addr, id_, proc_factory, proc_kwargs):
ctx = zmq.Context()
sock = ctx.socket(zmq.REQ)
sock.identity = f"woker_{id_}".encode()
@ecolss
ecolss / nvidia_driver_issues.txt
Last active December 3, 2023 12:11
nvidia driver issues on ubuntu
The problem,
- PC was running 20.04 LTS, and one day PC can't shut down properly, had to manually force the shutdown (pressing the power btn).
- After that, PC lost nvidia-driver stuff (nvidia-smi can't work anymore), so need to reinstall drivers.
- The frustrating part is, tried so many different tutorials/versions, none worked. (e.g. apt update/upgrade/purge/remove/install whatever can be found online)
The fix,
- At last, decided to upgrade ubuntu to 22.04 LTS, and then simply `$ sudo apt install nvidia-driver-535`, reboot and done.
- One key reason why decided to upgrade is, all apt solutions tried are blocked by glibc version requirement (higher libc6 version is needed, but on 20.04 seems no such versions).
@ecolss
ecolss / asyncio_example.py
Created November 7, 2023 19:02
asyncio example
import asyncio
from concurrent.futures import ThreadPoolExecutor
import random
import requests
import time
def unit_task(data):
"""
For example, this function can be the requests.get for http response.
@ecolss
ecolss / gradcam.py
Last active October 14, 2023 19:10
Grad CAM - example code
import cv2
from functools import partial
import json
import numpy as np
import os
from PIL import Image
import pylab as pl
import torch as th
from torch import nn
import torchvision as thv
@ecolss
ecolss / ridge_plot.py
Last active September 17, 2023 15:55
A ridge plot function using matplotlib.
import glob
import numpy as np
from matplotlib.gridspec import GridSpec
import numpy as np
import pylab as pl
from sklearn.neighbors import KernelDensity
def ridge_plot(groups, conf):
assert all([isinstance(el, dict) and all([k in el for k in ["name", "data"]]) for el in groups])
@ecolss
ecolss / mlr.py
Created July 2, 2017 13:28
a naive Pytorch impl of Alibaba's Piecewise-Linear Model (I'd call it mixture of LR), compare it with LR.
#!/usr/bin/env python
import numpy as np
import pylab as pl
import torch as th
from torch import nn, autograd as ag, optim
from torch.nn import functional as F
from sklearn import metrics
from sklearn.preprocessing import OneHotEncoder