Skip to content

Instantly share code, notes, and snippets.

View kittinan's full-sized avatar
🇹🇭
|||

Kittinan kittinan

🇹🇭
|||
View GitHub Profile
@kittinan
kittinan / sample_thread_pool.py
Created February 20, 2018 05:21
Python 3 Thread Pool Sample
# Ref: http://masnun.com/2016/03/29/python-a-quick-introduction-to-the-concurrent-futures-module.html
import time
import random
from concurrent.futures import ThreadPoolExecutor, wait, as_completed
def add(name):
res = random.randint(1, 5)
res = 2
@kittinan
kittinan / client.py
Last active March 26, 2025 08:29
Python OpenCV webcam send image frame over socket
import cv2
import io
import socket
import struct
import time
import pickle
import zlib
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('192.168.1.124', 8485))
@kittinan
kittinan / cnn_with_other_data.py
Last active February 28, 2018 09:31
Keras add a variable into a convolutional neural network's dense layer
"""
Adding a variable into Keras/TensorFlow CNN dense layer
https://stackoverflow.com/questions/42556919/adding-a-variable-into-keras-tensorflow-cnn-dense-layer
___________ _________ _________ _________ ________ ______
| Conv | | Max | | Conv | | Max | | | | |
Image --> | Layer 1 | --> | Pool 1 | --> | Layer 2 | --> | Pool 2 | -->| | | |
|_________| |________| |_________| |________| | Dense | | Out |
| Layer |-->|_____|
#Edit /etc/network/interfaces
auto wlan0
iface wlan0 inet dhcp
wpa-ssid {ssid}
wpa-psk {password}
@kittinan
kittinan / tts_play.py
Created March 23, 2018 03:33
Raspberry PI Thai TTS and speak
import subprocess
from gtts import gTTS
def play_mp3(path):
subprocess.Popen(['mpg123', '-q', path]).wait()
text = "สวัสดี"
tts = gTTS(text=text, lang='th')
tts.save("hello.mp3")
play_mp3("hello.mp3")
@kittinan
kittinan / score.txt
Last active April 6, 2018 00:52
Deepcut JS score
Model: lite_model_v1.h5 (Dense 100)
f1score: 0.979600348056747
precision: 0.9749029122509861
recall: 0.9843432709344426
Model: lite_model_v1_1.h5 (Dense 100)
f1score: 0.9807887916860532
precision: 0.9759241434331015
recall: 0.9857021801093907
@kittinan
kittinan / plot_history.py
Created April 10, 2018 14:44
keras plot history object
# Ref: https://www.kaggle.com/danbrice/keras-plot-history-full-report-and-grid-search
def plot_history(history):
loss_list = [s for s in history.history.keys() if 'loss' in s and 'val' not in s]
val_loss_list = [s for s in history.history.keys() if 'loss' in s and 'val' in s]
acc_list = [s for s in history.history.keys() if 'acc' in s and 'val' not in s]
val_acc_list = [s for s in history.history.keys() if 'acc' in s and 'val' in s]
if len(loss_list) == 0:
print('Loss is missing in history')
return
@kittinan
kittinan / AESCipher.py
Created April 30, 2018 04:02 — forked from swinton/AESCipher.py
Encrypt & Decrypt using PyCrypto AES 256 From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
@kittinan
kittinan / download.py
Last active May 4, 2018 09:50
Download Youtube Audio with multi threading
import pandas as pd
import youtube_dl
import os
from youtube_dl.utils import DownloadError
from concurrent.futures import ThreadPoolExecutor, wait, as_completed
def download_youtube(youtube_id, idx):
@kittinan
kittinan / remote.py
Created May 11, 2018 09:51
Broadlink send IR command
import pickle
import broadlink
import sys
import os
if len(sys.argv) != 3:
sys.exit(0)
type = sys.argv[1]
command = sys.argv[2]