Skip to content

Instantly share code, notes, and snippets.

View leafac's full-sized avatar

Leandro Facchinetti leafac

View GitHub Profile
@leafac
leafac / notes.md
Created February 24, 2024 15:10
HTTP body parsing
- `application/x-www-form-urlencoded`
  - `URLSearchParams`
  - <https://github.com/expressjs/body-parser>.
- `multipart/form-data`
  - <https://github.com/mscdex/busboy>.
    - <https://github.com/expressjs/multer>.
    - <https://github.com/richardgirges/express-fileupload>.
  - <https://github.com/node-formidable/formidable>.
    - Does too much (plugins, and so forth).
  • .
  • autocannon uses negligible CPU.

  • Use yes > /dev/null to saturate one core.

  • Stats shows an aggregate of all the CPU cores, just like the Activity Monitor lower pane. So if 1 out of 8 cores is saturated, you see 25% usage.

  • In a Mac Mini with a M1 processor, the performance cores saturate first and the efficiency cores saturate last.

  • Sending signals:

    ⌃C SIGINT

| kill, Activity Monitor > Quit, Stats > Kill process, and so forth | SIGTERM |

  • Worker threads
    • “Workers (threads) are useful for performing CPU-intensive JavaScript operations. They do not help much with I/O-intensive work. The Node.js built-in asynchronous I/O operations are more efficient than Workers can be.”
    • “Unlike child_process or cluster, worker_threads can share memory.”
    • But they can’t share server ports and they don’t come with load balancing
  • https://www.npmjs.com/package/workerpool
    • Manage pool of workers (I suppose in case of crashes and things like that)
    • Makes it easier to pass values from and to worker
    • Makes it easier to define worker code inline, but the usefulness of that is limited, because it isn’t a real closure
  • https://www.npmjs.com/package/piscina
  • Less magical than workerpool, just handles pool
@leafac
leafac / Tailwind.clr
Last active December 1, 2023 23:39
Create macOS Color Palette (.clr) with JavaScript
@leafac
leafac / notes.md
Created February 17, 2023 12:05
Sortable Lists (Drag-and-Drop API)
@leafac
leafac / notes.md
Created February 3, 2023 19:36
Image/Video Proxy
- Use Got hook
- Use Transform in pipeline
  • Approaches
    • Question about current approach: sindresorhus/got#2060
    • Alternative approach that doesn’t work: Using Caddy. That would be nice because it would reduce the load on the application. But it could be limiting moving forward because it’d be more difficult to do HMAC, and so forth. But none of this matters, Caddy doesn’t seem to support proxying to arbitrary upstreams.
    • Alternative approach: Use a standalone image proxy & fire it up behind Caddy, alongside the main application.
    • Alternative approach: await on headers & only pipe the body?
  • Tests: