Skip to content

Instantly share code, notes, and snippets.

View vadimkantorov's full-sized avatar
💭
looking for an internship for summer/fall 2021

Vadim Kantorov vadimkantorov

💭
looking for an internship for summer/fall 2021
View GitHub Profile
@vadimkantorov
vadimkantorov / git.sh
Last active December 25, 2024 19:22
Various git tricks
# fork your own repo, example of my repo https://github.com/vadimkantorov/eventmap
git clone [email protected]:vadimkantorov/eventmapexample.git
cd eventmapexample
git remote add upstream [email protected]:vadimkantorov/eventmap.git
git pull upstream gh-pages
git checkout gh-pages
git push -u origin gh-pages
# update git to latest version on ubuntu
sudo add-apt-repository -y ppa:git-core/ppa
@vadimkantorov
vadimkantorov / safepdfmerge.py
Last active August 16, 2024 19:53
Python oneline safe pdf merging showcasing using a way of lambda handling exceptions
# git clone --branch v0.4 --depth 1 --single-branch https://github.com/pmaupin/pdfrw
# PYTHONPATH="$PWD/pdfrw:$PYTHONPATH" python3 safepdfmerge.py /path/to/target/dir /path/to/my/file1.pdf /path/to/my/file2.pdf /paths/to/other/files.pdf
import sys, os, pdfrw; safe_read_pdf_pages = lambda path: exec(f"try: res = pdfrw.PdfReader({path!r}).pages;\nexcept: print({path!r}, sys.exc_info()); res = []", globals(), globals()) or res; writer = pdfrw.PdfWriter(); [writer.addpages(safe_read_pdf_pages(inpfn)) for inpfn in sys.argv[2:]]; os.makedirs(sys.argv[1], exist_ok = True); writer.write(os.path.join(sys.argv[1], os.path.basename(sys.argv[2])))
@vadimkantorov
vadimkantorov / download_only_subtitles_from_youtube.sh
Last active September 7, 2022 00:49
Download only subtitles for a given lang with youtube-dl
# download only auto subtitles, resources:
# https://superuser.com/questions/927523/how-to-download-only-subtitles-of-videos-using-youtube-dl
# http://ytdl-org.github.io/youtube-dl/download.html
# wget https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe && ./vcredist_x86.exe /install /quiet /norestart
# wget https://yt-dl.org/downloads/latest/youtube-dl.exe
# downloadonlysubtitles ru 'https://www.youtube.com/watch?v=VBHhhGOGdKk'
alias downloadonlysubtitles='youtube-dl --skip-download --write-auto-sub --sub-lang' # or ./youtube-dl.exe on Windows
@vadimkantorov
vadimkantorov / heb.py
Created August 15, 2022 15:21
Grep all Hebrew strings from stdin
# cat foo.html | python heb.py
# https://en.wikipedia.org/wiki/Hebrew_(Unicode_block)
import re, sys; print('\n'.join(filter(bool, map(str.strip, re.findall(u'[ \u0590-\u05ff]+', sys.stdin.read())))))
@vadimkantorov
vadimkantorov / attach_virtualusb.diskpart
Last active July 28, 2022 16:09
Create a virtual flash drive, format and attach it in Windows
rem diskpart /s attach_virtualusb.diskpart
select vdisk file=C:\Users\vadim\virtualusb.vhd
attach vdisk
assign letter=B
@vadimkantorov
vadimkantorov / rdv_myvisit.py
Last active September 17, 2022 22:25
Print a list of nearest rendez-vous at all POIA/PIBA locations in Israel (e.g. for renewing Darkon). Currently useless, as myvisit.com introduced severe anti-scraping mitigations.
# Usage: using Chrome DevConsole's Network tab, grab JWT token from a manual search of rdv at https://myvisit.com (found in Authorization/Cookie header of /CentralAPI/SearchAvailableDates call) and call as:
# python3 poia_rdv_myvisit.py --jwt 'eyJ...'
# this jwt token is a result of recaptcha solution and is valid for 30 min
# found existing service to pick the rdv times for passport renewal: https://picktimebot.com/, Chrome extension to collect the JWT token: https://github.com/SharonBrizinov/PickTime
# klita currently fails LocationSearch request, so duplicates are fetched from crawled services.json
# -*- coding: utf-8 -*-
import argparse
import json
import time
@vadimkantorov
vadimkantorov / explorer.txt
Created April 13, 2022 15:39
Explorer OneDrive hang
shcore.dll
ntoskrnl.exe!KeSynchronizeExecution+0x6776
ntoskrnl.exe!KeLowerIrql+0x16d7
ntoskrnl.exe!KeLowerIrql+0x3589
ntoskrnl.exe!KeWaitForSingleObject+0x234
ntoskrnl.exe!KeQuerySystemTimePrecise+0x131b
ntoskrnl.exe!RtlFindClearBits+0x1634
ntoskrnl.exe!KeLowerIrql+0x1c66
ntoskrnl.exe!KeLowerIrql+0x3589
@vadimkantorov
vadimkantorov / sequential_backprop.py
Last active November 12, 2021 16:34
Mini-batching within the model in PyTorch
# Instance-Aware, Context-Focused, and Memory-Efficient Weakly Supervised Object Detection, https://arxiv.org/abs/2004.04725
# https://github.com/NVlabs/wetectron/issues/72
# https://discuss.pytorch.org/t/mini-batching-gradient-accumulation-within-the-model/136460
import torch
import torch.nn as nn
class SequentialBackprop(nn.Module):
def __init__(self, module, batch_size = 1):
super().__init__()
@vadimkantorov
vadimkantorov / torchutils.py
Last active November 4, 2021 14:38
PyTorch useful functions
import torch
import torch.nn.functional as F
import torchvision
import base64
gather_incomplete = lambda tensor, I: tensor.gather(I.ndim, I[(...,) + (None,) * (tensor.ndim - I.ndim)].expand((-1,) * (I.ndim + 1) + tensor.shape[I.ndim + 1:])).squeeze(I.ndim)
expand_dim = lambda tensor, expand, dim: tensor.unsqueeze(dim).expand((-1, ) * (dim if dim >= 0 else tensor.ndim + dim + 1) + (expand, ) + (-1, ) * (tensor.ndim - (dim if dim >= 0 else tensor.ndim + dim + 1)))
encode_image_as_html = lambda img, height, width: '<img height="{height}" width="{width}" src="data:image/jpeg;base64,{encoded}" />'.format(height = height, width = width, encoded = bytes(base64.b64encode(torchvision.io.encode_jpeg(F.interpolate(img[None], (height, width)).squeeze(0)))).decode())
# Blender 2.93 python script for producing images like in https://github.com/facebookresearch/meshrcnn/issues/22
# blender -noaudio --background --python meshrcnn_overlay_mesh.py -- --object-path test.obj --background-path test.png
#
# Sample ouptut:
# https://github.com/facebookresearch/meshrcnn/issues/100
#
# References:
# https://github.com/yuki-koyama/blender-cli-rendering/blob/master/02_suzanne.py
# https://github.com/weiaicunzai/blender_shapenet_render/blob/master/render_rgb.py
# https://towardsdatascience.com/blender-2-8-grease-pencil-scripting-and-generative-art-cbbfd3967590