Profile

Click to view full profile
Hi, I'm Veerapat Sriarunrungrueang, an expert in technology field, especially full stack web development and performance testing.This is my coding diary. I usually develop and keep code snippets or some tricks, and update to this diary when I have time. Nowadays, I've been giving counsel to many well-known firms in Thailand.
view more...

Tuesday, December 28, 2010

How to Lemmatization with Wordnet in NLTK

We can convert a word back to its basic form by using wordnet lemmatizer. Moreover, we can specific part of speech to check its form: n->noun, v->verb, a->adjective, r->adverb (if not specify, it will be noun).
from nltk.stem.wordnet import WordNetLemmatizer
l = WordNetLemmatizer()
l.lemmatize('cars')            # car
l.lemmatize('women')           # woman
l.lemmatize('fantasized','v')  # fantasize
So, a word will be checked with wordnet to see its basic form according to part of speech.

Monday, December 27, 2010

What's the difference between list and tuples in Python?

The key difference is tuple is immutable but list is not. So, tuple can be used as a key in dictionary and get more slight performance and tuple has a structure but list has a order.

Thursday, December 23, 2010

Wordnet Interface in Python with NLTK

Currently, my project involves with natural language processing and also wordnet for seeing the relationship between word meanings. In python, wordnet can be used with NLTK. NLTK has a wordnet of Princeton University.The main features that are supported in NLTK as following: synset, lemma, hypernym, hyponym, antonym and path similarity.

Basic use examples:
import nltk
from nltk import wordnet as wn
#looking word's synsets
wn.synsets('beautiful')
#synsets
car = wn.synset('car.n.01')
car.lemmas
car.hypernyms()
car.hyponyms()
#antonyms
car.lemmas[0].antonyms()

See more details at:
http://nltk.googlecode.com/svn/trunk/doc/howto/wordnet.html
http://wordnet.princeton.edu/

Sunday, December 12, 2010

How to make object support indexing in python (object[index])

Sometime, we may want the object can do like array or dict that use object[index] instead of object.getsomthing() for making it more convenience. So, the solution is easy, python provide us the attribute for creating object support indexing that is "__getitem__(key)".

For example
class Test:
 def __getitem__(self,key):
  return 0

a = Test()
print a[2]
print a["hello"]
We can modify its behavior in the method.
More information about python attributes at: http://docs.python.org/reference/datamodel.html

Saturday, December 11, 2010

Beginning with Text to Speech in Android

For this post, my motivation came from creating a program to speak some books. So, I need text to speech.
Then, I found these two resources from android site which are very interesting and easy to understand. Those two links are as following:

http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html
http://android-developers.blogspot.com/2010/03/speech-input-api-for-android.html

Two sites can help you to begin with text to speech in android .
Enjoy ^^

TweetDeck Manual for Thai

Try this link: http://variety.eduzcom/

How to check subclass in python

An object oriented in python is different from full-support object oriented like java or etc. To check subclass, we need to use built-in function from python called "issubclass"

Ok, let's begin with issubclass(class, classinfo).
class A(object):
 pass

class B(A):
 pass

a = A()
b = B()

print issubclass(a.__class__,A)
print issubclass(b.__class__,B) 

It is easy right? ^^

Wednesday, December 1, 2010

How to get current Date/Time in Python

In my project, sometimes I have to used current date to compare. So, we need to get date from the system.
import datetime
dt = datetime.datetime.now()
print dt.year
print dt.month
print dt.day
print dt.hour
print dt.minute
print dt.second
Very easy right ^^

Divinity 2: Statue Puzzle at Keara’s Headquarters

Divinity 2 is an interesting game for me in the story and game play. While I playing this game, I feel I'm in the game. The broad story is very simple. It's the story between dragon knight and dragon slayer. And once our character will be a dragon slayer who hunt the dragons but ,by chance, our character will be a dragon knight. And both sides become our opponents.

So far, I walk to Keara's Headquaters, and face with the puzzle problems in the games. I'm interested in this puzzle about how the creator think this puzzle? for me, it's very hard to solve it.

There 5 five statues. We have to identify their names to open the last door in order to fight with Keara.
There are 2 types of statue. First one will be statue with the fire blades, another one will be statue with the blades.
I will give 5 statues into the number of 1, 2, 3, 4 and 5  for easy understanding.
There are 5 five names: Mayhem, Chaos, Devastation, Havoc, Waste.

The first room, (1) stay alone and it's a fire blades type.
The second room, (2), (3) stay together. (2) is a blades and (3) is a fire blades.
The third room, (4), (5) stay together. (4) is a fire blades and (5) is a blades.

Each statue will give us clues.
(1) hints: Mayhem is not in the same room as Havoc. Devastation is in
the same room as Chaos.

(2) hints: I am either Devastation or Chaos. Waste is in the same room
as Mayhem.

(3) hints: Mayhem is alone in his room. Havoc is in this room.

(4) hints: I am neither Chaos, nor Havoc. Chaos is neither in my room,
nor in Waste's.

(5) hints: I am in the same room as Waste. I am neither Mayhem, nor
Waste.

We have to identify each statue name with those hints. At last, I can pass but take a long time - -".

Hints: Some sentences are lying, we have to change them into opposite way.
Answer: (1) is Devastation, (2) is Waste, (3) is Chaos, (4) is Havoc, and (5) is Mayhem.
(Drag over to see hints and answer.)

Hope that it can help ^^

Sunday, November 21, 2010

How to run parallel programs(MPI) in Windows

Long time ago, I had tried HPC in Windows for running MPI. Fortunately, I just found it in my old tweet --".
So, if you want to try go to this link: http://blogs.msdn.com/b/risman/archive/2009/01/04/ms-mpi-with-visual-studio-2008.aspx

Saturday, November 20, 2010

How to set an environment for running parallel programs(MPI) with MPICH in Linux

One of my class in this semester is Parallel Programming. Normally, I have to use cluster computer in the faculty by using remote log in, but, I don't like when I have to modify codes or create new codes, I have to upload it to the server. It's not convenience for me. So, I just find the solution to run parallel code (MPI) in one single machine that can work as the cluster with one machine.

The solution is we can use mpich2 package. The step to install is here.

Requirement:
You have to use Linux (I try with Ubuntu 10.10 and Mint 9). You may run this os through a Virtual Machine.

Step:
1. If your machine doesn't install gcc then type : "sudo apt-get install gcc"
2. Then you install mpich2 by using this command : "sudo apt-get install mpich2"
3. After you install come to your home folder e.g. /home/[your username] by : "cd $HOME"
4. Then you go to that directory and create the file name ".mpd.conf" and the content is "MPD_SECRETWORD=mr45-j9z"
5. type "chmod 600 .mpd.conf"
6. The directory that want to run code have to create the file name "mpd.hosts" which content is "localhost"
7. Finish configuration.

Test:
1. You have to boot mpd by "mpdboot -n 1"
2. Your machine Must be connected to the access point.
3. Compile program by "mpicc -o x x.c" ; where x is your code file name .
4. Run the code by "mpirun -np y ./x" ; where y is process number and x is object code name.

Now, You can run MPI code in your machine.
More Information: https://help.ubuntu.com/community/MpichCluster

Saturday, November 13, 2010

Barcamp Bangkok #4 2010 - My experience (Part2)

Last time, I talked about sections that I have no ideas and knowledge. But, in this part, I'm interested in topics then went to those rooms.

15:00 - 15:30 - Room 1001 - Seeking Hyper Productivity by @juacompy
The speaker come from Proteus Technologies. He is an employee in international company. In this section, he said that his company can do hyper productivity. In my opinion (conclusion), separate the factors that effect to the productivity into two sections: Project management and member personality. Project management includes group flow, how to manage works should be divided in functions not divide by tasks because if we divides work by tasks, for example, Jim gather requirements and John design database. How can John doing it? he know nothing about project requirements. It needs a lot of communication to succeed. So, he suggest to divide works by functions and then do work that related to own function. Also, which technologies we should use to achieve the project, he said he uses dynamic and appropriate languages to build. Doing from easy parts first and then follow by hard parts can increase your confident to make your productivity improve a lot. Second, Member personality, he said a project manager should understand his teammates very well, and also each member should know himself/herself very well to know what time they can have the highest productivity. Then manage themselves to do works in their prefer styles.

