Skip to content

Instantly share code, notes, and snippets.

View ekrresa's full-sized avatar
🎯
chilling...

Ochuko Ekrresa ekrresa

🎯
chilling...
View GitHub Profile
@ekrresa
ekrresa / useLocalStorage.tsx
Last active December 29, 2023 00:21
Custom react hook to manage localStorage values. SSR safe
export function useLocalStorage<T>(key: string, initialValue: T) {
const [value, setValue] = React.useState<T | undefined>(() => initialValue);
// Gets initial value from localStorage if available
React.useLayoutEffect(() => {
let initialValue;
try {
const localStorageValue = localStorage.getItem(key);
@kandros
kandros / .dockerignore
Last active December 17, 2020 09:10
Dockerfile for next.js projects
e2e
fixtures
*.test.*
node_modules
.next
.env
Dockerfile
.git
@flybayer
flybayer / env.ts
Created September 15, 2020 23:10
zod env validation
// config/env.ts
import assert from "utils/assert"
import * as z from "zod"
assert(typeof window === "undefined",
"The config/env.ts file cannot be used in the browser")
const isProduction = process.env.NODE_ENV === "production"
const isDevelopment = process.env.NODE_ENV === "development"
const isTest = process.env.NODE_ENV === "test"
@bradtraversy
bradtraversy / node_nginx_ssl.md
Last active June 19, 2024 00:37
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@stolinski
stolinski / useMeasure.js
Created April 18, 2019 18:16
useMeasure - taken from React Spring example
import { useRef, useState, useEffect } from 'react'
import ResizeObserver from 'resize-observer-polyfill'
export default function useMeasure() {
const ref = useRef()
const [bounds, set] = useState({ left: 0, top: 0, width: 0, height: 0 })
const [ro] = useState(() => new ResizeObserver(([entry]) => set(entry.contentRect)))
useEffect(() => (ro.observe(ref.current), ro.disconnect), [])
return [{ ref }, bounds]
}
@yoavniran
yoavniran / ultimate-ut-cheat-sheet.md
Last active June 1, 2024 09:44
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon, and Jest

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.