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 / 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 <ethaizone@hotmail.com>
*
* @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
@ethaizone
ethaizone / cmd.sh
Created May 12, 2018 07:05
MySQL - Dump and import with GZip
# Export
mysqldump -u root -p your_db | gzip -c > your_db_2018-05-12.sql.gz
# Export with datetime in filename
mysqldump -u root -p your_db | gzip -c > your_db_$(date +%Y-%m-%d-%H.%M.%S).sql.gz
# Import
zcat your_db_2018-05-12.sql.gz | mysql -u root -p your_db
@ethaizone
ethaizone / safe_math_operator.js
Created September 28, 2017 07:44
Example how to make math calculation with safe output
const countDecimals = function (value) {
if(Math.floor(value) === value) return 0;
return value.toString().split(".")[1].length || 0;
}
const operators = {
'+': (a, b) => {
let decimalLength = Math.pow(10, Math.max(countDecimals(a), countDecimals(b)))
return ((a*decimalLength) + (b*decimalLength))/decimalLength
},
@ethaizone
ethaizone / await.js
Created July 26, 2017 07:09
How to use await with promise. Javascript.
// USE BABEL WITH PRESET ES2017
// FUCKING AWESOME PROMISE EXAMPLE
// FIRST PROMISE
function a() {
return Promise.resolve([1, 2, 3, 4, 5, 6])
// return Promise.reject(new Error("xxxx"))
}
@ethaizone
ethaizone / pstorm
Last active June 11, 2018 08:27
[Windows] Make any GUI program and run from CLI. This example is PHPStorm.
#!/bin/sh
basedir=`dirname "$0"`
# This is like symlink for bash cmd such as mintty, GIT bash, Cygwin
# I pass parameters to it too.
"$basedir/pstorm.cmd" "$@"
# Note - I tried create symlink but it not work at bash environment