Skip to content

Instantly share code, notes, and snippets.

View joshbduncan's full-sized avatar

Josh Duncan joshbduncan

View GitHub Profile
@joshbduncan
joshbduncan / javascript-table-search-filter.js
Last active February 28, 2023 16:51
Javascript Table Search Filter
//////////////////////////////////////
// Advanced Table Search Filtererrr //
//////////////////////////////////////
// Setup:
// 1. Page **must** include table with the id "search-table" (only one)
// 2. Page **must** include text input with id "search-input" (only one)
// 3. Table **may** include data-attribute "data-search-ignore-cols"
// that will ignore any columns listed in the data attribute.
// Columns to be ignored must be listed by index number (0-based)
@joshbduncan
joshbduncan / day25.py
Created January 13, 2022 16:20
Advent of Code 2021 - Day 25
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 December 30, 2021 15:46
Advent of Code 2021 - Day 22
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 / day21.py
Created December 29, 2021 16:59
Advent of Code 2021 - Day 21
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 December 24, 2021 16:37
Advent of Code 2021 - Day 19
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 December 23, 2021 03:54
Advent of Code 2021 - Day 18
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 December 21, 2021 16:58
Advent of Code 2021 - Day 17
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 December 19, 2021 16:25
Advent of Code 2021 - Day 15
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 August 4, 2021 17:42
Checking off linked record checkboxes via an Airtable script
// 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 14:52
Highlighting Flask Search Tokens With Javascript
<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>