Skip to content

Instantly share code, notes, and snippets.

View aparx's full-sized avatar

Vinzent Alexander aparx

View GitHub Profile
@aparx
aparx / formidableZodParse.ts
Last active February 21, 2023 08:02
Little gist providing two functions to parse a form from an incoming message and also validate it immediately using a given Zod schema.
import formidable from 'formidable';
import { IncomingMessage } from 'http';
import { z, ZodObject, ZodType } from 'zod';
export type KnownFormFields = Record<string, ZodType>;
export type FormParseResult<TFields, TFiles> = {
error?: Error;
fields?: TFields;
files?: TFiles;
@aparx
aparx / identity_enum.ts
Last active February 14, 2023 20:10
typescript enums without using enum
type EnumKey<EnumType> = keyof EnumType;
type IdentityEnum<T> = T extends Array<infer E extends string> ? {
readonly [P in T[keyof T] as E]: E
} : never;
type IdentityEnumConstructor = {
<T extends string[]>(...values: T): IdentityEnum<T>;
new <T extends string[]>(...values: T): IdentityEnum<T>;
};
@aparx
aparx / reactQueryInfiniteMapper.ts
Last active January 25, 2023 01:26
Enables individual page data remapping and removal for a set of queries using react-query (only through useInfiniteQuery)
import {Query, QueryCache, QueryClient, QueryFilters} from "@tanstack/react-query";
import {InfiniteData} from "@tanstack/query-core/build/lib/types";
export type InfiniteQueryData<U, V> = InfiniteData<U | V | undefined>;
export type InfinitePageMapperParam<OldPageT, NewPageT> = {
page: OldPageT | NewPageT,
index: number,
param?: unknown,
query?: Query<unknown, unknown, InfiniteQueryData<OldPageT, NewPageT>>,
@aparx
aparx / ChildMap.java
Created June 10, 2022 15:42
Interface representing key-value mappings, containing a possible other map that may be respected in lookup operations.
package io.github.sauranbone.plang.core.abstraction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
/**
@aparx
aparx / RegexEscaping.java
Last active February 13, 2022 05:17
Escapes regex characters in a string relatively fast.
package io.github.sauranbone.plang;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Pattern;
/**
* @author Vinzent Zeband
* @version 06:07 CET, 13.02.2022
* @since 1.0