Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar

Artem Zakharchenko kettanaito

View GitHub Profile
// 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,
@kettanaito
kettanaito / README.md
Last active September 21, 2026 11:31
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.

@kettanaito
kettanaito / INSTALL.md
Last active January 31, 2022 01:36
Source private beta

Beta Program

Thank you for deciding to participate in the closed beta of our new library called "Source"! Through your feedback we will be able to refine it, making the lives of thousands of developers easier.

What is this library about?

The Source library allows you to generate request handlers from various sources. Currently, we support only HTTP archives (HAR) and OpenAPI (Swagger).

What do you expect from me?

@kettanaito
kettanaito / apollo.d.ts
Created November 5, 2021 00:26
Annotate context type from "@apollo/client"
declare module '@apollo/client/core' {
export interface DefaultContext {
accessToken: string
}
}
export {}
@kettanaito
kettanaito / getCompilationSource.ts
Last active February 9, 2021 17:23
Webpack – Get compilation source
import { createFsFromVolume, Volume } from 'memfs'
const fs = createFsFromVolume(new Volume())
const compiler = webpack({
entry: 'file.js',
output: { filename: 'main.js' }
})
// Compile the file to memory.
compiler.outputFileSystem = fs
@kettanaito
kettanaito / case.ts
Last active January 29, 2021 14:19
Response body retrieval
// Determine a body of the given Response.
// In case of a Response that has no body (i.e. 204 response),
// return `null`.
function getResponseBody(res: Response) {
res.body // ReadableStream, locked
await res.text() // always "" for a response with no body
}
// Empty string cannot be used as a response body
// for the responses that have no body (i.e. 204 response).
@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
}

I have a class called SocketPolyfill that looks roughly like this:

import { EventEmitter } from 'events'

export class SocketPolyfill extends EventEmitter {
	// methods here
}
@kettanaito
kettanaito / README.md
Created June 20, 2020 16:02
Working with remotes in Git

Working with multiple remotes

Adding a new remote

$ git remote add REMOTE_NAME REMOTE_URL

Verify that the new remote has been added by running git remote -v and seeing your REMOTE_NAME in the list.