Skip to content

Instantly share code, notes, and snippets.

View bact's full-sized avatar
🥕
Writing to reach you

Arthit Suriyawongkul bact

🥕
Writing to reach you
View GitHub Profile
@bact
bact / tweet-archive-to-common-voice.py
Last active June 13, 2021 01:13
Prepare text from Twitter archive JSON for Thai Common Voice Sentence Collector submission
# 1) export text from JSON
import json
import pandas as pd
from pandas import json_normalize
# note: have to remove `window.YTD...` in the first line
data = json.load(open('bact-tweet.json'))
df = pd.DataFrame.from_records(json_normalize(data))
df = df[df["tweet.lang"] == "th"]
@bact
bact / thai_to_arabic_digits.py
Created July 6, 2019 09:44
Convert Thai digits to Arabic digits
_THAI_ARABIC = {
"๐": "0",
"๑": "1",
"๒": "2",
"๓": "3",
"๔": "4",
"๕": "5",
"๖": "6",
"๗": "7",
"๘": "8",
@bact
bact / thai_strftime.py
Last active March 21, 2024 05:28
Thai date and time string formatter
# thai_strftime()
# Thai date and time string formatter
# Formatting directives similar to datetime.strftime()
#
# จัดรูปแบบข้อความวันที่และเวลา แบบเดียวกับ datetime.strftime()
# โดยจะใช้ชื่อเดือนเป็นภาษาไทย และปีเป็นพุทธศักราช
# (ไม่รองรับปีก่อน พ.ศ. 2484 - ก่อนการเปลี่ยนวันปีใหม่ไทย)
#
# No Rights Reserved
# PUBLIC DOMAIN or CC0 1.0 Universal
@bact
bact / is_one_swap_can_sort.py
Last active September 23, 2018 18:19
Find if a list of int can be sorted by only one swap
def is_one_swap_can_sort(nums):
sorted_nums = sorted(nums)
if nums == sorted_nums:
return True
len_nums = len(nums)
for i in range(len_nums):
for j in range(i+1, len_nums):
test = nums.copy()
if test[i] > test[j]:
@bact
bact / bingap_regex.py
Last active June 26, 2021 06:30
find binary gap using regular expression
import re
def bingap(num): # wronggggg
zeroes = re.findall(r"0+", bin(num)[2:])
return len(max(zeroes, key=len)) if zeroes else 0
n = 32
print(bin(n))
bingap(n)
@bact
bact / keybase.md
Created April 8, 2016 08:39
keybase proof

Keybase proof

I hereby claim:

  • I am bact on github.
  • I am bact (https://keybase.io/bact) on keybase.
  • I have a public key ASA8vzg-kfcvZpfOGoeTXJR8gVCxI4B3NQ3I8H8JQ15B8Ao

To claim this, I am signing this object: