Skip to content

Instantly share code, notes, and snippets.

Avatar

Korakot Chaovavanich korakot

  • VISTEC
  • Bangkok, Thailand
View GitHub Profile
@korakot
korakot / zig.py
Last active February 4, 2023 13:32
Install zig in Colab
View zig.py
url = 'https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz'
!curl $url | tar xJ
!mv zig-linux-x86_64-0.10.1 /opt/bin
%%file main.zig
const std = @import("std");
pub fn main() void {
std.debug.print("Hello world\n", .{});
}
@korakot
korakot / table.txt
Created January 19, 2023 07:40
Table in markdown
View table.txt
| | | | | |
|---|---|---|---|---|
| | | | | |
| | | | | |
| | | | | |
@korakot
korakot / strip_context.py
Last active January 20, 2023 02:36
Strip line to get only context around a word
View strip_context.py
def context(line, word, padding=40):
# หาคำแรก แล้ว pre-40, หาคำสุดท้าย post+40 เอาง่ายๆ แบบนี้ล่ะ
p1 = line.index(word)
p1s = line.rfind(' ', 0, max(0, p1-padding))
if p1s==-1:
p1s = 0
p2 = line.rindex(word)
p2s = line.find(' ', min(len(line), p2+padding))
if p2s == -1:
p2s = len(line)
@korakot
korakot / docx_lines.py
Last active January 19, 2023 04:06
Extract lines from docx (word document)
View docx_lines.py
from pathlib import Path
!pip -q install python-docx
from docx import Document
files = list(Path('docx').glob('*.docx'))
def docx_lines(path):
doc = Document(path)
lines = []
for para in doc.paragraphs:
@korakot
korakot / s3.txt
Created December 11, 2022 05:41
S3 public URL
View s3.txt
# bucket: dham
# path: /first.wav
https://dham.s3.amazonaws.com/first.wav
# longer URL with region
https://dham.s3.us-west-2.amazonaws.com/first.wav
@korakot
korakot / transcribe_status.py
Created November 17, 2022 02:46
Check status of Amazon transcription jobs
View transcribe_status.py
import boto3
tran = boto3.client('transcribe')
def check_jobs(in_name):
jobs = []
resp = tran.list_transcription_jobs(JobNameContains=in_name)
while True:
jobs += resp['TranscriptionJobSummaries']
next_token = resp.get('NextToken')
@korakot
korakot / remove.sh
Created November 16, 2022 05:43
Remove jupyter kernel without prompt
View remove.sh
jupyter kernelspec remove ir -f
@korakot
korakot / clear.py
Created October 29, 2022 06:44
Clear cell output in Colab
View clear.py
from google.colab import output
output.clear()
# IPython also has clear_output() but this is shorter.
@korakot
korakot / u16.py
Created October 24, 2022 04:54
Read UTF-16 (u16) file
View u16.py
import io
text = io.open('aa1.txt', encoding='utf-16-le').read()
@korakot
korakot / natsort.py
Last active October 24, 2022 04:21
Natural Sort in python
View natsort.py
import re
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
sorted(items, key=alphanum)
# another solution
natsort = lambda s: [int(t) if t.isdigit() else t.lower() for t in re.split('(\d+)', s)]
sorted(items, key=natsort)