Skip to content

Instantly share code, notes, and snippets.

View moinulmoin's full-sized avatar
:shipit:
building

Moinul Moin moinulmoin

:shipit:
building
View GitHub Profile
@moinulmoin
moinulmoin / autoScroll.ts
Created August 30, 2023 14:20
AutoScroll down - Puppeteer Page
// ref: https://stackoverflow.com/a/53527984/14491361
/**
* Scrolls the page automatically until either the end of the page
* @param page - The page to scroll.
* @returns A Promise that resolves when the scrolling is complete.
*/
async function autoScroll(page: Page): Promise<void> {
await page.evaluate(async () => {
await new Promise<void>((resolve) => {
@moinulmoin
moinulmoin / useLocalStorage.js
Created January 25, 2023 11:05
LocalStorage Hook for Nextjs SSR
import { useCallback, useEffect, useState } from 'react';
const useLocalStorage = (key, initialValue) => {
const [state, setState] = useState(null);
useEffect(() => {
const initialize = (key) => {
try {
const item = localStorage.getItem(key);
if (item && item !== 'undefined') {
const root = {
a: {
m: { c: { x: 'apple', y: {} } },
n: { 1: {}, 2: {} },
o: {},
},
};
const findPath = (tree, destination) => {
for (let key in tree) {