Skip to content

Instantly share code, notes, and snippets.

@ruslangrimov
ruslangrimov / extract_tar_to_ram_remove.py
Last active February 11, 2024 16:28
Extract tar into memory, remove the original tar file and save files to the same disk if there is no space for usual extraction
import os
import tarfile
from tqdm.auto import tqdm
tar_file = "/data/images.tar.gz"
extract_to = "/data/"
files = {}
with tarfile.open(tar_file, "r:gz") as file:
@ruslangrimov
ruslangrimov / kill_by_grep.sh
Created November 9, 2023 10:30
Kill all processed by grep
kill $(ps aux | grep '[p]ython csp_build.py' | awk '{print $2}')
@ruslangrimov
ruslangrimov / pool.py
Created April 13, 2023 12:48
Multiprocessing pool
from multiprocessing import Pool
with Pool(processes=10) as pool:
for _ in tqdm(pool.imap_unordered(parse_row, df.itertuples(name=None)), total=len(df)):
pass
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ruslangrimov
ruslangrimov / install_opencv_on_ubuntu.sh
Last active September 2, 2021 12:22
Install OpenCV on Ubuntu
# Prepare
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libjasper-dev
# If previous line doesn't work
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
@ruslangrimov
ruslangrimov / pytorch_log_all_outputs.py
Created May 29, 2020 19:40
Get outputs of each layer using hooks
class SaveOutput:
def __init__(self):
self.outputs = []
def __call__(self, module, module_in, module_out):
self.outputs.append(module_out)
def clear(self):
self.outputs = []
@ruslangrimov
ruslangrimov / settings.js
Created April 30, 2020 15:35
My VSCode settings
{
"window.zoomLevel": 0,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.rulers": [ 80 ],
"terminal.integrated.inheritEnv": false,
"python.dataScience.sendSelectionToInteractiveWindow": true,
"files.trimTrailingWhitespace": true,
"python.linting.flake8Enabled": true,
@ruslangrimov
ruslangrimov / run_gpu_watch.sh
Created February 11, 2020 10:52
Create tmux session with two panes
#!/bin/sh
tmux new-session -d -s watch 'exec watch -n 1 nvidia-smi'
tmux rename-window 'Watch'
tmux select-window -t watch:0
tmux split-window -v 'exec htop'
tmux resize-pane -y 8
@ruslangrimov
ruslangrimov / resume_output_receiving_in_notebooks.js
Last active February 18, 2022 14:46
Script to resume receiving cells output after a notebook reloaded or even opened in other browser
// This script makes it possible to resume cells output receiving after a notebook reloads.
// Works even when the notebook is open in other browser (output will be shown in all opened windows).
// Works with keras and tqdm (not with tqdm_notebook).
//
// Add this code into your ~/.jupyter/custom/custom.js
define([
'base/js/namespace',
'base/js/promises'
], function(Jupyter, promises) {
@ruslangrimov
ruslangrimov / pytorch_repr.py
Created December 27, 2019 11:02
Reproducible pytorch cuda
np.random.seed(42)
random.seed(42)
cudnn.benchmark = False
cudnn.deterministic = True
torch.manual_seed(42)
torch.cuda.manual_seed_all(42)
torch.set_printoptions(precision=10)