Skip to content

Instantly share code, notes, and snippets.

@haysclark
haysclark / ExtendScript.d.ts
Last active November 5, 2024 09:24
Illustrator 26.0.3 TypeScript types for use with Adobe CEP and ExtendScript (WIP)
// Type declarations for ExtendScript Built-in types
// Initial declarations by: Eric Robinson <[email protected]>
/**
* The base class of all JavaScript objects.
*/
interface Object {
/**
* Points to the constructor function that created this object.
* Note that this property is treated as an XML element in the XML class.
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active May 29, 2025 09:23
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for(...;...;...) or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@dlukes
dlukes / server.js
Created January 20, 2017 09:29
Pattern for using Promise-based background jobs in Node + Express.
/* A quick reminder on how to use Promises with Node and Express in order to run potentially
* time-consuming jobs asynchronously (assuming the jobs are able to run in the background thanks to
* libuv and actually return Promises).
*
* Start the server, navigate to /startjob, then refresh a few times, the job should be in progress.
* You can navigate elsewhere in the "app" in other browser tabs in the meanwhile (/). After about
* 20s, you should get a result by refreshing the tab where you originally submitted the job.
*
* I hope this pattern will be useful e.g. for processing images with the `sharp` library (see
* <http://sharp.dimens.io>).