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, April 29, 2011

Using Fences to organize your desktop shortcuts

Recently, I had a problem with the shortcuts on the desktop. I usually connect my laptop to an external monitor, so the resolution usually changes. The problem was that my shortcuts arrangement also changed! Now, I have a solution you can use Fences to organize your shortcuts, and it can remember the shortcuts arrangement.

Download at: http://download.cnet.com/Fences/3000-2072_4-10909535.html

The Fences Example

Monday, April 25, 2011

Cut Automator script for Mac with Automator

One thing that caused a lot of problems for me in Mac is there is no "cut" short key like "ctrl+x" in Windows. I had to dragged items, sometimes it's hard to do like that. So far, I tried to develop "Cut Script" with Automator. It can be used by using right clicking to the item, then select the path to move.

You can create it as following steps:
1. Open Automator from your Application.
2. Service receives selected change to "files or folders" and in to "Finder".
3. Drag "Get Selected Finder Items" to the Automator space.
4. Drag "Set Value of Variable", and change its name to "item".
5. Drag "Apple Script".
Step 3-5
6. Drag "Ask for Finder Items", and change type(Type:) to "Folders".
7. Drag "Set Value of Variable", and change its name to "path".
8. Drag "Apple Script".

Step 6-8
9. Drag "Get Value of Variable", and change its name to "item".
10. Drag "Move Finder Items", and change to(To:) to "path".

Step 9-10
Download

In addition, you can also download it, and then place it into your profile service folder (~/Users/[User]/Library/Services/).
Now, you can move your file faster with easy steps. Don't have to drag anymore!

Saturday, April 2, 2011

How to install Python Imaging Library (PIL)

Python Imaging Library is a library for doing image processing tasks just as its name. In Windows you can install it easily by downloading PIL windows installer, but in Linux and Mac are more harder. You have to compile and install it from a source package. PIL also need other libraries in order to install it completely as followings: JPG, Freetype, LittleCMS 1.19 NOT 2.0+.

In Linux, you may install those libraries via your command line. For example, sudo apt-get install (Ubuntu). Then, install PIL.

However, in Mac, you have to install Xcode and X11 to make your Mac can use "./configure" and "make" command. After that, installing MacPorts or Fink which allow you to get those required libraries and download them via command line (use "port install" or "fink install" respectively). Finally, install PIL after installing dependent libraries.


You can download PIL from here (all platforms): from http://www.pythonware.com/products/pil/

To install PIL from source package do steps follows:
1. Change current directory of your terminal under PIL source folder.
2. Type "sudo python setup.py build_ext i".
3. Run the test "python selftest.py".
4. If everything is fine, then install it by typing  "sudo python setup.py install".

Then, you should run PIL example code to make sure installation is complete. If not or in the case that you already installed PIL, you need to delete its package from site-package in python library. Then, you have to extract PIL source package from zip file again (do not use older extracted folder because it won't work for sure). Build it again, then install.

p.s. Required libraries: libjpeg, freetype, lcms

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/