This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bson import ObjectId | |
import functools | |
# Created by Nimit Suwannagate | |
def recursive_all(f): | |
""" | |
Decorator for making recursive function. | |
:param f: | |
:return: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Dump collection. For who can't set breakpoint in their project. | |
* | |
* By EThaiZone | |
*/ | |
if (! function_exists('jd')) { | |
/** | |
* Dump and json and exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}, |
NewerOlder