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, November 23, 2012

Convert string to byte array and byte array to string (C#)

To convert from string into byte array, we can use Encoding class to convert into specific format such as ASCII or UTF8.

Example: 
using System.Text;
...
string str = "Hello, World!!!";
byte[] byteData = Encoding.UTF8.GetBytes(str);
On the opposite way, to convert back from byte array into string, we can simply use StreamReader to read it from MemoryStream.

Example:
string output = string.Empty;
byte[] byteData = ...;
using (var memoryStream = new MemoryStream(byteData))
{
     using (var streamReader = new StreamReader(memoryStream))
     {
          output = streamReader.readToEnd();
     }
}

What is MemoryStream, and its purpose (C#)

MemoryStream represents a pure data in memory as a stream of data. It is useful to use with other types such as BinaryReader to improve performance. It can be constructed from array of bytes. To use MemoryStream, it will store in a memory which is faster than disk or network accesses, and use it as temporary data on memory.

Wednesday, November 14, 2012

Using the aria-labelledby attribute

The aria-labelledby attribute can be used for indicating label for an object which can be a list of id (separated by space). It is useful  for rich internet applications to describe objects. There are 2 sources, and 1 example websites that may helpful.

Monday, November 5, 2012

Crawl HTTP 403 Forbidden Error page (may solve)

Sometime, to crawl specific page, the web servers may block you crawl their contents using a simple method by looking at UserAgent header request from a client request. In well-known web clients like IE, FireFox, Chrome, Opera, those clients are trusted by anyone, so servers will allows them to access the contents. Specific programs, however, won't be allowed to do that just because they don't have signature for it. To solve this program, you can add UserAgent header into that program using signature from well-known web clients. In case that servers block for specific clients to prevent some bots that don't have UserAgent header,  This way is the easiest solution.

The following code is an example of adding UserAgent header in C#:
HttpWebRequest request = (HttpWebRequest)WebRequest.CreateDefault(uri);
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5";
And this is an example code for Python:
import urllib2
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
ob = opener.open('http://www.google.com/')
print ob.read()

Wednesday, October 17, 2012

Learn to code with Codeacademy

In the past to learn programming languages, we need to study from books, teachers, static website. However, today, we have a interactive website that can teach us online interactively to make us visualize how programming languages work. It's a lot easier than the past. Visit Codeacademy to start practice yourself :D

Saturday, September 29, 2012

Getting Start Windows Azure

Today, Cloud services are heavily used in many companies, which can reduce the expenses in term of hardware maintenance includes scalability problem. For the well known cloud service providers may be Amazon, Google, and Microsoft. In this post I've got Windows Azure information i.e. first step of setting up Windows Azure, and its architecture.


Another one is a link exploring cloud architecture: http://msdn.microsoft.com/en-us/magazine/hh852589.aspx.



In short, Windows Azure provides 3 types of cloud services as follows: IaaS, PaaS, SaaS while Amazon provide cloud service in the level of IaaS, and provide PaaS in Google.

Thursday, September 27, 2012

HTML5 Gaming with CreateJS

Nowadays, the JavaScript technology has moved very fast, which is now we can use it to create some games. CreateJS is a library set that consists of EaseJS, TweenJS, SoundJS, PreloadJS to do element controls, animation, sound, and resources management. It is under MIT license, so it is free to use.

The following link is a example to create a simple game using CreateJS: http://blogs.msdn.com/b/davrous/archive/2012/03/16/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx.

Download CreateJS and try it here.


Thursday, September 20, 2012

Disrupt University 1st round - 4 days workshop (TH)

The following links are about the first round of Disrupt University: Bringing Silicon Valley to Thailand brief story (in Thai contents). Personally, I had a chance to attend 2nd round of this workshop, however, due to some reasons I can't join to the course and rejected the acceptation.
  1. http://ojazzy.tumblr.com/post/27252524215/disrupt-university-1
  2. http://ojazzy.tumblr.com/post/27836116803/disrupt-university-2
  3. http://ojazzy.tumblr.com/post/28342886884/disrupt-university-3
  4. http://ojazzy.tumblr.com/post/28986929903/disrupt-university-day-4
For who don't know what Disrupt University is you can visit: http://disruptuniversity.com/.