Skip to content

Instantly share code, notes, and snippets.

View polRk's full-sized avatar
👋
YDB NodeJS Maintainer

Vladislav Polyakov polRk

👋
YDB NodeJS Maintainer
View GitHub Profile
@polRk
polRk / useWidthObserver.ts
Created May 11, 2020 16:45
Watch component width changes
import debounce from 'lodash/debounce'
import { RefObject, useEffect } from 'react'
export const useWidthObserver = <T extends HTMLElement>(
refObject: RefObject<T>,
setWidth: (width: number) => void
) => {
useEffect(() => {
function resizeListener() {
if (refObject.current) {
@smnbbrv
smnbbrv / promisified-grpc-client.ts
Last active February 19, 2025 18:43
Promisify @grpc-js service client with typescript
import { Client, ServiceError, Metadata, CallOptions, ClientUnaryCall } from '@grpc/grpc-js';
import { Message } from 'google-protobuf';
type OriginalCall<T, U> = (request: T, metadata: Metadata, options: Partial<CallOptions>, callback: (error: ServiceError, res: U) => void) => ClientUnaryCall;
type PromisifiedCall<T, U> = ((request: T, metadata?: Metadata, options?: Partial<CallOptions>) => Promise<U>);
export type Promisified<C> = { $: C; } & {
[prop in Exclude<keyof C, keyof Client>]: (C[prop] extends OriginalCall<infer T, infer U> ? PromisifiedCall<T, U> : never);
}
@enobufs
enobufs / before_after_each_test.go
Created May 7, 2022 23:07
beforeEach and afterEach with go-test
package main
import (
"fmt"
"os"
"runtime"
"testing"
)
func TestMain(m *testing.M) {