Skip to content

Instantly share code, notes, and snippets.

View smnbbrv's full-sized avatar

Semen Bobrov smnbbrv

  • entwico GmbH
  • Munich
View GitHub Profile
@smnbbrv
smnbbrv / cleanup.sh
Last active April 17, 2023 09:40
Cleanup semver docker images in nexus repository
#!/bin/bash
# credits to https://gist.github.com/sfwn/7453e78be0374b3d53f1e44f5bb8beef
# TODO replace ghead with head for non-macos
# TODO provide DOCKER_LOGIN and DOCKER_PASSWORD as arguments
DOCKER_REGISTRY="https://docker.example.com/v2"
DOCKER_LOGIN="xxx"
DOCKER_PASSWORD="yyy"
@smnbbrv
smnbbrv / promisified-grpc-client.ts
Last active November 4, 2023 21:22
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);
}
@smnbbrv
smnbbrv / memoize.decorator.ts
Last active February 5, 2023 13:28
Memoize decorator based on WeakMaps (respects non-primitive arguments by reference)
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 February 5, 2019 09:15
Open Gitlab page
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 November 23, 2018 10:28
Download Google font using google-webfonts-helper. Use within the target directory
# 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