Skip to content

Instantly share code, notes, and snippets.

View thinnakrit's full-sized avatar
🏕️
I love camping :D

Thinnakrit thinnakrit

🏕️
I love camping :D
View GitHub Profile
[
{
"facility_name": {
"en": "Free Wi-Fi",
"th": "ฟรี Wi-Fi",
"cn": "免费无线网络"
},
"facility_id": "WIFI"
},
{
@thinnakrit
thinnakrit / translate-chatgpt.ts
Last active March 29, 2023 05:23
Next.js : ChatGPT API for translated
import type { NextApiRequest, NextApiResponse } from 'next';
const axios = require('axios');
const openaiKey = 'OPEN_AI_KEY';
const getOpenAI = async (prompt: string) => {
const response = await axios.post(
'https://api.openai.com/v1/completions',
{
@thinnakrit
thinnakrit / disabledDate.ts
Last active October 27, 2022 10:43
Antd: disabledDate by set condition disabled before start date and disable end of month
import moment from 'moment'
export const convertDateToTimestamp = (date: string, format: string): number => {
if (format === 'DD/MM/YYYY') {
const dateToParts = date.split("/");
const dateToFormat = Number(new Date(+Number(dateToParts[2]), Number(dateToParts[1]) - 1, +Number(dateToParts[0])));
return dateToFormat
} else {
return 0
}
@thinnakrit
thinnakrit / calculateImpermanentLoss.js
Last active May 14, 2021 02:29
calculateImpermanentLoss.js
const calcAPoolSize = (aPrice, constantProduct) => {
return Math.sqrt(constantProduct / aPrice);
};
const calcBPoolSize = (aPrice, constantProduct) => {
return Math.sqrt(constantProduct * aPrice);
};
const calculateImpermanentLoss = (
priceInitialA,
_.zip(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]
// xor
_.xor([2, 1], [2, 3]);
// => [1, 3]
// xorBy
_.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2, 3.4]
_.without([2, 1, 2, 3], 1, 2);
// => [3]
// uniq
_.uniq([2, 1, 2]);
// => [2, 1]
// uniqBy
_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]
// union
_.union([2], [1, 2]);
// => [2, 1]
// unionBy
_.unionBy([2.1], [1.2, 2.3], Math.floor);
// => [2.1, 1.2]
// take
_.take([1, 2, 3]);
// => [1]
_.take([1, 2, 3], 2);
// => [1, 2]
_.take([1, 2, 3], 5);
// => [1, 2, 3]