Skip to content

Instantly share code, notes, and snippets.

@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):
View aoc2020-day15-v2.py
def solve(match):
pdict = {}
for i, p in enumerate(data):
pdict[int(p)] = i + 1
turn = len(pdict) + 1
same = 0
while turn < match:
View aoc2020-day15.py
# read in aoc input
data = open("day15.in").read().strip().split(',')
def solve(match):
# add starting numbers to dict for tracking
pdict = {}
for i, p in enumerate(data):
pdict[int(p)] = [i + 1]
View aoc2020-day13.py
# read in aoc input and setup to vars from instructions
time = int(open("day13.in").read().strip().split()[0])
buses = open("day13.in").read().strip().split()[1].split(',')
departures = {}
# part 1
for bus in buses:
if bus != 'x':
bus_id = int(bus)
# calculate closest departure to your time for each bus
View aoc2020-day9.py
# read in aoc input
data = open("day9.in").read().strip().split('\n')
# setup vars to track
pre = 25
pos = 25
# solve for part 1
while True:
p1 = int(data[pos])