15:30 - 16:30 - Room 1002 - Agile Architecture by Ben Scherrey
In this topics,  I totally forgot about a story the speaker said on that day - -".
I know only he said he uses  test driven development and scrum to collaborate with his customer to reduce overhead. Also, has small cross function teams. For each team, one person know everything. Uses continuous integration entire processes. Write an automate testing to test the system.

16:30 - 17:30 - Room 1006 - All Mashed Up - HTML5 + JQuery + Google Code + YQL by Naoroll
I think the speaker come from Google Sigapore. He show how to connect HTML5 + JQuery + Google App Engine + YQL together. He also uses Google spreadsheet as database. Each sheet is similar to a table. Uses YQL to query everything from the internet like select * from internet for mesh up data which you can get it from Yahoo Developer Network. At the end, he gave a Google shirt if show him about our work. At that time, I forget about my Android game - -" to show him for a shirt. Again, he gave a Google sticker for each audience but, unfortunately, ran out of stickers in front of my eyes T_T

Next time, I will write about day 2.
Part 1: http://darkkung-blog.blogspot.com/2010/11/barcamp-bangkok-4-2010-my-experience.html
Part 3: http://darkkung-blog.blogspot.com/2011/02/barcamp-bangkok-4-2010-my-experience.html

Tuesday, November 9, 2010

Barcamp Bangkok #4 2010 - My experience (Part1)

In last month, Barcamp 4 was held on Oct 23rd and 24th at Sripatum University. In short, BarCamp is an international network of user-generated conferences — open, participatory workshop-events, whose content is provided by participants. More details at http://www.barcampbangkok.org/overview

The first day schedule is here: http://www.barcampbangkok.org/events/barcamp-4/2010-10-23
The second day schedule is here: http://www.barcampbangkok.org/events/barcamp-4/2010-10-24

My first day:
11:00 - 11:30 - Room 902 - Ruby Version Manager by Ake Koomsin
In this section, the speaker will talk about RVM to mangae version of ruby for pakage to install/uninstakk or use which version for each project. I think the speaker is great beacause he's not native but he can present in English and there are many foreign audiences who're interested in ruby too.

11:30 - 12:00 - Room 1003 - Introduction to GIT by Till
In this section, he talk about GIT which is versioning system to keep code in respository like SVN and manage code version. One downside of GIT is we have to use it with command line only(console).
Example Commands:
git add => to add a file into git server.
git commit -a => to update a file when we change something
git status => check status
git revert => reverse changes

12:30 - 13:00 - Room 905 - Why Eco Tourism sucks by Thomas Wahhoff
In short, he said eco tourism in some countries can't help the life of local people, and the quality and service are poor in rural areas especially foods. He said, in trips, he's very exhausted and can't conserve the nature.
I agree with him from what he said that a traveler want convenience, safe food, entertain, relax, and real experience. But there is no branding of eco tourism. So, it's suck.

14:30 - 15:00 - Room 1003 - How to bootstrap a company by Phil L
Because I'm not the person who want to create by own company (means that I've a little knowledge about it), so I can't understand some contents in this section. Basically, we have to create many interesting ideas first (10,000). Then, filter only good and practical ideas(20). Next, adjust or develop the remaining ideas(2). Finally, you will get the perfect idea(1).

p.s. It's not finish yet ^^, I will continue soon.
Part 2: http://darkkung-blog.blogspot.com/2010/11/barcamp-bangkok-4-2010-my-experience_13.html
Part 3: http://darkkung-blog.blogspot.com/2011/02/barcamp-bangkok-4-2010-my-experience.html

