Skip to content

Instantly share code, notes, and snippets.

@rbelling
rbelling / valueOfEnum.ts
Created August 18, 2022 20:37
Create a type for the values of an enum
/**
* @description given an enum, extracts its values (string) and lets you type-check them.
* @example
* ```typescript
* enum Foo = {
* Hello: "a",
* World: "b"
* }
*
* const a: ValueOfEnum<Foo> = "a"; // correct
@rbelling
rbelling / replaceProps.ts
Created August 18, 2022 20:36
Replace Props - given a type, replaces the provided props in it and returns the resulting type
import { Except, Merge } from "type-fest";
/**
* @description Merge `ReplacedProps` in `T`, excluding keys of `ReplacedProps` that are not originally in T.
* @example
* ```typescript
* type FooBar = { foo: string, bar: string }
*
* type FooBarReplaced = ReplacedProps<FooBar, { bar: number }>
*
@rbelling
rbelling / .spectral.yml
Last active April 7, 2022 15:42
Spectral rules for openapi validation
extends: [[spectral:oas, all]]
# See description of each at https://meta.stoplight.io/docs/spectral/ZG9jOjExNw-open-api-rules
rules:
info-contact: off
info-license: off
license-url: off
oas3-api-servers: off
oas3-parameter-description: error
@rbelling
rbelling / cleanup-topics.sh
Last active March 2, 2022 16:04
Deleting kafka topics from namespaces that no longer exist, using confluent cli
#!/usr/bin/env bash
for topic in $(confluent kafka topic list);
do
k8s_namespace=$(echo "${topic}" | cut -d. -f1)
if [[ $k8s_namespace == slice-* ]] ; then
if kubectl get ns "${k8s_namespace}" ; then
echo "${k8s_namespace}" exists
else
confluent kafka topic delete "${topic}"
@rbelling
rbelling / quicksort.hs
Created January 30, 2020 12:03 — forked from kangax/quicksort.hs
Haskell-inspired quick sort in ES6
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort (filter (<=x) xs)
biggerSorted = quicksort (filter (>x) xs)
in smallerSorted ++ [x] ++ biggerSorted
function minSum(num, k) {
console.log(num.length, k);
if (!(1 <= num.length && num.length <= Math.pow(10, 5)) || !(k >= 1 && k <= Math.pow(10, 7))) {
console.error("Error: input is outside the bounds");
return;
}
// return minSum_READABLE(num, k);
return minSum_FAST(num, k);
}
@rbelling
rbelling / addFooterLink.ts
Last active December 21, 2019 16:10
This works for O5A/S5A/LT both desktop and mobile