Skip to content

Instantly share code, notes, and snippets.

View KXLAA's full-sized avatar
🫣

Kolade Afode KXLAA

🫣
View GitHub Profile
@onmax
onmax / processByBatches.ts
Created January 26, 2024 04:14
Effective approach to processing items in batches asynchronously in JavaScript. This function processByBatches allows parallel processing of items, with a customizable batch size. There's room for enhancements, like incorporating Promise.allSettled or adding more options. Feedback and improvements are welcome!
interface ProcessByBatchesOptions {
/**
* The number of items to process in parallel.
* @default 10
*/
batchSize?: number
}
async function processByBatches<ItemType, ResultType>(
items: ItemType[],
@betafcc
betafcc / FizzBuzzIterator.d.ts
Last active September 5, 2022 10:57
Type-Level FizzBuzz in Typescript
// Iterator approach, seems to be good up until ~850
type Result = Take<100, FizzBuzzIterator[1]>
// ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", ...]
export type FizzBuzzIterator<
S extends Record<any, any> = { 3: []; 5: []; i: [] },
R extends string = `${S[3]["length"] extends 3 ? "Fizz" : ""}${S[5]["length"] extends 5 ? "Buzz" : ""}`
> = [
R extends "" ? `${S["i"]["length"]}` : R,
FizzBuzzIterator<{
type AnyFunction = (...args: any[]) => any
function useEvent<T extends AnyFunction>(callback?: T) {
const ref = useRef<AnyFunction | undefined>(() => {
throw new Error("Cannot call an event handler while rendering.")
})
// Or useInsertionEffect if it's React 18
useLayoutEffect(() => {
ref.current = callback
})
@lilpolymath
lilpolymath / LRUCache.md
Created April 12, 2022 14:30
Implementing a given cache size behaving as an LRU cache with an expiry time and auto cache burst

Question

Implement Promise based memoization with a given cache size behaving as an LRU cache with an expiry time and auto cache burst.

Answer

First, what we have to do is breakdown the terms in the problem statement to understand what is going on and what we are asked to do.

  1. Promise based memoization: Memoization is one of the ways we can improve the performance of functions by eliminating redundant calls. Memoization is a technique where we store the results of a function call in a cache and return the result from the cache if the function is called again with the same arguments.
import { set, unset, get, PropertyPath } from 'lodash';
import { useSyncExternalStore } from 'react';
export type SimpleReactiveStore = ReturnType<typeof createSimpleReactiveStore>;
/**
*
* @returns a simple store you can use with your react components.
*/
export function createSimpleReactiveStore() {
const data: object = {};
@khushal87
khushal87 / blog3.md
Last active July 21, 2025 07:23
Linking a custom domain from Google domains to Vercel app

Linking a custom domain to a deployed application is confusing and at times you don't get a route on how to link the domain with the website. 😫

In this article, I will be explaining how to link a Custom domain brought in Google Domains service to an application hosted on Vercel.

Perks of using vercel is that it allows adding domain without any verification unlike Heroku/Netlify, which means you don't have to add your billing details to add a domain to your application. Moreover, it is fast, efficient, and easy to use.😁

What is Vercel?

​Vercel is a deployment and collaboration platform for frontend developers. ​Vercel enables developers to host websites and web services that deploy instantly and scale automatically – all without any configuration. Source - Official Docs

@2color
2color / test.yaml
Last active August 25, 2025 10:17
How to run integration tests with PostgreSQL and Prisma on GitHub Actions
# .github/workflows/test.yaml
name: test
on: push
jobs:
test:
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
@celian-rib
celian-rib / useScrollBlock.ts
Last active May 24, 2024 08:54 — forked from reecelucas/useScrollBlock.js
React hook to enable/disable page scroll (Typescript version)
import { useRef } from 'react';
const safeDocument: Document = document;
/**
* Usage:
* const [blockScroll, allowScroll] = useScrollBlock();
*/
export const useScrollBlock = (): [() => void, () => void] => {
const scrollBlocked = useRef(false);
@BjornDCode
BjornDCode / gist:5cb836a6b23638d6d02f5cb6ed59a04a
Created February 3, 2020 11:58
Tailwind - Fixed sidebar, scrollable content
// Source: https://twitter.com/calebporzio/status/1151876736931549185
<div class="flex">
<aside class="h-screen sticky top-0">
// Fixed Sidebar
</aside>
<main>
// Content
</main>