Skip to content

Instantly share code, notes, and snippets.

View mykeels's full-sized avatar
😄
faffing!

Ikechi Michael mykeels

😄
faffing!
View GitHub Profile
@mykeels
mykeels / 0_Program.cs
Last active April 13, 2024 07:34
Code for extracting OpenAPI schema from ASP.NET Core projects
// 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>();
@mykeels
mykeels / states-and-cities.json
Created April 8, 2018 12:43
Nigerian States and Cities in JSON
[
{
"name": "Abia",
"cities": [
"Aba South",
"Arochukwu",
"Bende",
"Ikwuano",
"Isiala Ngwa North",
"Isiala Ngwa South",
@mykeels
mykeels / RsaKeyService.cs
Last active January 26, 2024 03:47
For IdentityServer4's AddSigningCredentials in production
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.IdentityModel.Tokens;
@mykeels
mykeels / change-casing.ts
Last active January 8, 2024 21:23
Change cashing
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>>}`
@mykeels
mykeels / controller-error-handling.ts
Created August 19, 2023 01:03
controller-error-handling.ts
import httpStatus from "http-status";
export const makeError = <TErrorName extends string>(
name: TErrorName,
message?: string
) => ({
name,
message,
});
@mykeels
mykeels / repository.interface.ts
Created August 5, 2023 21:05
Generic repository interface, that just might work across DBs
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;
@mykeels
mykeels / snake-camel.d.ts
Created May 30, 2023 23:25
Typings for the snake-camel npm package https://www.npmjs.com/package/snake-camel
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
@mykeels
mykeels / USE_FETCH_USERS_HOOK.md
Last active April 14, 2022 14:39
A simple hook, showing dependency inversion

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:

1. No dependency inversion

const useFetchUsers = () =&gt; {
@mykeels
mykeels / Done-CheckPoints.md
Last active April 2, 2022 03:12
A list of checkpoints, to be marked before an application can be said to be "done".

Web Apps

  • Migrations (if applicable)
  • Seeders (if applicable)
  • Automated Tests
    • Integration
    • E2E
      • Authentication
      • Authorization
  • Documentation