Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Duncan joshbduncan

View GitHub Profile
@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 / 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 / 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:
View make_banner.py
def make_banner(txt: str, padding: int = 5, border: str = '*') -> str:
return (
f'{border * (len(txt) + padding * 2)}\n'
f'{" " * padding}{txt}\n'
f'{border * (len(txt) + padding * 2)}'
)
banner = make_banner('Banner as a variable', 4, '#')
print(banner)
View aoc2020-day18.py
def calc1(line):
nums = [int(x) for x in line if x not in ['+', '*']]
ops = [x for x in line if x in ['+', '*']]
total = nums.pop(0)
for n in nums:
if ops == []:
break
else:
total = eval(str(total) + ops.pop(0) + str(n))
View aoc2020-day17.py
def p1(active):
for _ in range(6):
new = set()
xvals = [x[0] for x in active]
yvals = [y[1] for y in active]
zvals = [z[2] for z in active]
for x in range(min(xvals) - 1, max(xvals) + 2):
for y in range(min(yvals) - 1, max(yvals) + 2):
for z in range(min(zvals) - 1, max(zvals) + 2):