Skip to content

Instantly share code, notes, and snippets.

View ethaizone's full-sized avatar
💭
It's same on Gitlab.

Nimit Suwannagate ethaizone

💭
It's same on Gitlab.
View GitHub Profile
@ethaizone
ethaizone / react-context-usereducer-pattern-guide.md
Last active March 24, 2025 04:18
React Context + useReducer Pattern Guide

React Context + useReducer Pattern Guide

A clean and lightweight alternative to Redux using React's built-in Context + useReducer. Great for small to medium applications that need global state management without the overhead of additional libraries.

Example demonstrates a counter implementation but can be extended for more complex state management needs.

Overview

This guide shows a clean and type-safe approach to implementing global state management in React without external state management libraries. Perfect for small to medium-sized applications where Redux might be overkill.

Features

@ethaizone
ethaizone / terminal-prompt-git-branch-status-zsh.md
Last active February 20, 2025 05:46 — forked from reinvanoyen/terminal-prompt-git-branch-zsh.md
Add Git Branch Name and Status to Terminal Prompt (MacOS zsh)

Add Git Branch Name and Status to Terminal Prompt (zsh)

image

Install

Open ~/.zshrc in your favorite editor and add the following content to the bottom.

git_status() {
    # Early return if not in a git repository
@ethaizone
ethaizone / json-float-as-string.py
Last active October 21, 2024 10:05
Junior in team asked me if they don't want to see exponential notation in json, how to do in python?
import json
import re
class CustomJSONEncoder(json.JSONEncoder):
def encode_float(self, obj):
if isinstance(obj, float):
return format(obj, "f").rstrip('0').rstrip('.')
return super().encode(obj)
def encodeObj(self, obj):
@ethaizone
ethaizone / extension_on_enum.dart
Last active May 26, 2024 08:04
Dart: Note collections
// Example about using extension on Enum.
enum ValidationError { empty }
// Magical happen in here but it's on this enum only. Not in prototype.
extension ValidationErrorMessage on ValidationError {
String text(String label) {
switch (this) {
case ValidationError.empty:
return 'Please enter a password';
@ethaizone
ethaizone / replaceNullStringWithUndefined.ts
Created February 6, 2024 11:24
TS function to alter value in each items and can loop if it's array.
/**
* This function recursively replaces all 'null' string values with undefined in an object or array of objects.
*
* @author Nimit Suwannagate <[email protected]>
*
* @param {T} obj - The object or array of objects to process. The object's values can be of type string, number, or undefined.
* @returns {T} - The processed object or array of objects with all 'null' string values replaced with undefined.
*
* @template V - The type of the values in the object. Defaults to string | number | undefined.
* @template R - The type of the object. Defaults to Record<string, V>.
@ethaizone
ethaizone / sentryMiddleware.ts
Last active June 29, 2023 06:17
Sentry middleware for Redux toolkit
// FYI. I added this as history data but I don't use it on actual project because `createAsyncThunk` did serialize on error object.
import { isRejected, isRejectedWithValue } from '@reduxjs/toolkit'
import type { AnyAction, Middleware, MiddlewareAPI } from '@reduxjs/toolkit'
import * as Sentry from '@sentry/react'
/**
* Log a error and send to sentry
*/
export const sentryMiddleware: Middleware =
@ethaizone
ethaizone / example.py
Last active August 20, 2019 09:16
Python recursive call as decorator.
from bson import ObjectId
import functools
# Created by Nimit Suwannagate
def recursive_all(f):
"""
Decorator for making recursive function.
:param f:
:return:
@ethaizone
ethaizone / anime_internet_radio.txt
Created August 3, 2019 17:28
Anime internet radio collection.
# ~320kbps
## ANISON.FM
http://pool.anison.fm:9000/AniSonFM(320)
# ~128kbps
## Radio Forever Anime
http://199.168.188.202:9310/
## AnimeNfo Radio
http://itori.animenfo.com:443/
@ethaizone
ethaizone / dump.php
Last active May 31, 2018 04:55
[PHP] Dump collection.
<?php
/**
* Dump collection. For who can't set breakpoint in their project.
*
* By EThaiZone
*/
if (! function_exists('jd')) {
/**
* Dump and json and exit
@ethaizone
ethaizone / git.sh
Created May 17, 2018 08:08
Save working space by git stash then make patch file for apply later.
# Credit: https://stackoverflow.com/questions/3973034/export-a-stash-to-another-computer
# First just stash your working space
git stash
# Maybe you need check your stash which file that have right now.
git stash show
git stash show -p
# Create patch file from whole your stash