Skip to content

Instantly share code, notes, and snippets.

View adeleke5140's full-sized avatar
💭
crafting software

Kehinde adeleke5140

💭
crafting software
View GitHub Profile
@adeleke5140
adeleke5140 / convertImage.ts
Created October 30, 2023 13:18
An API route to convert a base64 encoded image ans save it to a jpeg file.
import { writeFileSync } from "fs";
import { join } from "path";
import { NextApiRequest, NextApiResponse } from "next";
export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
if (req.method === "POST") {
const base64 = req.body.image;
const cleanBase64Data = base64.replace(/^data:image\/jpeg;base64,/, ""); // Remove the data URI prefix
const binaryData = Buffer.from(cleanBase64Data, "base64");
@adeleke5140
adeleke5140 / CustomLink.tsx
Created October 22, 2023 01:36
Navbar Links
@adeleke5140
adeleke5140 / Avatar.tsx
Created September 26, 2023 16:51
A Generic avatar component
import { classNames } from 'utils'
type Size = 'small' | 'medium' | 'large'
type AvatarProps = {
size?: Size
src?: string
alt?: string
}
@adeleke5140
adeleke5140 / index.css
Created September 2, 2023 12:59
styling the react date picker
/*
Styles for the React date picker input
*/
/* .react-datepicker-wrapper {
width: 100%;
}
.react-datepicker__input-container {
@adeleke5140
adeleke5140 / index.ts
Created August 28, 2023 05:38
interesting type
interface BannerProps {
type: "base" | "success" | "error";
children: React.ReactNode;
}
{
[key in BannerProps["type"]]: string;
}
@adeleke5140
adeleke5140 / buildIcons.ts
Created August 27, 2023 12:24
Generate svg sprites
import { promises as fs } from "node:fs";
import * as path from "node:path";
import { glob } from "glob";
import { parse } from "node-html-parser";
async function buildIcons() {
const cwd = process.cwd();
const inputDir = path.join(cwd, "svgs");
const inputDirRelative = path.relative(cwd, inputDir);
const outputDir = path.join(cwd, "src", "component", "icons");
@adeleke5140
adeleke5140 / index.tsx
Created August 11, 2023 17:40
Copy to clipboard
import { CopyToClipboard } from "react-copy-to-clipboard";
import { useEffect, useState } from "react";
const index = () => {
const [copiedStatus, setCopiedStatus] = useState(false);
useEffect(() => {
let timeout: number;
if (copiedStatus) {
@adeleke5140
adeleke5140 / Readme.md
Last active July 25, 2023 20:09
2fa-input-react

2fa with React

This is an attempt at creating a set of input element that accept 2fa code.

There is a bug where pressing the backspace key messes with the focused input which I don't have the time to fix right now.

Mine is written in TS but this is the original version in JS: Original

@adeleke5140
adeleke5140 / compose.js
Created April 26, 2023 17:05
function composition
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), vx)
@adeleke5140
adeleke5140 / flatten.js
Last active April 26, 2023 14:03
Flatten a multidimensional array
function flatten(value){
//do this immutably without modifying the initial arr
value.reduce((acc, cur) => acc.concat(Array.isArray(curr) ? flatten(curr): curr), [])
}
//iteration
function flatten(value){
const res = []