Skip to content

Instantly share code, notes, and snippets.

@alexshpilkin
alexshpilkin / ruforum
Last active Apr 3, 2019
Scrape rutracker.org forums
View ruforum
#!/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 Apr 2, 2019
Write data from stdin to a ZIP file on the fly
View datafile.py
#!/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 Mar 31, 2019
Watch the Ukrainian CVK website and send push notifications
View push
#!/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 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
base=${1-/dev/null}
prev=; next=; diff=
trap 'rm -f "$prev" "$next" "$diff"' EXIT
prev=$(mktemp); next=$(mktemp); diff=$(mktemp)
@alexshpilkin
alexshpilkin / Makefile
Created Nov 23, 2018
Blocked fraction as function of domain length
View Makefile
.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 Oct 25, 2018
Recursively download directories with Apache listings
View apache.sh
#!/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 Sep 25, 2018
Replication of the Russian perevertysh
View _murom.py
#!/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 Jun 7, 2018
Keybase verification
View keybase.md

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:

@alexshpilkin
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 \
| "$0.post"
@alexshpilkin
alexshpilkin / aos.sh
Created May 25, 2018
Download series from AOS
View aos.sh
#!/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 'http://animeonline.su/zend/anime/myvi/index/id/'"$1" \
| sed -Ene 's/.*"url": +"([^"]*)".*/\1/p' | head -1 \
| sed 's|player/embed/html|watch|'