Skip to content

Instantly share code, notes, and snippets.

@alexshpilkin
alexshpilkin / drv.wsdl
Last active February 3, 2023 23:25
Access SOAP APIs of the Ukrainian DRV with Python and Zeep
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://www.drv.gov.ua/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://www.drv.gov.ua/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.drv.gov.ua/">
@alexshpilkin
alexshpilkin / aggregate.py
Last active April 14, 2019 20:12
Aggregate multiple CVK scrapes into precinct histories
#!/usr/bin/env python3
# NB Depends on dict preserving the insert order (CPython >= 3.6, PyPy all)
from csv import DictReader
from datetime import datetime as DateTime
from os import scandir
from simplejsonseq import dump
from sys import argv, stderr, stdout
import ietfcsv # ietf-tab CSV dialect
@alexshpilkin
alexshpilkin / ruforum
Last active April 3, 2019 17:52
Scrape rutracker.org forums
#!/bin/sh -eu
set -o pipefail
TRACE=${TRACE-}; export TRACE
tracef() {
fmt=$1; shift
if [ -t 2 ]; then printf '\033[0K%s'"$fmt"'\r' "$TRACE" "$@" >&2; fi
}
trap 'tracef ""' EXIT
@alexshpilkin
alexshpilkin / datafile.py
Last active April 2, 2019 20:31
Write data from stdin to a ZIP file on the fly
#!/usr/bin/env python3
from collections import deque as Deque
from zipstream import ZipFile
class Buffer:
def __init__(self):
self.queue = Deque()
self.finished = False
@alexshpilkin
alexshpilkin / push
Last active March 31, 2019 18:57
Watch the Ukrainian CVK website and send push notifications
#!/bin/sh -eu
ENDPOINT="https://middleman.ferdinand-muetsch.de/api/messages"
if [ "$#" -ne 2 ]; then
echo "usage: $0 TOKEN ORIGIN" >&2
exit 1
fi
jq -ac --unbuffered --arg token "$1" --arg origin "$2" \
'{"recipient_token": $token, "text": ., "origin": $origin}' | \
@alexshpilkin
alexshpilkin / change
Last active February 5, 2019 13:38
Convert between Transtool and GNU gettext files
#!/bin/sh -eu
po=$(printf %s *.??.po)
detail=false; if [ "x${1-}" = x-d ]; then detail=true; shift; fi
base=${1-/dev/null}
prev=; next=; diff=
trap 'rm -f "$prev" "$next" "$diff"' EXIT
prev=$(mktemp); next=$(mktemp); diff=$(mktemp)
@alexshpilkin
alexshpilkin / Makefile
Created November 23, 2018 19:29
Blocked fraction as function of domain length
.PHONY: all clean
all: blocked.png blocked.svg
clean:
rm -f backorder.hist ru.hist blocked.png blocked.svg
blocked.png blocked.svg: blocked ru.hist backorder.hist
./$<
backorder.hist: backorder.csv hist
@alexshpilkin
alexshpilkin / apache.sh
Last active October 25, 2018 22:09
Recursively download directories with Apache listings
#!/bin/sh -eu
# FIXME doesn't do URL decoding
list=; trap 'rm -f "$list"' EXIT; list=$(mktemp)
url=$1; path=${2-}
echo "DIR $path"
curl -sSL# -o "$list" "$url"
<"$list" pup 'pre img:not([alt="[DIR]"]) + a attr{href}' | tail +2 | \
@alexshpilkin
alexshpilkin / _murom.py
Last active September 25, 2018 14:30
Replication of the Russian perevertysh
#!/usr/bin/env python3
from matplotlib import pyplot as plt
from numpy import arange
def find(func, iterable):
result = None
for i, elem in enumerate(iterable):
if func(elem):
assert result is None
@alexshpilkin
alexshpilkin / keybase.md
Created June 7, 2018 04:47
Keybase verification

Keybase proof

I hereby claim:

  • I am alexshpilkin on github.
  • I am alexshpilkin (https://keybase.io/alexshpilkin) on keybase.
  • I have a public key ASAbZo8Qp8U-zCBRPlyofF38flV9f0EAAp_LQXFMwtwrgwo

To claim this, I am signing this object: