Skip to content

Instantly share code, notes, and snippets.

@alexshpilkin
alexshpilkin / scrape
Last active June 14, 2018 15:50
Частичный экспорт dir.alumni57.ru в формат sch57.ru
#!/bin/sh -eu
set -o pipefail # FIXME bashism
BASE=http://dir.alumni57.ru
ROOT=$BASE/
LMAP='{ "А": "a", "Б": "b", "В": "v", "Г": "g", "Д": "d", "Е": "e", "К": "k", "М": "m" }'
curl -sS "$ROOT" | pup 'article h2 a:first-child json{}' \
| jq -r '.[] | "\(.text)\t\(.href)"' | sort -nk1 \
| while read year url; do
@alexshpilkin
alexshpilkin / README
Last active June 15, 2023 21:46
Convert the RKN list to a Mikrotik firewall address list
Download the RKN list from https://github.com/zapret-info/z-i, massage it into
a Mikrotik script that manages a firewall address list, and put it up on a web
server. Note well that the list is gigantic---more than 80,000 entries as of
2018-04-28---so be sure to check if your router can handle it in advance (for
example, hAP Lite, with its measly 32M of memory, can’t).
On the router side, do something like
/tool fetch url="https://sheaf.site/rkn.rsc" dst-path=rkn.rsc
:import rkn.src
@alexshpilkin
alexshpilkin / dns
Last active April 29, 2018 21:21
HTTP API for local DNS records in unbound(8)
#!/bin/sh -eu
DOMAIN=lointa.in
JOURNAL=/srv/dns/$DOMAIN
fail() { echo "Status: $1"; echo "Content-Type: text/plain"; echo; echo "$REQUEST_METHOD"; exit; }
if [ -z "$PATH_INFO" ]; then
echo "Status: 308 Permanent Redirect"
echo "Content-Length: 0";
@alexshpilkin
alexshpilkin / download
Last active May 5, 2018 22:09
Download an article from Medium
#!/bin/sh -eu
set -o pipefail
temp=$(mktemp)
trap "rm -f '$temp'" EXIT
curl -sS "$1" \
| pup 'script[src*="main-base.bundle"] + script text{}' \
| sed -Ee '1d;$d' -e 's/window\[[^]]*\]\((.*)\)/\1/' -e 's/\\x3[Cc]/</g' -e 's/\\x3[Ee]/>/g' \
| jq .value >"$temp"
@alexshpilkin
alexshpilkin / aos.sh
Created May 25, 2018 00:56
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 'http://animeonline.su/zend/anime/myvi/index/id/'"$1" \
| sed -Ene 's/.*"url": +"([^"]*)".*/\1/p' | head -1 \
| sed 's|player/embed/html|watch|'
@alexshpilkin
alexshpilkin / convert
Last active May 28, 2018 22:34
Convert Georgian election PDFs into TSV
#!/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 / 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:

@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 / 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 / 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