Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / aoc2021_day8.fish
Last active December 9, 2021 15:55
Advent of Code 2021 - Day 8
function day8 \
--description "https://adventofcode.com/2021/day/8 - usage: day8 part1 datafile.dat" \
--argument-names part datafile
test -f "$datafile"; or echo >&2 "file expected" && return 1
set part (string match --regex '.$' $part)
day8part$part $datafile
end
@mattmc3
mattmc3 / aoc2021_day7.fish
Created December 7, 2021 15:41
Advent of Code 2021 - Day 7
function aoc2021_day7 \
--description "https://adventofcode.com/2021/day/7 - usage: aoc2021_day7 part1 datafile.dat" \
--argument-names part datafile
test -f "$datafile"; or echo >&2 "file expected" && return 1
set part (string match --regex '.$' $part)
set --local crab_alignment (string split ',' <$datafile)
set --local possible_positions (echo $crab_alignment | tr ' ' '\n' | sort -n | uniq)
set --local min_pos (echo $possible_positions | tr ' ' '\n' | sort -n | head -n 1)
set --local max_pos (echo $possible_positions | tr ' ' '\n' | sort -n | tail -n 1)
@mattmc3
mattmc3 / day6.fish
Last active December 6, 2021 19:54
Advent of Code - Day 6
function day6 \
--description "https://adventofcode.com/2021/day/6 - usage: day6 part1 datafile.dat" \
--argument-names part datafile
test -f "$datafile"; or echo >&2 "file expected" && return 1
set part (string match --regex '.$' $part)
set --local total_days (test $part -eq 1 && echo 80 || echo 256)
set --local lantern_fish_timers (string split ',' <$datafile)
set --local new_fish_each_day (string split '' (string repeat -n $total_days 0))
@mattmc3
mattmc3 / day5.fish
Created December 5, 2021 16:23
Advent of Code - Day 5
function day5 \
--description "https://adventofcode.com/2021/day/5#part2 - usage: day5 part1 datafile.dat" \
--argument-names part datafile
test -f "$datafile" || or set datafile (realpath (status dirname)/../data/day5.dat)
set part (string match --regex '.$' $part)
#day5-sanitychecks $datafile
# make a temp file of all points
set --local data (cat $datafile)
@mattmc3
mattmc3 / day4.fish
Created December 4, 2021 22:08
Advent of Code 2021 - Day 4
function day4 \
--description "https://adventofcode.com/2021/day/4 - usage: day4 part1 datafile.dat" \
--argument-names part datafile
set part (string match --regex '.$' $argv[1])
if test "$part" -ne 1 && test "$part" -ne 2
echo "Expecting part number 1 or 2 '$part'" >&2 && return 1
end
test -n "$datafile"; \
or set datafile (realpath (status dirname)/../data/day4.dat)
@mattmc3
mattmc3 / day3.fish
Last active December 3, 2021 18:14
Advent of Code 2021 - Day 3
function day3 \
--description "https://adventofcode.com/2021/day/3 - usage: day3 part1 datafile.dat" \
--argument-names part datafile
set part (string match --regex '.$' $argv[1])
if test "$part" -ne 1 && test "$part" -ne 2
echo "Expecting part number 1 or 2 '$part'" >&2 && return 1
end
test -n "$datafile"; \
or set datafile (realpath (status dirname)/../data/day3.dat)
@mattmc3
mattmc3 / day2.fish
Last active December 2, 2021 18:17
Advent of code 2021 - Day2
function day2 \
--description "https://adventofcode.com/2021/day/2: `usage - day2 1 data.txt`" \
--argument-names part datafile
if test "$part" -ne 1 && test "$part" -ne 2
echo "Expecting part number 1 or 2 '$part'" >&2 && return 1
end
set --global horizontal_position 0
set --global depth_position 0
@mattmc3
mattmc3 / day1.fish
Created December 2, 2021 05:25
2021 Advent of Code - Day 1
function day1part1 \
--description "https://adventofcode.com/2021/day/1"
set --local inputfile (realpath (status dirname)/day1_input.txt)
set --local depth_data (cat $inputfile)
set --local depth_increased_counter 0
set --local depth_decreased_counter 0
set --local depth_same_counter 0
set --local previous_measurement $depth_data[1]
for index in (seq 2 (count $depth_data))
@mattmc3
mattmc3 / stackoverflow.tampermonkey.js
Created August 2, 2021 00:57
Tampermonkey - StackOverflow
// ==UserScript==
// @name stackoverflow tampering
// @namespace http://tampermonkey.net/
// @version 0.1
// @description StackOverflow - hide #hot-network-questions and deleted stuff.
// @author mattmc3
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// @match https://*.stackoverflow.com/*
// @match https://*.stackexchange.com/*
@mattmc3
mattmc3 / colorize_tap.awk
Last active January 22, 2021 22:44
awk TAP colorizer
#!/usr/bin/env -S awk -f
# https://testanything.org
BEGIN {
CYAN="\033[0;36m"
GREEN="\033[0;32m"
RED="\033[0;31m"
BRIGHTGREEN="\033[1;92m"
BRIGHTRED="\033[1;91m"
NORMAL="\033[0;0m"