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

Saturday, May 28, 2011

Fetch Web Pages in Python using urllib2

urllib2 is an extensible library for opening URLs. Mostly, we will use fetch data from URLs via HTTP. We can use it to access normal Website, HTTP Authentication, Web Proxy, and etc. urllib2 is included in python standard library.

Example:

import urllib2
# Normal usage
f = urllib2.urlopen('http://wwww.google.com')
print f.read()

# Use under Proxy
auth_handler = urllib2.ProxyBasicAuthHandler(urllib2.HTTPPasswordMgrWithDefaultRealm())
auth_handler.add_password(realm=None,uri='proxy-name',user='username',passwd='password')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
f = urllib2.urlopen('http://wwww.bing.com')
print f.read()

In the example, It use GET to fetch data. If you want to change it to POST, you have to put data attribute in the method.

The basic usage is "urllib2.urlopen(url[, data][, timeout])".

More details at: http://docs.python.org/library/urllib2.html

Sunday, May 22, 2011

So You Think You Can Dance Online

So You Think You Can Dance is an American Dance reality show. It is broadcast on the Fox Channel. It's marvelous. I began to watch it since March via AXN Channel during vacation. Each competitor has a high standard in dancing, so it make me feel excited when I'm watching it.

Watch at: http://www.sidereel.com/So_You_Think_You_Can_Dance

Or you may download it directly using KeepVid, or Keep-Tube without any limitation from MegaUploadVideo. Enjoy watching ><!

Wednesday, May 18, 2011

The differences between get and post method in HTTP

Sometimes, I confuse which method should be used in HTTP. Now, I have found the answer from http://wiki.answers.com.

The answer is here:
GET Method:
  1. All the name value pairs are submitted as a query string in URL.
  2. It's not secured as it is visible in plain text format in the Lacation bar of the web browser.
  3. As the data transfers through address bar (URL) there are some restrictions in using space, some characters like ampersand (&) etc in the GET method of posting data. We have to take special care for encoding data if such special characters are present.
  4. Length of the string is restricted.
  5. If method is not mentioned in the Form tag, this is the default method used.
  6. If get method is used and if the page is refreshed it would not prompt before the request is submitted again.
  7. One can store the name value pairs as bookmark and directly be used while sharing with others - example search results.
  8. Data is always submitted in the form of text
  9. If the response of the page is always same for the posted query then use GET example database searches
POST Method:
  1. All the name value pairs are submitted in the Message Body of the request.
  2. Length of the string (amount of data submitted) is not restricted.
  3. Post Method is secured because Name-Value pairs cannot be seen in location bar of the web browser.
  4. If post method is used and if the page is refreshed it would prompt before the request is resubmitted.
  5. If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
  6. Data is submitted in the form as specified in enctype attribute of form tag and thus files can be used in FileUpload input box.

Read more: http://wiki.answers.com/Q/What_is_the_difference_between_get_and_post_method_in_HTTP

Thursday, May 5, 2011

As follow VS As following

http://www.andrewbiggs.com/smf/index.php?topic=76.0
These two words usually make me feel confused how to use them all the time - -*.

Free ASP.NET MVC “NerdDinner” Tutorial

 Here, you will know a lot of basic things for ASP.NET MVC framework as following topics:

Interesting Silverlight blog posts

7 Simple Steps to Connect SQL Server using WCF from SilverLight
WCF Basics - Data Contracts
Silverlight: How to Send Message to Desktop Application
Silverlight: How to Receive Messages from Desktop Application
RIATasks: A Simple Silverlight CRUD Example (using View Model)
A Sample Silverlight 4 Application Using MEF, MVVM, and WCF RIA Services
Silverlight Elevated Permissions
Full-Screen Support

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