Skip to content

Instantly share code, notes, and snippets.

View devinrhode2's full-sized avatar
๐Ÿ˜€

Devin Rhode devinrhode2

๐Ÿ˜€
View GitHub Profile
@devinrhode2
devinrhode2 / safeCall.ts
Last active December 30, 2022 20:23
safely call function, and return `returnValue | Error` https://www.swyx.io/errors-not-exceptions
/**
* Calls `callback`, catches any errors and returns `returnValue | Error`
*
* TODO: create npm package
*
* See: https://dev.to/devinrhode2/comment/1fcga
*/
export const safeCall = <
TCallback extends (
...args: unknown[]
import { execaCommandSync } from 'execa'
/** @type {(cmdString: string, debug?: 'debug') => [string | undefined, string | unknown]} */
export const exec = (cmdString, debug) => {
let exception
let result
try {
result = execaCommandSync(cmdString, {
env: {
// @ts-expect-error - not application code
@C-Sinclair
C-Sinclair / useZodls.ts
Created July 27, 2022 11:19
Zod typesafe localstorage hook
import { useCallback, useState } from "react";
import { z, ZodType } from "zod";
type Value<S extends ZodType> = z.infer<S>;
type ValueSetter<S extends ZodType> = (currentValue: Value<S>) => void;
type UseZodls<S extends ZodType> = [
/**
* The current value of the data from local storage
* Will default to the defaultValue if not found in local storage