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 / server_time_sync.js
Last active December 16, 2022 12:37
Sync server time to client browser with JS. Implement follow Network Time Protocol.
// Thanks http://stackoverflow.com/questions/1638337/the-best-way-to-synchronize-client-side-javascript-clock-with-server-date
var serverTimeOffset = false;
function getServerTime(callback) {
if (serverTimeOffset === false) {
var scripts = document.getElementsByTagName("script"),
URL = scripts[scripts.length - 1].src;
var clientTimestamp = Date.parse(new Date().toUTCString());
@ethaizone
ethaizone / array.php
Created June 11, 2015 04:05
Array collection helpers. Ported from Laravel4.
<?php
/**
* Array collection helpers
*
* Ported from Laravel4.
* By EThaiZone
*/
if ( ! function_exists('array_add'))
{
@ethaizone
ethaizone / redirect_mobile_to_app_store.php
Last active May 24, 2022 17:56
[PHP] Auto redirect to app store. (Android/IOS)
<?php
// android store
if (preg_match('#android#i', $_SERVER ['HTTP_USER_AGENT'])) {
header('Location: market://details?id=com.google.android.apps.maps');
exit;
}
// ios
if (preg_match('#(iPad|iPhone|iPod)#i', $_SERVER ['HTTP_USER_AGENT'])) {
@ethaizone
ethaizone / git_autocommit_all.bat
Created October 18, 2013 06:58
Commit git with bat file
@echo off
echo type "commit" or "update"
cd "curl"
set GIT_PATH="C:\Program Files (x86)\Git\bin\git.exe"
set BRANCH = "origin"
:P
set ACTION=
set /P ACTION=Action: %=%
@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 / mb_str_split.php
Created January 23, 2016 16:52
mb_str_split function. multibyte version of str_split.
<?php
if (!function_exists('mb_str_split')) {
/**
* Convert a multibyte string to an array
*
* @param string $string The input string.
* @param integer $split_length Maximum length of the chunk.
* @param string $encoding The encoding parameter is the character encoding.
* @return array
@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