diff options
Diffstat (limited to '')
| -rwxr-xr-x | aoc | 35 | ||||
| -rwxr-xr-x | aocd | 13 |
2 files changed, 35 insertions, 13 deletions
| @@ -0,0 +1,35 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Set up a working environment for Advent of Code (https://adventofcode.com/). | ||
| 4 | # Requires tmux, lynx, curl and a valid AOC_SESSION_COOKIE session cookie. | ||
| 5 | |||
| 6 | # usage: aoc [yyyy nn] | ||
| 7 | # If yyyy (year) and nn (day, with leading zero if single digit) are not | ||
| 8 | # specified, the current year and day are used. | ||
| 9 | |||
| 10 | editor="vi a.py" | ||
| 11 | basedir="$HOME/src/aoc" | ||
| 12 | lynx_cookie_file="$(mktemp)" | ||
| 13 | clibrowser="lynx -cookie_file=$lynx_cookie_file" | ||
| 14 | |||
| 15 | year="${1:-$(date +'%Y')}" | ||
| 16 | day="${2:-$(date +'%d')}" | ||
| 17 | daynozero="$(echo "$day" | sed 's/^0//')" | ||
| 18 | |||
| 19 | cd "$basedir/$year/$day" | ||
| 20 | |||
| 21 | # Download the puzzle input and save it to input.txt | ||
| 22 | url="https://adventofcode.com/$year/day/$daynozero/input" | ||
| 23 | curl "$url" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
| 24 | |||
| 25 | # Open a tmux session with lynx in its own windows, and an editor and a | ||
| 26 | # terminal in split view. | ||
| 27 | printf 'adventofcode.com\tFALSE\t/\tTRUE\t2079722976\tsession\t%s' \ | ||
| 28 | "$AOC_SESSION_COOKIE" > "$lynx_cookie_file" | ||
| 29 | url="https://adventofcode.com/$year/day/$daynozero" | ||
| 30 | tmux new-session \; \ | ||
| 31 | send-keys "$editor" C-m \; \ | ||
| 32 | split-window -h \; \ | ||
| 33 | select-pane -t 0 \; \ | ||
| 34 | new-window \; \ | ||
| 35 | send-keys "$clibrowser $url" C-m \; | ||
| @@ -1,13 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Download input from the Advent of Code website (https://adventofcode.com/). | ||
| 4 | # Requires setting an AOC_SESSION_COOKIE variable with a valid session cookie. | ||
| 5 | |||
| 6 | # usage: aocd [year n] | ||
| 7 | # If year and n are not specified, the current year and day are used. | ||
| 8 | |||
| 9 | YEAR="${1:-$(date +'%Y')}" | ||
| 10 | DAY="${2:-$(date +'%d' | sed 's/^0//')}" | ||
| 11 | URL="https://adventofcode.com/$YEAR/day/$DAY/input" | ||
| 12 | |||
| 13 | curl "$URL" -H "cookie: session=$AOC_SESSION_COOKIE" -o input.txt | ||
