Skip to content

Instantly share code, notes, and snippets.

View wannaphong's full-sized avatar
🧭
out-of-time

Wannaphong Phatthiyaphaibun wannaphong

🧭
out-of-time
View GitHub Profile
@wannaphong
wannaphong / map.cs
Created January 22, 2017 12:25 — forked from huangcd/map.cs
a map function like python in C#
public static IEnumerable<TResult> Map<in TSource, TResult>(IEnumerable<TSource> sources, Func<TSource, TResult> mapper)
{
foreach (var source in sources)
{
yield return mapper(source);
}
}
@wannaphong
wannaphong / q.py
Created January 22, 2017 12:42 — forked from fheisler/q.py
Q-learning Tic-tac-toe
import random
class TicTacToe:
def __init__(self, playerX, playerO):
self.board = [' ']*9
self.playerX, self.playerO = playerX, playerO
self.playerX_turn = random.choice([True, False])
def play_game(self):
import logging
import os.path
import sys
from gensim.corpora import WikiCorpus
if __name__ == '__main__':
program = os.path.basename(sys.argv[0])
logger = logging.getLogger(program)
# -*- coding: utf-8 -*-
import logging
import os.path
import sys
import multiprocessing
from gensim.corpora import WikiCorpus
from gensim.models import Word2Vec
from gensim.models.word2vec import LineSentence
if __name__ == '__main__':
@wannaphong
wannaphong / thai-wordnet.py
Last active February 4, 2017 03:59
เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์ ใช้ประกอบบทความ https://python3.wannaphong.com/2017/02/wordnet-ภาษาไทยกับ-python.html โดยใช้ฐานข้อมูล Thai WordNet โหลดได้ที่ https://sourceforge.net/projects/thwnsqlite/files/thwnsqlite-201405121006.tar.bz2/download
# -*- coding: utf-8 -*-
# อ่านบทความได้ที่ https://python3.wannaphong.com/2017/02/wordnet-ภาษาไทยกับ-python.html
from __future__ import print_function
import sqlite3
from collections import namedtuple
conn = sqlite3.connect('tha-wn.db')
Word = namedtuple('Word', 'synsetid li')
Synset = namedtuple('Synset', 'synset li')
def getWords(wordid):
words = []
@wannaphong
wannaphong / jdutil.py
Created February 11, 2017 16:58 — forked from jiffyclub/jdutil.py
Functions for converting dates to/from JD and MJD
"""
Functions for converting dates to/from JD and MJD. Assumes dates are historical
dates, including the transition from the Julian calendar to the Gregorian
calendar in 1582. No support for proleptic Gregorian/Julian calendars.
:Author: Matt Davis
:Website: http://github.com/jiffyclub
"""
@wannaphong
wannaphong / builder.py
Created March 8, 2017 16:30 — forked from pazdera/builder.py
Example of `builder' design pattern in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of `builder' design pattern
# Copyright (C) 2011 Radek Pazdera
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" lang="th" xml:lang="th"><head><title>Scala</title><meta name="keywords" content=" reddit, reddit.com, vote, comment, submit " /><meta name="description" content="reddit: the front page of the internet" /><meta name="referrer" content="always"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link type="application/opensearchdescription+xml" rel="search" href="/static/opensearch.xml"/><link rel="canonical" href="https://www.reddit.com/r/Python/" /><meta name="viewport" content="width=1024"><link rel="dns-prefetch" href="//out.reddit.com"><link rel="preconnect" href="//out.reddit.com"><link rel='icon' href="//www.redditstatic.com/icon.png" sizes="256x256" type="image/png" /><link rel='shortcut icon' href="//www.redditstatic.com/favicon.ico" type="image/x-icon" /><link rel='apple-touch-icon-precomposed' href="//www.redditstatic.com/icon-touch.png" /><link rel="alternate" type="application/atom+xml" title="RSS" href="https://www.reddit.
@wannaphong
wannaphong / ทำนายจำนวนประชากรไทย.py
Last active May 14, 2017 16:38
ทำนายจำนวนประชากรของไทยด้วย Scikit-learn ใน Python https://python3.wannaphong.com/2017/05/thailand-population-scikit-learn-python.html
# ทำนายจำนวนประชากรของไทยด้วย Scikit-learn ใน Python
# เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์
# https://python3.wannaphong.com
# อ่านได้ที่ https://python3.wannaphong.com/2017/05/thailand-population-scikit-learn-python.html
# 14 พ.ค. 2560
'''
สร้าง dataset ข้อมูลประชากร
'''
thai = [20986780,
21550597,
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
time = pd.date_range('1951', periods=67, freq='A') # สร้างช่วงเวลา โดยจะเรียงจาก ปี 1951 ไล่ต่อมา 67 ปี A คือ ปี
listtime=time.tolist()
plt.plot(listtime,thai)
plt.show() # แสดงข้อมูลประชากรจากอดีต
data=pd.DataFrame({'date':time.values,'value':thai})
data['date_ordinal'] = data['date'].apply(lambda x: x.toordinal()) # แปลงวันเดือนปีไปเป็น proleptic Gregorian ordinal