Skip to content

Instantly share code, notes, and snippets.

@kerrishotts
kerrishotts / manual-workaround.js
Created Oct 13, 2021
Setting UXP textfield value manual workaround
View manual-workaround.js
const numberField = document.querySelector("sp-textfield[type=number]");
numberField.value = `${numberOfSteps}`; /* template literals will work */
numberField.value = "" + numberOfSteps; /* or you can do this. */
@kerrishotts
kerrishotts / setting-value.js
Created Oct 13, 2021
UXP setting sp-textfield value issue
View setting-value.js
const numberField = document.querySelector("sp-textfield[type=number]");
numberField.value = 10; /* won't work; field will be blank */
numberField.value = "10"; /* will work. */
@kerrishotts
kerrishotts / decimal-workaround.js
Last active Oct 13, 2021
Numeric sp-textfield issues & buggyfill
View decimal-workaround.js
(function () {
function fixNumericSpTextField() {
if(require("uxp").versions.uxp.startsWith("uxp-5.5.1")) {
const candidates = document.querySelectorAll("sp-textfield[type=number]");
candidates.forEach(el => {
el.setAttribute("type", "text");
el.setAttribute("data-uxp-type", "number");
});
}
document.addEventListener("input", evt => {
@kerrishotts
kerrishotts / fix-change-event.js
Created Oct 13, 2021
Buggyfill for sp-textfield not firing `change` event
View fix-change-event.js
(function () {
if(require("uxp").versions.uxp.startsWith("uxp-5.5.1")) {
let curField, curValue;
document.addEventListener("focus", evt => {
curField = evt.target;
curValue = curField.value;
}, true);
document.addEventListener("blur", evt => {
if (evt.target.tagName === "SP-TEXTFIELD") {
if (curField === evt.target) {
@kerrishotts
kerrishotts / README.md
Last active Mar 14, 2021
Pitch-based Velocity Mapper for Logic Pro X / Mainstage
View README.md
@kerrishotts
kerrishotts / Schedule.md
Created Dec 8, 2020
WCTD: Level II Training Content & Schedule
View Schedule.md

Session 1

Introduction and Prerequisites

A quick overview of what we'll be covering, and what you're expected to already know, including:

  • Basic HTML tags
  • CSS Syntax
  • Interacting with the DOM
  • Variables
@kerrishotts
kerrishotts / support.csv
Last active Nov 19, 2020
Support Matrix for in-app Extensibility
View support.csv
Extensibility Feature Intel Windows ARM Apple silicon (Rosetta 2) Apple silicon (Native)
C++ Plugins ✅ (Recompile) ✅ (Recompile)
CEP on Photoshop ⛔️ ⛔️
CEP on all other apps
Extend Script (& ScriptUI) on all apps)
Generator (Ps-only) ⛔️ ⛔️
UXP
@kerrishotts
kerrishotts / tokenizer.js
Created Jul 11, 2020
JS Code from Building a Basic Interpreter, '80s Style Part 2
View tokenizer.js
const tokens = ["CLS", "PRINT", ":" ];
function tokenize(inStr) {
let out = []; // return value is "crunched" array
let idx = 0; // index into inStr
let ch = ""; // current character
while (idx < inStr.length) {
ch = inStr.charCodeAt(idx); // get the current character code
if (ch >= 48 && ch <= 57) { // NUMERIC LITERAL
out.push (0xFD);
@kerrishotts
kerrishotts / 80.js
Created Oct 1, 2019
Dev.to Daily Challenge #80
View 80.js
// my JS engine doesn't have String.prototype.matchAll just yet
// so providing my own generator to do the same thing
function *matchAll(str, re) {
let match;
do {
match = re.exec(str); // get the first match of the regular expession
if (match) yield match; // if we have one, yield it
} while (match != null); // keep going until no more matches
}
@kerrishotts
kerrishotts / 2019-Sep-16.js
Created Sep 16, 2019
2019-Sep-16 Dev.to Challenge (Grade Book)
View 2019-Sep-16.js
const sum = (...nums) => nums.reduce((total, cur) => total + cur, 0);
const meanGrade = (...grades) => sum(...grades) / grades.length;
const letterForGrade = grade => {
const lastDigit = grade % 10;
const gradeLetter = Object.entries({90: "A", 80: "B", 70: "C", 60: "D", 0: "F"})
.sort(([a], [b]) => a < b)
.find(([minGrade]) => grade >= minGrade)
[1] + ((lastDigit < 5) ? "-" :
(lastDigit > 5) ? "+" : "");
return gradeLetter;