Skip to content

Instantly share code, notes, and snippets.

View emeraldsanto's full-sized avatar

Yanick Bélanger emeraldsanto

View GitHub Profile
@emeraldsanto
emeraldsanto / make-navigator-implementation-types-explainer.ts
Created September 4, 2021 03:50
Achieving type safe deep linking in React Native with react-navigation #7
/**
* This simply aggregates navigator constructors
* and allows us to support more than one type of navigator.
*/
const navigators = {
stack: createStackNavigator,
tab: createBottomTabNavigator,
} as const;
/**
@emeraldsanto
emeraldsanto / make-navigator-functions-explainer.tsx
Last active September 4, 2021 03:52
Achieving type safe deep linking in React Native with react-navigation #8
/**
* Surprisingly, there is very little code here as all we really need to do
* is provide a short hand for the default render function of the provided screens.
*
* If a custom `render` is provided, we execute it by passing the whole configuration
* as props.
*
* Otherwise use the default behaviour defined in `renderScreens`.
*/
export function makeNavigator<
@emeraldsanto
emeraldsanto / make-navigator-implementation-complete.tsx
Created September 4, 2021 03:53
Achieving type safe deep linking in React Native with react-navigation #9
const navigators = {
stack: createStackNavigator,
tab: createBottomTabNavigator,
} as const;
type NavigatorType = keyof typeof navigators;
type NavigatorProps<T extends NavigatorType> = ComponentProps<
ReturnType<typeof navigators[T]>['Navigator']
>;
@emeraldsanto
emeraldsanto / make-navigator-usage-example.tsx
Last active September 4, 2021 03:55
Achieving type safe deep linking in React Native with react-navigation #10
// SomeStack.tsx
export const SomeStackConfiguration = makeNavigator({
name: 'SomeStack',
type: 'stack',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
},
@emeraldsanto
emeraldsanto / make-navigator-integration-example.tsx
Last active September 4, 2021 03:58
Achieving type safe deep linking in React Native with react-navigation #11
import { LinkingOptions } from '@react-navigation/native';
const linking: LinkingOptions = {
prefixes: ['example://'],
config: {
screens: {
[RootStackConfiguration.name]: RootStackConfiguration.linking,
},
},
}
@emeraldsanto
emeraldsanto / typesafe-mongo-changestream.ts
Created December 25, 2021 18:29
Type safe MongoDB change stream
import { EventEmitter } from 'events';
import { getInstance } from './core-util/mongo';
import { ChangeEvent, ChangeEventCR, ChangeEventDelete, ChangeEventUpdate, ChangeStream, ObjectId } from 'mongodb';
type ChangeListenerFunction<T> = (payload: T) => void;
interface User {
address: {
city: string
country: string
@emeraldsanto
emeraldsanto / swagger-to-express.ts
Last active April 28, 2022 20:43
Define routes according to the Open API / Swagger specification and get a fully typed express resolver.
// === Parameter definition ===
interface RouteParameterBase {
description?: string;
nullable?: boolean;
required?: boolean;
}
interface BooleanRouteParameter extends RouteParameterBase {
type: 'boolean';
@emeraldsanto
emeraldsanto / slack-theme-verdandi.txt
Last active August 8, 2022 15:34
Slack light theme inspired by the Verdandi VS Code theme.
#f4f6f9,#e0e5ee,#d8edff,#0070d2,#e0e5ee,#16325c,#4bca81,#000000,#e0e5ee,#16325c
@emeraldsanto
emeraldsanto / async-batch.ts
Created February 26, 2022 17:39
Utility function to sequentially run batches of async operations with configurable concurrency.
/**
* Allows for sequentially running batches of async operations.
* @param {number} concurrency The maximum number of operations to run concurrently.
*/
export function batch(concurrency: number) {
return async function <TElement, TResult>(xs: Array<TElement>, handler: (x: TElement) => TResult): Promise<Array<TResult>> {
const results: Array<TResult> = [];
const batches = Array.from({ length: Math.ceil(xs.length / concurrency) }, (_, i) => i)
for await (const batchNumber of batches) {
@emeraldsanto
emeraldsanto / vivaldi-theme-verdandi.json
Last active October 1, 2022 13:56
Vivaldi light theme inspired by the Verdandi VS Code theme.
{
"accentFromPage": false,
"accentOnWindow": true,
"accentSaturationLimit": 1,
"alpha": 1,
"backgroundImage": "",
"backgroundPosition": "stretch",
"blur": 0,
"colorAccentBg": "#d8edff",
"colorBg": "#f4f6f9",