Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / mplalign.py
Last active March 21, 2018 20:08
Align vertical labels in subplots
#!/usr/bin/env python
import matplotlib.pyplot as plt
import random
import matplotlib.gridspec as gridspec
random.seed(20)
data1 = [random.random() for i in range(10)]
data2 = [random.random()*1000 for i in range(10)]
@alexshpilkin
alexshpilkin / 8086.fth
Last active January 2, 2018 21:00
Postfix 8086 assembler in Forth
oct
( register / memory )
: reg/mem? ( m -- ? ) 70 and 0 = ;
: ?reg/mem ( m -- m )
dup 70 and 0 <> ?abort" reg/mem? " ;
: ?memory ( m -- m )
dup 70 and 0 <> over 300 and 300 = ?abort" memory? " ;
@alexshpilkin
alexshpilkin / beta.1
Last active September 14, 2018 20:37
Sample binomial distributions
.TH BETA 1 2018 "Alexander Shpilkin"
.SH NAME
beta \- sample binomial distributions
.SH SYNOPSIS
\fBbeta \fIcount
.SH DESCRIPTION
Given a population size \fIN\fR and a sample \fIn\fR from a binomial
distribution with parameters (\fIN\fR, \fIp\fR), \fIbeta\fR computes
\fIcount\fR more samples from it, assuming a uniform Bayesian prior for the
unknown parameter \fIp\fR.

Keybase proof

I hereby claim:

  • I am alex-shpilkin 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: