| interface ProcessByBatchesOptions { | |
| /** | |
| * The number of items to process in parallel. | |
| * @default 10 | |
| */ | |
| batchSize?: number | |
| } | |
| async function processByBatches<ItemType, ResultType>( | |
| items: ItemType[], |
| // 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 | |
| }) |
Implement Promise based memoization with a given cache size behaving as an LRU cache with an expiry time and auto cache burst.
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.
- 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 = {}; |
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.😁
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
| # .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: |
| import { useRef } from 'react'; | |
| const safeDocument: Document = document; | |
| /** | |
| * Usage: | |
| * const [blockScroll, allowScroll] = useScrollBlock(); | |
| */ | |
| export const useScrollBlock = (): [() => void, () => void] => { | |
| const scrollBlocked = useRef(false); |
| // Source: https://twitter.com/calebporzio/status/1151876736931549185 | |
| <div class="flex"> | |
| <aside class="h-screen sticky top-0"> | |
| // Fixed Sidebar | |
| </aside> | |
| <main> | |
| // Content | |
| </main> |