Skip to content

Instantly share code, notes, and snippets.

View joshbduncan's full-sized avatar

Josh Duncan joshbduncan

View GitHub Profile
@joshbduncan
joshbduncan / textual_data_table_custom_sort.py
Created August 9, 2023 21:10
Custom Sorter for MM-DD-YY Column Type in a Textual DataTable
from operator import itemgetter
from typing import Any, Self
from textual._two_way_dict import TwoWayDict
from textual.app import App, ComposeResult
from textual.events import Click
from textual.widgets import DataTable
from textual.widgets.data_table import CellType, ColumnKey, RowKey
ROWS = [
@joshbduncan
joshbduncan / UngroupUnclipUncompound.jsx
Last active March 1, 2023 17:42
Clean-up junky Ai files by reducing any selected group, compound path, and clipping mask contents to just paths.
/**
* Clean-up junky files by reducing any group, compound path, and clipping mask contents to just paths.
*
* This works no matter how nested the container object are and works for better for weird
* edge cases than trying to remove each element from each container via the API.
*/
var doc = app.activeDocument; // Get active document
var sel = doc.selection; // Get selected items
@joshbduncan
joshbduncan / GoToArtboardExample.jsx
Created January 20, 2023 21:43
Go To Artboard (hacky example)
// Please note this is a hacky example in response to a question
// on the Adobe forums at the link below.
// https://community.adobe.com/t5/illustrator-discussions/using-artboards-as-an-archive-that-is-searchable/td-p/13504883
var aiVersion = parseFloat(app.version);
var locale = $.locale;
var os = $.os;
var sysOS = /mac/i.test(os) ? "mac" : "win";
var windowsFlickerFix = sysOS === "win" && aiVersion < 26.4 ? true : false;
@joshbduncan
joshbduncan / InsetShapesCompoundPath.jsx
Created January 19, 2023 21:31
Ai Create Inset Rectangles and Ellipses
// Create inset rectangles and ellipses and place into compound path
var doc = app.activeDocument;
var al = doc.activeLayer;
// type of path
// var type = "rectangle"
var pathType = "ellipse";
// amount of inset paths (max: 4)
@joshbduncan
joshbduncan / day2.py
Created December 2, 2022 15:54
Advent of Code 2022 - Day 2
def score_round(elf_idx, me_idx):
if elf_idx == me_idx: # draw
return me_idx + 1 + 3
elif me_idx % 3 != (elf_idx + 2) % 3: # win
return me_idx + 1 + 6
else:
return me_idx + 1 # lose
data = open("day2.in").read()
@joshbduncan
joshbduncan / AiCommandPalette-NO-ACTIONS.jsx
Created August 8, 2022 14:38
Ai Command Palette Error Test - Excluded Actions Options
/*
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 August 8, 2022 14:37
Ai Command Palette Error Test - Excluded Menu Options
/*
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 April 1, 2022 15:37
Progress Spinner Using Objects and Generators
import sys
import time
spinners = {
"angles": ["◢", "◣", "◤", "◥"],
"circle": ["◜", "◠", "◝", "◞", "◡", "◟"],
"dots": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
"ticks": ["-", "\\", "|", "/"],
}
@joshbduncan
joshbduncan / spinner_ctxmanager.py
Created April 1, 2022 15:22
Progress Spinner Using Python Context Manager and Generators
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 April 1, 2022 15:18
Simple Progress Spinner Using Python Generators
import sys
import time
def spinner(msg="working..."):
i = 0
ticks = ["-", "\\", "|", "/"]
try:
while True:
tick = ticks[i % len(ticks)]