Snippets

Reuseable code snippets collected by me

Retry 429 with backoff + pool

Stay under the NetSuite account concurrency limit and recover from 429 Too Many Requests

Upsert by external ID

Create or update a record in one call, so retries never create duplicates

NetSuite MCP custom tool

The three files a custom MCP tool needs: CustomTool script, JSON-RPC schema, and toolset SDF object

NetSuite M2M access token

Client credentials flow with a PS256-signed JWT and an in-memory token cache, no JWT library

Map/Reduce SuiteQL input

Feed a Map/Reduce script straight from SuiteQL and summarize errors properly

NetSuite TBA auth header

OAuth 1.0a HMAC-SHA256 signature for NetSuite token-based authentication, no dependencies

SuiteQL keyset pagination

Page through any number of SuiteQL rows with keyset pagination instead of offset

Paged SuiteQL in SuiteScript

Read more than 5,000 SuiteQL rows inside a script with query.runSuiteQLPaged

useAsync

Custom hooks to use an async effect

Validate color

Check if a string is a valid color

Shuffle an array

Shuffle an array in Javascript

Find and kill process on port

Find what process is running on given port and stop it (MacOS)

Code block syntax notes

Markdown Code block's basic and advanced syntax

Event Emitter

Simple Event Emitter or PubSub pattern

+/- days in Liquid

Adding/substracting days in Shopify's Liquid template language

Read files names

Read all file names inside a folder

toPlainEnglish

Replace all VNese letters with the corresponding English accents

.gitignore

Keep 1 file and ignore others in a directory

useLocalStorageState

Custom hooks to use local storage state