Skip to content

Instantly share code, notes, and snippets.

Avatar

Semen Bobrov smnbbrv

  • entwico GmbH
  • Munich
View GitHub Profile
@smnbbrv
smnbbrv / promisified-grpc-client.ts
Last active Aug 11, 2022
Promisify @grpc-js service client with typescript
View promisified-grpc-client.ts
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);
}
@smnbbrv
smnbbrv / memoize.decorator.ts
Last active Apr 7, 2022
Memoize decorator based on WeakMaps (respects non-primitive arguments by reference)
View memoize.decorator.ts
const globalCache = new WeakMap();
export function Memoize() {
return (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>) => {
if (descriptor.value != null) {
descriptor.value = getNewFunction(descriptor.value);
} else if (descriptor.get != null) {
descriptor.get = getNewFunction(descriptor.get);
} else {
throw new Error('Only put a Memoize decorator on a method or get accessor.');
@smnbbrv
smnbbrv / gitlab.sh
Created Feb 5, 2019
Open Gitlab page
View gitlab.sh
open $(git config remote.origin.url | sed -E 's/[^:]+:\/\/([^@]*@){0,1}([^:\/]+)([:0-9]*)(\/.+)\.git/https:\/\/\2\4/')
@smnbbrv
smnbbrv / download-google-font.sh
Last active Nov 23, 2018
Download Google font using google-webfonts-helper. Use within the target directory
View download-google-font.sh
# see https://fonts.google.com/attribution for licensing
curl -o f.zip "https://google-webfonts-helper.herokuapp.com/api/fonts/roboto?download=zip&subsets=latin,latin-ext&variants=regular,700" \
&& unzip f.zip \
&& rm f.zip