Saturday, November 6, 2010

How to list files in the directory in Python

Python can easily list files in the specific directory by using "dircache".

For example,

1. I have a folder "Test" under "C:\\", and this folder has 4 files contains 1.txt, 2.txt, 3.txt, 4.txt

2. Open the command at "C:\\" using "SHIFT + RIGHT CLICK"
more at => Windows: http://darkkung-blog.blogspot.com/2010/10/open-command-window-at-current-path-in.html
Linux-Ubuntu: http://darkkung-blog.blogspot.com/2010/10/quick-open-teminal-in-ubuntu-by-using.html

3. Type "python" to open Python Interactive Shell

4. Use the following code to see your files in that directory.

import dircache
flist = dircache.listdir("/Test/")
print flist

This technique can be used with "os.path" to check the contents in that directory which one is file or directory such as "os.path.isdir()", "os.path.isfile()".
more at => http://docs.python.org/library/os.path.html#os.path.islink


p.s. This technique is operating system independent.
Credit: http://www.programmersheaven.com/mb/python/191482/191482/list-files-in-a-directory/

Thursday, November 4, 2010

Add/Get current path to the system in Python

Some time, I may have to know the current path that I uses python interactive mode because I forget it = =", then may also to add it to the system path for something.
The solution is following:

1. Get the current path by using "os.getcwd()"
import os
os.getcwd()

2. Add the current path to the system by using "sys.path"
import sys
import os
# sys.path => will retrive the list of the system paths.
sys.path.add(os.getcwd())

Now, the current path will be added to the system path.

Monday, November 1, 2010

Differences between xrange() and range() functions in Python

Those 2 functions purpose is very similar when you use them in python, but the major different is range() function will generate the new list but xrange() is not. So, if your purpose doesn't use the advantage of the list to access you can just use xrange() function to make your code use less resources. For example, for-loop statement you can just use xrange() function to enumerate your loop.

for x in xrange(5):
 print x

Even you change xrange() function to range() function the result will be the same as:
0
1
2
3
4

But, As I already said, behind the scene range() function will generate it as a list that may make it slow when generate the big list for normal enumerate, xrange() function is enough.

Saturday, October 30, 2010

How to add code post in Blogger

First we have to put this under <head> tag in the Edit HTML of Blogger.

<script language="javascript" src="http://google-
code-prettify.googlecode.com/svn/trunk/src/prettify.js" 
type="text/javascript">
</script>
<link href="http://google-code-prettify.googlecode.com/svn/trunk
/src/prettify.css" rel="stylesheet" 
type="text/css">
</link>

Second, search for <body> tag and put
onload="prettyPrint()"
as attribute.

Finally, when you want to add code post you can write.
<pre class="prettyprint">
......... your code .........
</pre>

p.s. js,stylesheet can be downloaded and upload to somewhere ex. google-site and then change the link to your site.

Fire Drill at ICT [Continue]

At that time, there are 2 main parts: theory and workshop.
In the first part, it is an introduction about how to deal with fire and basic things to do to prevent fire occurring in the buildings. => In this part I came late, when I arrived, there are 5 minutes before took an exam.

So, I knew that they are classified into 4 kinds of objects to be fired as following: A-normal wood, paper and cloth, B-liquid that can be fired and oil, C-gas that can be fired, D-metal chemical substances such as magnesium.

In the second part, I have to practice how to get out of the buildings when fire emergency occurred, and I have to practice to carry injured people out from the buildings too. Finally, we practice to use fire extinguisher. Type A can use water to extinguish a fire. Type B can use dry-chemical, foam. Type C,D can use dry-chemical also.

Finally, on that day is really fun and know a lot of things to do when the buildings are fired :).

Monday, October 25, 2010

Print without a new line or space in Python

Normally, when we use print function in Python, it will automatically put new line at the end of the string. we can't omit it. So, there are 2 solutions as following:

1.
import sys 
sys.stdout.write("Hello")

2.
from __future__ import print_function 
print("Hello",end="")

