Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Extremely busy. Open source activity paused.

Artem Zakharchenko kettanaito

🚀
Extremely busy. Open source activity paused.
View GitHub Profile
@kettanaito
kettanaito / Dockerfile
Last active January 29, 2025 10:33
Puppeteer in 🐋 Docker
FROM node:22-slim as base
# Skip downloading Chromium as we are installing it manually.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# Point Puppeteer at the manually installed executable.
ENV PUPPETEER_EXECUTABLE_PATH="/usr/bin/google-chrome"
# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
@kettanaito
kettanaito / mocking-websockets.md
Last active November 12, 2023 10:43
On Mocking Websockets

On Mocking WebSockets

Unlike HTTP, WebSocket communication is duplex (both the client and the server can emit and listen to events) and persistent. This difference is reflected in how one would expect to mock a WebSocket communication.

Connection

I believe mocking WebSockets should be connection-based. This way each individual connected client is scoped to a particular interceptor handler.

interceptor.on('connection', (connection) => {
@markerikson
markerikson / rtk-esm-ts-notes-2023-02-27.md
Last active September 3, 2023 00:33
RTK ESM/TS Config meeting notes - 2023-02-27/28

RTK ESM/TS Discussion

Attendees:

  • Nathan Bierema
  • Mateusz Burzynski
  • Mark Erikson

Notes

  • Mateusz: what do you want besides "ship widely compat code?" What preferences?
@kettanaito
kettanaito / README.md
Last active April 10, 2025 04:04
Chromium on Vercel (serveless)

Chromium on Vercel (serverless)

This is an up-to-date guide on running Chromium in Vercel serverless functions in 2022. What you will read below is the result of two days of research, debugging, 100+ failed deployments, and a little bit of stress.

Getting started

Step 1: Install dependencies

Use chrome-aws-lambda that comes with Chromium pre-configured to run in serverless, and puppeteer-core due to the smaller size of Chromium distributive.

// TODO: make `pages` optional and measure the div when unspecified, this will
// allow more normal document flow and make it easier to do both mobile and
// desktop.
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
@kentcdodds
kentcdodds / README.md
Last active March 30, 2024 11:39
user-package-stats

user-package-stats

I was poking around trying to figure out all the packages I have access to publish and got curious. So I write this little script to determine the download stats for all the packages I have publish access to.

Feel free to try it yourself. Just change the username passed to getUserDownloadStats.

By default, the stats are sorted by their average daily downloads (descending). That should give you an idea of the most "popular" package of a given user relative to how long that package has been around.

You can use it with npx like so:

@kettanaito
kettanaito / compose.ts
Last active March 3, 2021 00:18
TypeScript snippets
// Source: https://medium.com/@minaluke/typescript-compose-function-b7512a7cc012
type ArityOneFn = (arg: any) => any
type PickLastInTuple<T extends any[]> = T extends [
...rest: infer U,
argn: infer L
]
? L
: never
type FirstFnParameterType<T extends any[]> = Parameters<PickLastInTuple<T>>[any]
type LastFnParameterType<T extends any[]> = ReturnType<T[0]>
@kettanaito
kettanaito / gql.d.ts
Last active October 27, 2020 16:17
Common TypeScript declarations
declare module '*.gql' {
import { DocumentNode } from 'graphql'
const vaule: DocumentNode
export default value
}
@kettanaito
kettanaito / code.js
Created January 25, 2020 10:26
Boolean: De Morgan's Laws
!(A && B) // is equivalent to
!A || !B
!(A || B) // is equivalent to
!A && !B