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 / barcode.py
Last active September 17, 2023 17:15
Barcode-like HTML visualization for speaker diarization / VAD outputs (supports at most two speakers + silence)
speaker_colors = ['gray', 'violet', 'lightblue']
ref_missing = ''
speaker_name_missing = ''
speaker_missing = 0
speaker_phrase_separator = ';'
speaker_separator = ', '
channel_missing = -1
time_missing = -1
_er_missing = -1.0
@vadimkantorov
vadimkantorov / genaudio.sh
Last active December 14, 2023 17:16
Generate audio sample files with ffmpeg
# test1.wav
ffmpeg -f lavfi -i "sine=frequency=1000:duration=5:r=48000" test1.wav
# test2.wav
ffmpeg -f lavfi -i sine=f=440:d=5 -f lavfi -i sine=f=880:d=5 -filter_complex "[0][1]amerge" test2.wav
# test3.wav
ffmpeg -f lavfi -i sine=f=440:d=5 -f lavfi -i anullsrc=d=5:cl=mono -f lavfi -i sine=f=880:d=5 -filter_complex "[0][1][2]concat=n=3:v=0:a=1" test3.wav
# https://github.com/stryku/ffcms
@vadimkantorov
vadimkantorov / print.py
Last active August 11, 2023 17:58
Intercepting python's builtin print function with two ways
class Printer:
def __init__(self):
self.log = ''
def __repr__(self):
return self.log
def __call__(self, *args, **kwargs):
self.log += str(args) + '\n'
__builtins__.print(*args, **kwargs)
@vadimkantorov
vadimkantorov / wincputhrottle.cmd
Last active August 9, 2023 19:40
Print CPU throttling stats on Windows
typeperf.exe -sc 1 "\Processor Information(_Total)\Processor Frequency"
REM "(PDH-CSV 4.0)","\\DELL_DE_VADIM\Processor Information(_Total)\Processor Frequency"
REM "08/09/2023 13:43:32.695","1358.000000"
typeperf.exe -qx | findstr.exe Frequency
REM \Windows Time Service\Clock Frequency Adjustment (PPB)
REM \Windows Time Service\Clock Frequency Adjustment
REM \Processor Information(0,0)\% of Maximum Frequency
REM \Processor Information(0,1)\% of Maximum Frequency
REM \Processor Information(0,2)\% of Maximum Frequency
@vadimkantorov
vadimkantorov / hist.py
Last active August 5, 2023 23:59
Approximate hist * mult representation in PyTorch
import torch
def dist(histA, histB):
# this min-sum histogram distance is used in Selective SehistArch histAt https://ivi.fnwi.uvhistA.nl/isis/puhistBlichistAtions/2013/UijlingsIJCV2013
return torch.min(histA / histA.sum(dim = -1, keepdim = True), histB / histB.sum(dim = -1, keepdim = True)).sum(dim = -1)
def merge(histA, multA, histB, multB):
hist_int32 = histA * multA + histB * multB
mult_int32 = hist_int32.amax(dim = -1, keepdim = True).div_(255, rounding_mode = 'floor').add_(1) # need to round up or down?
@vadimkantorov
vadimkantorov / csharpfrompython.cs
Last active November 22, 2023 03:01
Run a C# function from Python using Python.NET from https://pythonnet.github.io/pythonnet/python.html Call csharpfrompython.py which first calls the compiler and then calls the functions, feature request of better compiler bindings at https://github.com/pythonnet/pythonnet/issues/2196 ; includes two examples of NumPy -> C# array marshalling
namespace CSharpFromPythonNamespace
{
public class CSharpFromPythonClass
{
public string Hi(string x)
{
return "Hi " + x;
}
public static string Hello(string x)
@vadimkantorov
vadimkantorov / w3redirect.html
Last active June 8, 2023 17:49
Replace URL and title and place into a directory as https://path/to/subscribe/index.html, passes https://validator.w3.org/
<!DOCTYPE html><html charset="utf-8" lang="en"><head><meta http-equiv="refresh" content="0; url=https://path.to/my/url"><title>This Is My Title</title></head></html>
@vadimkantorov
vadimkantorov / printflock.py
Created February 22, 2023 12:36
Print in multi-threaded/multi-process env
# from https://github.com/stas00/toolbox/blob/master/pytorch/all_reduce_bench.py
def printflock(*msgs):
""" print """
with open(__file__, "r") as fh:
fcntl.flock(fh, fcntl.LOCK_EX)
try:
print(*msgs)
finally:
fcntl.flock(fh, fcntl.LOCK_UN)
@vadimkantorov
vadimkantorov / upwork_too_many_redirects.txt
Last active February 20, 2023 10:51
How to contact Upwork.com support if you are hitting errors "Too many redirects" / "Unable to retrieve organization information" when creating a new Upwork account
This Upwork bug has been present for years and Upwork does nothing to fix it or even investigate it:
- https://community.upwork.com/t5/Freelancers/I-can-t-log-in-ERR-TOO-MANY-REDIRECTS/m-p/710733
- https://community.upwork.com/t5/Support-Forum/Invited-colleague-cannot-log-in-to-Upwork/td-p/1154335
In this situation, you cannot log in, and thus cannot even create a normal support ticket.
It seems that the problem appears because Upwork put account-> company association in an invalid state,
and thus something blows up when Upwork tries to fetch the account's company information during login.
I found a few ways to reach Upwork's Support even if you cannot log in:
- Create a support ticket about account/password recovery: https://support.upwork.com/hc/en-us/requests/new?ticket_form_id=360000464433
@vadimkantorov
vadimkantorov / sitemap.py
Last active February 23, 2024 23:29
Print all URLs of a standardized XML sitemap
# https://sitemaps.org/protocol.html
import sys
import xml.dom.minidom
import urllib.request
def sitemapindex_urlset_concat(url):
sitemapindex = xml.dom.minidom.parse(urllib.request.urlopen(url))
for sitemap in sitemapindex.getElementsByTagName('sitemap'):
urlset = xml.dom.minidom.parse(urllib.request.urlopen(sitemap.getElementsByTagName('loc')[0].firstChild.nodeValue))