Skip to content

Instantly share code, notes, and snippets.

View devgioele's full-sized avatar

devgioele devgioele

View GitHub Profile
@devgioele
devgioele / useAugmentedFormContext.ts
Last active May 5, 2023 07:00
An extension of react-hook-form's `useFormContext`
import _ from 'lodash'
import { useRef } from 'react'
import {
FieldError,
FieldPath,
FieldValues,
useFormContext,
} from 'react-hook-form'
import { DistributivePick } from '../typescript/DistributivePick'
@devgioele
devgioele / FormCompatible.ts
Created April 28, 2023 07:53
Transform number fields to strings recursively
type FormCompatible<T> = T extends unknown
? {
[P in keyof T]: T[P] extends infer K
? K extends object
? FormCompatible<T[P]>
: K extends number
? string
: K
: never
}
@devgioele
devgioele / PartialRequired.ts
Last active April 18, 2023 12:27
Partial and Required helpers
/**
* A version of `Partial` that makes only the given keys of `T` optional.
*/
export type PartialPick<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
/**
* A version of `Partial` that makes all the not specified keys of `T` optional.
*/
export type PartialOmit<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>
@devgioele
devgioele / Distributive.ts
Created April 18, 2023 12:25
Distributive versions of Pick and Omit
/**
* A version of `Pick` that preserves unions composing `T` by applying `Pick` on each union of `T`.
*/
export type DistributivePick<T, K extends keyof T> = T extends unknown
? Pick<T, K>
: never
/**
* A version of `Omit` that preserves unions composing `T` by applying `Omit` on each union of `T`.
*/
@devgioele
devgioele / partial-except.ts
Created January 8, 2023 09:35
A TypeScript type that makes all keys of an object optional, except for the keys given. Useful for making less strict variants of an existing type.
/** Make all keys of T optional except for K. */
type PartialExcept<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>;
@devgioele
devgioele / arch-rpi-64-full-disk-encryption-ssh-unlock.md
Last active February 25, 2024 02:47 — forked from gea0/arch-rpi-64-full-disk-encryption-ssh-unlock.md
Tutorial for installing a 64-bit Arch Linux ARM system on the Raspberry Pi 4B, with an encrypted root filesystem, and the option to remotely unlock it via a pre-boot SSH daemon.

Arch Linux ARM 64 on Raspberry Pi 4B With Full Disk Encryption And SSH Unlock: 2022 Edition

There are multiple ways to get a full disk encrypted arch linux system on raspberry. In this tutorial, we will install a 64-bit arch linux armv8 system, using dropbear as ssh server for remote pre-boot unlocking of the root filesystem. However, it will still be possible to unlock and use the pi as usual, with a keyboard and monitor. We will also create an unencrypted partition in the installation process, usable as a rescue system.

For different setup options, see the end of the document.

Get The Image and check the signature

@devgioele
devgioele / publish.yml
Created May 30, 2022 15:37
Publish to a private GitHub NPM registry with caching
name: Publish to the private GitHub NPM registry
on:
push:
branches:
- main
paths-ignore:
- '**/*.md'
jobs:
@devgioele
devgioele / env.ts
Created May 13, 2022 18:43
Load env vars utility
const msgMissing = (key: string): string => `Missing env var '${key}'`
export const loadOptionalEnvVar = (key: string): string | undefined =>
process.env[key]
/**
* Load an environment variable.
* @param key The key used to access the environment variable.
* @returns The value of the environment variable.
*/
@devgioele
devgioele / .env
Last active May 12, 2022 14:52
Verify env vars with Node.js
ARR1 = "value1 value2 value3"
ANOTHER = "test"
OPTIONAL_EXAMPLE = "optional test"
@devgioele
devgioele / renameRecursively.ps1
Last active December 9, 2021 13:58
Powershell cmd to rename files recursively using a regex
# Changing the file extensions of files from .js to .tsx
Get-ChildItem ./src -File -Recurse | Rename-Item -NewName { $_.Name -replace '\.js','.tsx' }