Skip to content

Instantly share code, notes, and snippets.

alexshpilkin / ruforum
Last active Apr 3, 2019
Scrape forums
View ruforum
#!/bin/sh -eu
set -o pipefail
tracef() {
fmt=$1; shift
if [ -t 2 ]; then printf '\033[0K%s'"$fmt"'\r' "$TRACE" "$@" >&2; fi
trap 'tracef ""' EXIT
alexshpilkin /
Last active Apr 2, 2019
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 / push
Last active Mar 31, 2019
Watch the Ukrainian CVK website and send push notifications
View push
#!/bin/sh -eu
if [ "$#" -ne 2 ]; then
echo "usage: $0 TOKEN ORIGIN" >&2
exit 1
jq -ac --unbuffered --arg token "$1" --arg origin "$2" \
'{"recipient_token": $token, "text": ., "origin": $origin}' | \
alexshpilkin / change
Last active Feb 5, 2019
Convert between Transtool and GNU gettext files
View change
#!/bin/sh -eu
po=$(printf %s *.??.po)
detail=false; if [ "x${1-}" = x-d ]; then detail=true; shift; fi
prev=; next=; diff=
trap 'rm -f "$prev" "$next" "$diff"' EXIT
prev=$(mktemp); next=$(mktemp); diff=$(mktemp)
alexshpilkin / Makefile
Created Nov 23, 2018
Blocked fraction as function of domain length
View Makefile
.PHONY: all clean
all: blocked.png blocked.svg
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 /
Last active Oct 25, 2018
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 /
Last active Sep 25, 2018
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 /
Created Jun 7, 2018
Keybase verification

Keybase proof

I hereby claim:

  • I am alexshpilkin on github.
  • I am alexshpilkin ( on keybase.
  • I have a public key ASAbZo8Qp8U-zCBRPlyofF38flV9f0EAAp_LQXFMwtwrgwo

To claim this, I am signing this object:

alexshpilkin / convert
Last active May 28, 2018
Convert Georgian election PDFs into TSV
View convert
#!/bin/sh -eu
set -o pipefail # FIXME bashism
pdftotext -q -layout "$1" - \
| iconv -t iso8859-1//translit | iconv -f georgian-ps \
| "$"
alexshpilkin /
Created May 25, 2018
Download series from AOS
#!/bin/sh -eu
set -o pipefail
# mkdir sub; for file in *.mp4; do n=${file#*#}; n=${n%% *}; mv "$file" "sub/$(printf '%02d - Episode %d.mp4' $n $n)"; done
myvi() {
youtube-dl -c -R inf --socket-timeout 1 -o "$2" $(
curl -sS ''"$1" \
| sed -Ene 's/.*"url": +"([^"]*)".*/\1/p' | head -1 \
| sed 's|player/embed/html|watch|'