Skip to content

Instantly share code, notes, and snippets.

View AkinAguda's full-sized avatar

Akinwunmi Aguda AkinAguda

  • Nigeria
View GitHub Profile
@AkinAguda
AkinAguda / ColorSlider.tsx
Last active February 14, 2024 12:02
A gradient color slider in the context of Next.js + Typescript + tailwind
"use client";
import { memo, useState } from "react";
import classes from "./colorSlider.module.css";
import {
GRADIENT,
MAX_RANGE,
RGB,
determineColorFromValue,
@AkinAguda
AkinAguda / ussd.ts
Last active February 1, 2024 00:27
Sample USSD implementation for a friend
type PageId = number;
type PageOption = {
optionText: string;
dialIndex: number;
pageId: PageId;
};
class Page {
id: PageId;
@AkinAguda
AkinAguda / range.ts
Last active January 26, 2024 22:53
A `Range` type in typescript that ensures that a value is within a certain range of positive values (not inclusive of the last)
// Convert string to number
type ToNumber<S> = S extends `${infer N extends number}` ? N : never;
// Creates an array with a particular length
type ArrayWithLength<
T extends number,
A extends number[] = number[],
> = A["length"] extends T ? A : ArrayWithLength<T, [...A, A["length"]]>;
// Generates a union type with all the numbers from zero -> n
@AkinAguda
AkinAguda / TestComponent.tsx
Last active July 31, 2023 12:20
Force React component to expect certain props if another is defined
interface CommonData {
someRandomData: string;
}
type DataOne = {
someDataOneValue: string;
};
type DataTwo = {
someDataTwoValue: string;