Skip to content

Instantly share code, notes, and snippets.

View jakobvase's full-sized avatar

Jakob Vase jakobvase

View GitHub Profile
@jakobvase
jakobvase / aws-sftp-server.md
Last active October 2, 2024 07:13
Creating an AWS sftp server for testing

Creating an AWS sftp server for testing

I created an sftp server in aws for testing.

  • Generate an ssh key pair ssh-keygen -t ed25519
  • Log in to AWS
  • Go to s3 and create a bucket for the server
  • Go to IAM and create a role
    • Pick 'AWS Service'
  • Select 'Transfer' as the use case
@jakobvase
jakobvase / yup.test.ts
Last active February 10, 2025 16:53
yup
import { object, string } from 'yup';
describe('yup', () => {
/**
* I've had some trouble getting yup to work as I want, and I think it's unintuitive.
* But I have to use it, so I'm writing down these tests so I can actually see what does what.
*
* A few key gotchas:
* * The default value of an object is `{}`, so `object({a: string()})` will allow `undefined`.
* The way to get around this is to add `default(undefined).required()` to all objects.
const h:<FormEventHandler<HTMLFormElement>> = (e) => {
e.preventDefault();
const fe = new FormData(e.currentTarget);
console.log(fe);
}
@jakobvase
jakobvase / useSplitPanel.ts
Last active May 11, 2023 14:48
useSplitPanel
import {
MouseEvent as ReactMouseEvent,
RefObject,
useCallback,
useEffect,
useRef,
} from "react";
const rootFontSize = 13;
@jakobvase
jakobvase / useThrowUnhandledError.tsx
Last active May 1, 2023 13:12
This is a workaround to the fact that errors thrown in `useEffect` and similar cause the whole react tree to unmount. It takes the error and throws it inside the render tree instead.
/**
* This is a workaround to the fact that errors thrown in `useEffect` and similar cause the whole
* react tree to unmount. It takes the error and throws it inside the render tree instead.
*
* Taken from https://www.developerway.com/posts/how-to-handle-errors-in-react and
* https://github.com/facebook/react/issues/14981#issuecomment-468460187.
*
* Usage:
* ```
* const Component = () => {
@jakobvase
jakobvase / Delay.tsx
Created January 25, 2023 12:52
A component to test suspense fallbacks.
import { ComponentType, lazy } from "react";
/**
* A component to test suspense fallbacks.
*
* Wrap the children of your <Suspense> in <Delay>, and watch your beautiful fallback for 5 seconds.
*
* Don't use it in production.
*/
export const Delay = lazy(
@jakobvase
jakobvase / Search.tsx
Last active January 21, 2023 19:34
Relay search component
import graphql from "babel-plugin-relay/macro";
import { Suspense, useState } from "react";
import {
PreloadedQuery,
usePaginationFragment,
usePreloadedQuery,
useQueryLoader,
} from "react-relay";
import { SearchQuery } from "./__generated__/SearchQuery.graphql";
import { Search_Results$key } from "./__generated__/Search_Results.graphql";
@jakobvase
jakobvase / RouterTypes.ts
Created December 20, 2022 18:53
Some thoughts on router types
**
* A router needs to accept adding RouteDefinitions, which are routes with a name and
* path, and potentially a 'fromArgs' and 'fromUrl' constructor, however these might be
* possible to determine programmatically, so maybe not necessary.
*
* Uses:
* * Determine which route we are on, and get any arguments for that route.
* * Create a link to a route by supplying name and arguments.
* * Potentially extend the route definition to do more? Preload? Do we want that in by default?
*/