Skip to content

Instantly share code, notes, and snippets.

View oliora's full-sized avatar

Andrey Upadyshev oliora

View GitHub Profile
@oliora
oliora / timestamp.sh
Created November 8, 2022 14:58
Shell timestamp conversion aliases
alias to-timesptamp-ms="python3 -c 'import datetime, sys; s = sys.argv[1]; s = s[:-1] if s[-1] == \"Z\" else s; print(round(datetime.datetime.fromisoformat(s).replace(tzinfo=datetime.timezone.utc).timestamp() * 1000))'"
alias from-timesptamp-ms="python3 -c 'import datetime, sys; t = int(sys.argv[1]); print(datetime.datetime.utcfromtimestamp(t/1000).strftime(\"%Y-%m-%dT%H:%M:%S.%f\")[:-3]+\"Z\")'"from-timesptamp-ms
@oliora
oliora / strlen.h
Last active August 3, 2023 10:43
Primitive AVX2 strlen implementation in C++
#pragma once
#include "common.h" // https://github.com/oliora/habr-switches-perf-test/blob/main/common.h
#include <cstdint>
#include <string_view>
#include <utility>
#include <immintrin.h>
template <size_t StepSize>
requires((StepSize <= PageSize)
@oliora
oliora / udp-send.py
Last active August 11, 2023 13:21
Trivial UDP sender in Python
# Run it like `python3 udp-send.py <detination_addr> <destination_port> [<interface_to_bind>]`
import socket
import sys
with socket.socket(type=socket.SOCK_DGRAM) as s:
if len(sys.argv) >= 4:
s.bind((sys.argv[3], 0))
s.connect((sys.argv[1], int(sys.argv[2])))
s.send(b'Hello!')
@oliora
oliora / udp-receiver.py
Last active August 3, 2023 10:42
Trivial UDP receiver in Python
# Run it like `python3 udp-receiver.py 0.0.0.0 <listening_port>`
import socket
import sys
with socket.socket(type=socket.SOCK_DGRAM) as s:
s.bind((sys.argv[1], int(sys.argv[2])))
while True:
(data, ancdata, msg_flags, address) = s.recvmsg(1024)
print(f'Received "{data.decode()}", ancdata="{ancdata}", sender={address}, flags={msg_flags}')
@oliora
oliora / extract_tables_from_pdf.py
Last active December 21, 2024 16:06
Extract tables from PDF into CSV
#!/usr/bin/env python3
'''
Usage (on Mac):
Extract tables to clipboard. Simply paste it to Google Spreadsheets afterwards:
python3 extract_tables_from_pdf.py ~/Downloads/doc.pdf" --remove-eols --pages '27-30' | pbcopy
Extract to a file: