Skip to content

Instantly share code, notes, and snippets.

View JMassey1's full-sized avatar
🏢
In Office

Jordan Massey JMassey1

🏢
In Office
View GitHub Profile
@JMassey1
JMassey1 / nullableInput.ts
Last active November 4, 2025 21:01
Zod type for a form value that starts as null but will not accept null
// Borrowed from: github.com/TanStack/form/issues/1583#issuecomment-3127845132
/**
* Modifies the provided schema to be nullable on input, but non-nullable on output.
*/
function nullableInput<TSchema extends ZodType>(schema: TSchema) {
return schema.nullable().transform((value, ctx) => {
if (value === null) {
@JMassey1
JMassey1 / random.cpp
Created November 16, 2021 17:28
Mersenne random engine (C++)
void generateRandomVector(std::vector<int>& inputVector, const std::pair<int,int> RAND_BOUNDS, const int VEC_SIZE) {
std::random_device rnd_device;
std::mt19937 mersenne_engine{rnd_device()};
std::uniform_int_distribution<int> distribution {RAND_BOUNDS.first, RAND_BOUNDS.second};
auto generator = [&distribution, &mersenne_engine]() {
return distribution(mersenne_engine);
};