Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Working on EpicWeb.dev

Artem Zakharchenko kettanaito

🚀
Working on EpicWeb.dev
View GitHub Profile
@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 June 28, 2024 01:12
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
@msafi
msafi / Electron-Webpack-require-is-not-defined-.md
Last active October 16, 2021 19:17
Electron Webpack `require is not defined`

If you're using Webpack to bundle your Electron app and you're getting require is not defined, and you don't want to set nodeIntegration to true for security, change the target of your webpack bundle from electron-renderer to web. That way webpack won't be trying to look for things like require and module in the environment.

I found this solution after reading this comment SimulatedGREG/electron-vue#644 (comment)