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 / timezone_localtime_to_cet.py
Last active March 9, 2024 13:56
Given a list of "lat,lng" prints a local timestamp (20h) in all of the timezones
# python -m pip install timezonefinder pytz --user
import timezonefinder
import pytz
import datetime
latlnglist = '''
43.0010092,41.0208743
42.9972303,41.0089412
43.0125911,40.9705287
42.9991332,41.0408331
@vadimkantorov
vadimkantorov / example_leaflet_openstreetmap.html
Last active March 9, 2024 11:43
Example of using LeafletJS map with OpenStreetMap tiles to display a list of events using circle markers and simple popups
<html><body>
<link href="https://tile.openstreetmap.org/{z}/{x}/{y}.png" id="link_tiles" />
<!--
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"
@vadimkantorov
vadimkantorov / socialmediacard.py
Created February 28, 2024 16:00
Fetches meta/og social media tags from a URL (based on https://gist.github.com/vstoykov/6028987 and upgraded for python3)
# based on https://gist.github.com/vstoykov/6028987
# python socialmediacard.py 'https://meduza.io/feature/2024/02/28/ya-sdelayu-vse-chtoby-zlo-otstupilo-a-prekrasnoe-buduschee-prishlo'
import html.parser
import urllib.request
class SeoParser(html.parser.HTMLParser):
CONTENT_TAGS = ('p', 'h1', 'h2', 'h3', 'h4')
ALLOWED_INLINE_TAGS = ('b', 'u', 'strong', 'em', 'br')
@vadimkantorov
vadimkantorov / sed.sh
Created January 30, 2024 18:33
Various sed tricks
# excel opens correctly only utf16 with BOM with tab separator or utf8 with bom with comma separator
sed '1s/^\(\xef\xbb\xbf\)\?/\xef\xbb\xbf/' will_prepend_bom_to_utf8_file_if_it_does_not_have_bom_yet.csv
@vadimkantorov
vadimkantorov / spellcheck.sh
Created January 30, 2024 12:43
Examples of using aspell, hunspell etc
printf "Привет, bonjour, hello\nasdasd" > test.txt
sudo apt install hunspell hunspell-ru hunspell-fr
hunspell -l -d en_US,ru_RU,fr_FR text.txt
sudo apt install aspell aspell-ru
aspell list --lang=ru < README.md
aspell check README.md
@vadimkantorov
vadimkantorov / dataurifycss.py
Last active January 11, 2024 17:07
Embed resources into CSS
# python3 dataurifycss.py -i assets/main.3cfd67ba.css --delete > assets/main.css
import os
import argparse
import re
import sys
import base64
parser = argparse.ArgumentParser()
parser.add_argument('--input-css-path', '-i')
@vadimkantorov
vadimkantorov / .github_workflows_web.yml
Created January 4, 2024 14:53
Example GitHub Workflow for downloading run artifacts and pushing to gh-pages
name: web
on:
workflow_dispatch:
inputs:
build_runid:
description: 'build_runid'
required: true
default: '7410445048'
permissions: write-all
@vadimkantorov
vadimkantorov / grep.sh
Created January 1, 2024 10:40
Various grep tricks
# print only attribute values for class="notion-color-gray" and similar
grep -o \"notion-color-[^\"]*\" test.html
@vadimkantorov
vadimkantorov / find.sh
Last active January 1, 2024 10:40
Various find tricks
# cat all files not in .git directory
find -not -iwholename '*.git*' -type f -exec cat {} +
# cat all tsx files not in .git directory with file name section header
find -not -iwholename '*.git*' -type f -name '*.tsx' -exec tail --lines=+1 {} +
# unpack several downloaded tar files and then delete the original archives
find -name '*.tar.gz' -type f -exec tar -xf {} \; -delete
# search recursively in all CMakeLists.txt files a substring 1.78
@vadimkantorov
vadimkantorov / readwiktionary.py
Last active February 19, 2024 21:49
Read Wiktionary dump in Python
# https://dumps.wikimedia.org/wikidatawiki/entities/ https://dumps.wikimedia.org/ruwiktionary/ https://dumps.wikimedia.org/ruwiktionary/20231201/
#
# wget -L https://dumps.wikimedia.org/wikidatawiki/entities/20231213/wikidata-20231213-lexemes.json.bz2 https://dumps.wikimedia.org/ruwiktionary/20231201/ruwiktionary-20231201-pages-meta-current.xml.bz2
# bzcat wikidata-20231213-lexemes.json.bz2 | wc -l # 1198580
# bzcat wikidata-20231213-lexemes.json.bz2 | head -n 2
# bzcat ruwiktionary-20231201-pages-meta-current.xml.bz2 | wc -l # 196257893
# bzcat ruwiktionary-20231201-pages-meta-current.xml.bz2 | head -n 100
# bzgrep '<page>' ruwiktionary-20231201-pages-meta-current.xml.bz2 | wc -l # 2814450
# time python3 readwiktionary.py ruwiktionary-20231201-pages-meta-current.xml.bz2 ruwiktionary-20231201-pages-meta-current.xml.bz2 # real 11m15.868s # user 9m36.938s # sys 0m5.656s