Normally, end="\n" and print is not a function that means after string it will  be add "\n" at the end. Using __future__ to import print as function.

Now, we can print without a new line.

Saturday, October 23, 2010

How to test if object is sequence, or iterable?

In the java or c# languages, we can found that it is very easy to know that class is a collection by checking the interface Collection. But in python some time it can't check by using isinstance, issubclass methods. So, the solution is we can just used the __iter__ attribute in that object.

Friday, October 22, 2010

How to clear screen in Python Interactive Shell

Most of the time when I deal with interactive mode, there are a lot of lines. , this is a simply solution to solve this problem.
There are 2 methods
1. Short Key: Under Linux/UNIX system (on x86 at least) you can use the CTRL+L
2. Writing a code:

import os
if os.name == "posix":
# Unix/Linux/MacOS/BSD/etc
os.system("clear")
elif os.name in ("nt", "dos", "ce"):
# DOS/Windows
os.system("CLS")
 

Quick open teminal in Ubuntu by using one click

From the last entry, Windows can open command window at the current path in one click. Also, Ubuntu can do that too. The solution is here.
1. Open terminal.
2. Type "sudo apt-get install nautilus-open-terminal"
3. Restart your machine.
4. After that, when you right click at that directory, it will show tab for openning terminal.
5. Click at that tab, the terminal will be shown at the current directory you click.
p.s. Linux Mint can do that without any installation.
For Windows: http://darkkung-blog.blogspot.com/2010/10/open-command-window-at-current-path-in.html
For Mac: http://darkkung-blog.blogspot.com/2011/02/quick-open-terminal-in-mac-by-using-one.html

Open Command Window at the current path in one click

Hi all, do you ever lazy to change current directory in Windows manually? for me, the answer is yes.
Today, I have an very easy solution to make you happy :)

1. Go to the current directory that you want to work on.
2. Hold SHIFT button + Right click.














3. Click at Open command window here.














4. You got it!!!

p.s. Actually, this method can only work on Windows Vista and Windows 7.
For Linux-Ubuntu: http://darkkung-blog.blogspot.com/2010/10/quick-open-teminal-in-ubuntu-by-using.html
For Mac: http://darkkung-blog.blogspot.com/2011/02/quick-open-terminal-in-mac-by-using-one.html

Wednesday, October 20, 2010

Fire Drill at ICT

On 27 Wed Oct 2010, ICT faculty has a training about Fire Fighting!
The schedule is shown as following:

Oct 27, 2010
12.30 - Register IT204
13.00 - 14.30  - Practice to use bucket, fire extinguisher, dry chemical, gas co2.
14.45 - 16.30 - Practice to flee from the building by simulate the event with sign of fire alarm.

On that day, I will write gained experience again.

Monday, October 18, 2010

My first Android game - Pig Hunter

According to one of my class, Wireless class, I have to write mobile application and also select game application. Because of having an Android phone - Sony Ericsson X10, so I will select Android application to write a game application.
The description said that the main character is a pig. Then, Natty, my teammate, will plot the game story that the pig will rule the world by destroying the other races for making the pig planet. So, I have an idea that we can use touch as a gun shot - -" and uses the pictures which can flip between front and back as targets.

Game Screenshots

Finally, I have a sound problem in Android that I can't use SoundPool class to manage multiple sound resources in X10[Android v1.6]. So, the game still has this bug. If someone know how to correct this problem, pls tell me :D

Credit:
Developed by Darkkung & Natty
Art by http://pixmac.com, http://zulva.com
Sfx by http://stonewashed.net


Download game apk:

Sunday, October 17, 2010

Greeting - The first post in my blog

Hi, it is the first time for me to write my own blog. The contents of this blog that I will write are about my journey that may be my life, technology, days experiences, programming, events or exhibitions, my works, and so on...

The main purpose of this blog is to write my own diary which can see it any time any place because I'm easy to forget a lot of things that I ever did -*-

p.s. If I have a time, I will write it as more as possible.