Skip to content

Instantly share code, notes, and snippets.

View natterstefan's full-sized avatar
🟨
getting things done 💪🏻

Stefan Natter natterstefan

🟨
getting things done 💪🏻
View GitHub Profile
@natterstefan
natterstefan / moveMouse.js
Created April 27, 2023 19:40
JS Utils | Move Mouse Randomly Forever
// function to generate a random number within a range
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// function to generate a random mouse coordinate within the viewport
function getRandomCoordinate() {
const x = getRandomNumber(0, window.innerWidth);
const y = getRandomNumber(0, window.innerHeight);
return { x, y };
@natterstefan
natterstefan / README.md
Created January 18, 2023 10:08
Next.js | Catchall including index

Next.js | Catch-All route including index

@natterstefan
natterstefan / README.md
Last active September 2, 2022 07:16
react-i18next and TS2589: Type instantiation is excessively deep and possibly infinite.

react-i18next and TS2589: Type instantiation is excessively deep and possibly infinite.

visitors

The patch works both with tsc and next build, as described in the comments of the patch.

Inspired by

@natterstefan
natterstefan / usePrevious.ts
Created August 30, 2022 11:07
React | usePrevious hook
/**
* inspired by
* @see https://codesandbox.io/s/use-previous-hook-persistent-with-matcher-hujqez?file=/src/hooks.tsx:0-1069
* @see https://www.developerway.com/posts/implementing-advanced-use-previous-hook
* @see https://usehooks.com/usePrevious/
*/
import { useRef, useEffect } from 'react'
export const usePrevious = <TValue>(value: TValue) => {
const ref = useRef<TValue>()
@natterstefan
natterstefan / HTMLToReact.tsx
Last active April 8, 2024 13:54
html-react-parser | TypeScript solution
/**
* Works in Next.js 10.x
*/
import React from 'react'
import parse, {
domToReact,
attributesToProps,
Element,
HTMLReactParserOptions,
} from 'html-react-parser'
@natterstefan
natterstefan / README.md
Last active September 23, 2022 02:42
Storybook | Tailwind in Next.js App with Webpack@5

Storybook | Tailwind in Next.js App with Webpack@5

Installation

# install storybook dependencies
yarn add @storybook/addon-actions @storybook/addon-essentials @storybook/react -D
yarn add @storybook/addon-postcss@latest -D

# install webpack5 dependency
@natterstefan
natterstefan / Dockerfile
Created March 16, 2021 10:26
Docker | Advanced Nodejs Dockerfile
# We make use of ARG to set some variables that we
# can use in the Dockerfile
ARG node_version=14
ARG node_image=node:${node_version}-alpine
# STAGE 1: This is the "builder" stage where we build the
# application and give this step a name: "builder"
FROM $node_image as builder
ENV NODE ENV=production
@natterstefan
natterstefan / Dockerfile
Created March 16, 2021 10:26
Docker | Simple NodeJS Dockerfile
# We use the latest nodejs@14 image as our base image
FROM node:14-alpine
# set the default NODE_NEV to production
ENV NODE ENV=production
# make sure everything happens inside the /app folder
WORKDIR/app
# now we cache the node_modules layer
@natterstefan
natterstefan / asdf-set-version.sh
Created March 7, 2021 07:00
adsf | Set version
asdf global <name> <version> [<version>...]
asdf shell <name> <version> [<version>...]
asdf local <name> <version> [<version>...]
# asdf global nodejs 14.15.4