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...

Friday, March 25, 2011

How to create table of contents in Blogger

Check out this link http://www.mybloggertricks.com/2010/12/how-to-create-table-of-contents-for.html

REST vs SOAP Web Services

Check out this link REST vs SOAP Web Services.
For Web Service Architecture is at W3C.

How to use JSON in python

JSON stands for JavaScript Object Notation. It is a light-weight text format that usually used it for data interchange (alternative choice to XML based). We can use it in  RESTful services.
to
Now, it just a example how encrypt and decrypt JSON in Python. The most important in JSON is the property key must be string only.

The followings are available data type in JSON:

# Python can use json from standard library
import json
# Create object in python
ob = {'name':'Json','email':['x@a.com','x@b.com']}
# Convert python object into json string format
jstring = json.dumps(ob)
print jstring
# Load python object from json string
jobject = json.loads(jstring)
print jobject

Wednesday, March 23, 2011

How to move file in Python shell

In the previous post, I introduced about change current directory in Python shell. Now, it's about move file in the shell by using "shutil.move(src, dst)" (shell util).
For example:
# Move text.txt from src to dst
shutil.move('/src/text.txt','/dst')
More detail at: http://docs.python.org/library/shutil.html

Tuesday, March 22, 2011

How to read line from an input file without \n

In python, when you read each line from a file, the line string will contain \n at the end of line (1 character).
So, you have to remove it manually unlike Java you can read line in Scanner class.
f = open(...)               # Open file

f.readline().rstrip('\n')   # Remove last character
or
f.readline()[:-1]           # Remove last character

Monday, March 21, 2011

How to change current directory in Python shell

Basically, you can't use os.system('cd ...') directly. But you can use os.chdir('path') instead.
For example:
os.chdir('..')    # Move up
os.chdir('./')    # Current dir
os.chdir('path')  # Go to folder name 'path'
More detail at: http://docs.python.org/library/os.html

Problem Solving using creative thinking

There are 3 general steps:
1. Target the goal: you must have the concrete and attainable target in order to asking questions that straight to the point.
2. Find the ways to solve the problem: think, think, and think. Don't think about possibility and reality yet.
3. Analysis and select good ideas: adjust ideas, re-think, possibility, logicality, or blend ideas together.
But ideas are not creative if not better, can't solve a problem, and not attainable.
Ref: Creative Thinking - Dr.Kriengsak Chareonwongsak
Web: http://www.kriengsak.com/

Sunday, March 20, 2011

How to show hidden files in Mac

It's very easy by do as following:
1. Open "Terminal"
2. type "defaults write com.apple.finder AppleShowAllFies TRUE"
3. Then type "killall Finder" to restart Finder

Note: If you want to change back to hidden files, just change TRUE into FALSE

Wednesday, March 16, 2011

How to calculate precision and recall

Basically, we can calculate precision and recall easily. For example, we have total 1000 cases. We know that there are 100 cases which are positive. Then, you want system to predict the positive. For example, you get 200 positive cases in testing and then you record the ids of our predictions. After that, sum up how many times to get right and wrong. There are 4 ways to determine right of wrong:

1. True Negative (TN): case negative and system can predict as negative.
2. False Negative (FN): case positive but system predicted as negative.
3. False Positive (FP): case negative but system predicted as positive.
4. True Positive (TP): case positive and system can predict as positive.

Then, we found that got 80 true positives of 200 cases. Total cases (N) = 1000
TP = 80
FN = 20 -> (100-80)
FP = 120 -> (200-80)
TN = 780 -> ((1000-100)-(200-80)) -> (900-120)
Note that: TP + FN + FP + TN = N,
TP + FN = Number of positive labels,
TN + FP = Number of negative labels

Finally, we can do calculation.
Accuracy = (TP + TN) / N = (80 + 780) / 1000 = 0.86 => 86%
Recall = TP / (TP + FN) = 80 / (80 + 20) = 0.8 => 80%
Precision = TP / (TP + FP) = 80 / (80 + 120) = 0.4 => 40%