Skip to content

Instantly share code, notes, and snippets.

View hungify's full-sized avatar
🎯
Focusing

hungify hungify

🎯
Focusing
  • ˋ@2024ˎˊ
  • undefined, Vietnam
  • 06:13 (UTC +07:00)
View GitHub Profile
@hungify
hungify / react.md
Last active May 15, 2024 15:49
Summary about React Ecosystem

Summary

  • React always recursively renders components by default, so when a parent renders, its children will render
  • Rendering by itself is fine - it's how React knows what DOM changes are needed
  • But, rendering takes time, and "wasted renders" where the UI output didn't change can add up
  • It's okay to pass down new references like callback functions and objects most of the time APIs like React.memo() can skip unnecessary renders if props haven't changed
  • But if you always pass new references down as props, React.memo() can never skip a render, so you may need to memoize those values
  • Context makes values accessible to any deeply nested component that is interested
  • Context providers compare their value by reference to know if it's changed
  • A new context values does force all nested consumers to re-render but, many times the child would have re-rendered anyway due to the normal parent->child render cascade process
@hungify
hungify / refresh-token-machine.tsx
Last active May 12, 2024 08:21
Refresh Token Machine (X Time before expiration)
"use client";
import dayjs from "dayjs";
import { jwtDecode } from "jwt-decode";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { useAuthContext } from "../auth/context";
export default function RefreshTokenMachine() {
const [diff, setDiff] = useState<number>(1000);
@hungify
hungify / keymap.json
Last active October 14, 2024 15:08
My Zed keymap Settings
[
// Bindings from VS Code
{
"context": "Editor",
"bindings": {
"cmd-shift-k": "editor::DeleteLine",
"cmd-i": "editor::ShowCompletions",
"shift-pageup": "editor::SelectToBeginning",
"shift-pagedown": "editor::SelectToEnd",
"cmd-pageup": "editor::PageUp",
@hungify
hungify / settings.json
Last active October 14, 2024 15:07
My Zed Settings
{
"assistant": {
"default_model": {
"provider": "copilot_chat",
"model": "gpt-4o"
},
"version": "2"
},
"terminal": {
"cursor_shape": "bar"
@hungify
hungify / alpine_cron_job.md
Last active December 3, 2023 09:40
Running cron job inside a Docker container with Alpine distribution.

Running cron job inside a Docker container with Alpine distribution

With Docker

alpine.dockerfile

FROM alpine

RUN which crond && rm -rf /etc/periodic