Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Duncan joshbduncan

View GitHub Profile
@joshbduncan
joshbduncan / AiCommandPalette-NO-ACTIONS.jsx
Created Aug 8, 2022
Ai Command Palette Error Test - Excluded Actions Options
View AiCommandPalette-NO-ACTIONS.jsx
/*
Ai Command Palette
Copyright 2022 Josh Duncan
https://joshbduncan.com
This script is distributed under the MIT License.
See the LICENSE file for details.
*/
// TODO: add the ability to edit custom commands
@joshbduncan
joshbduncan / AiCommandPalette-NO-MENU
Created Aug 8, 2022
Ai Command Palette Error Test - Excluded Menu Options
View AiCommandPalette-NO-MENU
/*
Ai Command Palette
Copyright 2022 Josh Duncan
https://joshbduncan.com
This script is distributed under the MIT License.
See the LICENSE file for details.
*/
// TODO: add the ability to edit custom commands
@joshbduncan
joshbduncan / spinner_object.py
Last active Apr 1, 2022
Progress Spinner Using Objects and Generators
View spinner_object.py
import sys
import time
spinners = {
"angles": ["◢", "◣", "◤", "◥"],
"circle": ["◜", "◠", "◝", "◞", "◡", "◟"],
"dots": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
"ticks": ["-", "\\", "|", "/"],
}
@joshbduncan
joshbduncan / spinner_ctxmanager.py
Created Apr 1, 2022
Progress Spinner Using Python Context Manager and Generators
View spinner_ctxmanager.py
import sys
import time
from contextlib import contextmanager
def spinner_indicator(msg):
ticks = ["-", "\\", "|", "/"]
i = 0
while True:
tick = ticks[i % len(ticks)]
@joshbduncan
joshbduncan / spinner_simple.py
Created Apr 1, 2022
Simple Progress Spinner Using Python Generators
View spinner_simple.py
import sys
import time
def spinner(msg="working..."):
i = 0
ticks = ["-", "\\", "|", "/"]
try:
while True:
tick = ticks[i % len(ticks)]
View javascript-table-search-filter.js
////////////////////////////////////
// Simple 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 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 / 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(",")]))