Inspired by https://twitter.com/TkDodo/status/1734255363266843017?t=dOhCHPJJMd2bq2A8VK8R-A&s=19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use a conditional, because You may not want to provide swagger documentation in public environments | |
if (_configuration.GetValue<bool>("SwaggerConfiguration:EnableSwagger")) | |
{ | |
services.AddEndpointsApiExplorer(); | |
services.AddSwaggerGen(options => { | |
options.AddCustomIds(); | |
options.AddMetadata(typeof(Program)); | |
options.SchemaFilter<NullableEnumSchemaFilter>(); | |
options.SchemaFilter<RequiredPropertiesSchemaFilter>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { camelCase, pascalCase, snakeCase } from "change-case"; | |
type CamelToPascalCase<S extends string> = S extends `${infer F}${infer R}` | |
? `${Capitalize<F>}${R}` | |
: S; | |
type PascalToCamelCase<S extends string> = S extends `${infer F}${infer R}` | |
? `${Uncapitalize<F>}${R}` | |
: S; | |
type SnakeToCamelCase<S extends string> = S extends `${infer F}_${infer R}` | |
? `${Uncapitalize<F>}${Capitalize<SnakeToCamelCase<R>>}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httpStatus from "http-status"; | |
export const makeError = <TErrorName extends string>( | |
name: TErrorName, | |
message?: string | |
) => ({ | |
name, | |
message, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Prettify<T> = { | |
[K in keyof T]: T[K]; | |
}; | |
export type Model<T> = Prettify< | |
T & { | |
_id: string; | |
createdAt: Date | string; | |
updatedAt: Date | string; | |
deletedAt?: Date | string | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` | |
? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}` | |
: S | |
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` | |
? `${T}${Capitalize<SnakeToCamelCase<U>>}` | |
: S | |
type StringKeys<TEntity extends {}> = { | |
[key in keyof TEntity]: key extends string ? key : never | |
}[keyof TEntity] | |
type IsLiteral<TValue> = TValue extends string | number | boolean | symbol |
Here, we'll explore loosely coupling react hooks with dependency inversion as a way to manage side effects.
NB: The hooks code given here, uses react-query hooks for simplicity cos I'm rushing to write this. I hope that's not a problem. Perhaps, someone will write the equivalent implementations using out-of-the-box react hooks.
We'll consider a simple react hook, that fetches a list of users in two ways:
const useFetchUsers = () => {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef {object} AWSCloudfrontMessageEvent | |
* @property {AWSCloudfrontEventRecord[]} Records | |
*/ | |
/** | |
* @typedef {object} AWSCloudfrontEventRecord | |
* @property {object} cf | |
* @property {{ distributionId: string, eventType: string, requestId: string, distributionDomainName: string }} cf.config | |
* @property {AWSCloudfrontRequest} cf.request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { promises as fs } from 'fs'; | |
import path from 'path'; | |
import inlineCss from 'inline-css'; | |
import env from '../common/config/env'; | |
/** | |
* So there are multiple *.hbs files, in a directory, and one of them, contains a link reference to tailwind cdn like: | |
* <link rel="stylesheet" href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"> | |
* In this script, we inline all their styles by | |
* - reading each file's content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: President Muhammadu Buhari | |
ministry: Minister of Petroleum | |
email: info@petroleumresources.gov.ng | |
phone: "0952335368" | |
- name: Mohammed Musa Bello | |
ministry: Minister of Federal Capital Territory, FCT | |
email: "" | |
phone: "" |
NewerOlder