Skip to content

Instantly share code, notes, and snippets.

@joshbduncan
joshbduncan / day25.py
Created Jan 13, 2022
Advent of Code 2021 - Day 25
View day25.py
from collections import defaultdict
data = open("day25.in").read().strip().split("\n")
tracker = defaultdict(str)
rows = len(data)
cols = len(data[0])
for r, line in enumerate(data):
for c, d in enumerate(line):
if d != ".":
@joshbduncan
joshbduncan / day22.py
Last active Dec 30, 2021
Advent of Code 2021 - Day 22
View day22.py
from collections import defaultdict
def cube_vol(b):
x1, x2 = b[0]
y1, y2 = b[1]
z1, z2 = b[2]
return (abs(x2 - x1) + 1) * (abs(y2 - y1) + 1) * (abs(z2 - z1) + 1)
@joshbduncan
joshbduncan / day18.py
Created Dec 23, 2021
Advent of Code 2021 - Day 18
View day18.py
import itertools
import math
import re
def add(data):
if " + " in data:
data = f"[{data.split(' + ')[0]},{data.split(' + ')[1]}]"
return data
@joshbduncan
joshbduncan / day21.py
Created Dec 29, 2021
Advent of Code 2021 - Day 21
View day21.py
import functools
import itertools
data = open("day21.in").read().strip().split("\n")
# part 1
p1, p2 = int(data[0][-1]), int(data[1][-1])
s1 = s2 = 0
die = rolls = 0
@joshbduncan
joshbduncan / day19.py
Created Dec 24, 2021
Advent of Code 2021 - Day 19
View day19.py
from collections import defaultdict
def parse(data):
scanners = []
for scanner in data:
beacons = []
for line in scanner.split("\n"):
if "--" not in line:
beacons.append(tuple([int(c) for c in line.split(",")]))
@joshbduncan
joshbduncan / day17.py
Created Dec 21, 2021
Advent of Code 2021 - Day 17
View day17.py
from collections import defaultdict
data = open("day17.in").read().strip()
x_range, y_range = data.split(": ")[1].split(", ")
x_lower, x_upper = x_range.split("=")[1].split("..")
x_lower, x_upper = int(x_lower), int(x_upper)
y_lower, y_upper = y_range.split("=")[1].split("..")
y_lower, y_upper = int(y_lower), int(y_upper)
@joshbduncan
joshbduncan / day15.py
Created Dec 19, 2021
Advent of Code 2021 - Day 15
View day15.py
import heapq
from collections import defaultdict
def solve(tiles):
rows, cols = size_y * tiles, size_x * tiles
costs = defaultdict(int)
pqueue = [(0, 0, 0)]
heapq.heapify(pqueue)
@joshbduncan
joshbduncan / checking-linked-records-in-airtable.js
Created Aug 4, 2021
Checking off linked record checkboxes via an Airtable script
View checking-linked-records-in-airtable.js
// get the two tables I need to work on
let jobsTable = base.getTable("Jobs");
let timeEntriesTable = base.getTable("Time Entries");
// get all time entries for later reference
let timeEntriesQuery = await timeEntriesTable.selectRecordsAsync();
// when run via button, automatically use that record otherwise choose
let record = await input.recordAsync('Choose a record', jobsTable);
// get all linked time entries for record
let linkedTimeEntries = record.getCellValue("Time Entries") || [];
output.text("Found " + linkedTimeEntries.length + " total time entries");
@joshbduncan
joshbduncan / token_highlighter.html
Last active May 5, 2021
Highlighting Flask Search Tokens With Javascript
View token_highlighter.html
<html>
<head>
<title>Flask Search Token Highlighter Javascript</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<style>
.quote-list {max-width: 42em; padding-top: 3em;}
</style>
</head>
View todoist-2-things.py
import os
import webbrowser
from datetime import datetime
from dotenv import load_dotenv
from todoist.api import TodoistAPI
load_dotenv()
try: