Skip to content

Instantly share code, notes, and snippets.

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