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

Wednesday, November 13, 2013

Saving and Restoring State in a Windows Store App (C#/XAML)

Walk to this link: http://blogs.msdn.com/b/robertgreen/archive/2013/01/30/saving-and-restoring-state-in-a-windows-8-xaml-app.aspx.

He already show how to drive down step by step and make me clear where to configure the code for how to save and restore state in Windows Store App.

Thursday, October 24, 2013

Web Test Recorder on Internet Explorer 11

Recently, I have got a problem about using Web Test Recorder after upgrading to Windows 8.1. It has come with the new version of internet explorer i.e. version 11. That doesn't compatible with current Web Test Recorder version (we have to wait until new release to support IE11). However, there is a workaround for this problem. Try to disable Enhanced Protected Mode, then it should work. If not, follow this link: http://blogs.msdn.com/b/visualstudioalm/archive/2013/09/16/using-internet-explorer-11-and-not-able-to-record-a-web-performance-test-successfully.aspx. It contains information to disable something new which doesn't support on Web Test Recorder.

Tuesday, August 27, 2013

Convert a color image to a greyscale image using Python Imaging Library

Recently, I have a chance to do some image processing tasks because of my lacking in term of using application like GIMP. I just want to do very easy task to convert a color image to a greyscale image because my printer cannot do color printing and set for black and white. I know it is very easy task with we can use some programs to do it instead of Image Processing program like GIMP or Photoshop. For me, I can do some Python programming then decide to write a small program to convert a color image to grey scale image within 5 minutes (from start writing a code and done processing).

In Python, we can use a lightweight library but easy and powerful to use to do Image Processing tasks that is Python Imaging Library. Before do converting task, we need to know some basis about Image Processing first.

The first thing that we should know is the color mode. In Image Processing there are many color modes which each mode is appropriate for some kind of tasks such as binary image (just black or white like a picture in Game Boy), 8-bit black and white (greyscale image), RGB (3x8-bit), etc. for more details can look at http://effbot.org/imagingbook/concepts.htm.

Okay, we have just known the image color system in Python Imaging Library. To convert a color image (usually RGB image) to greyscale image, it is not difficult because Python Imaging Library already provide the function to convert image mode. The code to convert has shown below:
from PIL import Image 
input_filename = 'input.png'
output_filename = 'output.png'
image_file = Image.open(input_filename)
# L refers to 8-bit pixels, black and white in Python Imaging Library
image_file = image_file.convert('L')
image_file.save(output_filename)
The step is load an image to the buffer then convert an image mode and save to another image file.
It's not hard but quite fun if we can play more interesting features in Python Imaging Library. With this code, we can convert an image within a sec :)

Example (Asuna from SAO):
Before
After
Reference: The Python Imaging Library Handbook

Tuesday, July 30, 2013

JavaScript control attributes for Windows Store Apps (data-win-* attributes)

Lately, I have done something mostly related to Windows Store App and I'm also interested in JavaScript. This language is very powerful in so many ways. It's easy to entry, you just have a browser and a text editor then your can start develop something. However, JavaScript is easy to start, but it is not easy to be mastered. I'm not a JavaScript professional, not even a web developer. But when compared the learning curve between JavaScript and Strong-Typed Languages (such as Java, C#). By the way, this post is not about language technologies.

JavaScript is powerful enough to make it be a one of native languages of Windows Store App. In this post would like to give introduction about added-on attributes to make html elements transformed into Windows Store controls.

The first one is "data-win-control". It is a very important attribute to create WinJS controls by giving them a control name then call process UI to apply controls on the startup. This attribute can't not be used on iframe element.
<div data-win-control="controlName" />

(function( ) {

    document.addEventListener("DOMContentLoaded", function(e) {
        WinJS.UI.processAll();
    });

})();


The next one is "data-win-options". It can receive a JavaScript object to set that control properties.
<div 
    data-win-control="control" 
    data-win-options="{ property1 : value1, property2 : value2}">
</div>


It can also do binding data as XAML does using "data-win-bind" (with some code in JavaScript side).
    <element data-win-bind="elementProperty1 : dataSourceProperty1; elementProperty2: dataSourceProperty2" />


To make elements can't be selected, use "data-win-selectable" property. It is just a true / false value. By default, all input elements and elements with the contentEditable attribute set to true are selectable.
<div data-win-selectable="true" ...


The controls can be binded with external resources for localization or other purposes using "data-win-res".
<p data-win-res="{textContent: 'String1'}"></p>


For the "data-win-fragmentLoad" property, the document said that this will be removed from the next version of Windows Library for JavaScript. So, I think we should not use it.

Reference: Windows Library for JavaScript control attributes

Wednesday, July 24, 2013

JavaScript class and namespace

The following links are the basic link provide the information how to create namspace and class in JavaScript.
The following example is to show how to create basic namespace and class. The namespace is name "NS" then create class in that namespace "Sound". Sound class has instance variable "name". and class variable "Variable". Also has the class method "Method1" and "Method2" which can be used like static method in Java or C#. After that this html page will be processed when document loaded and print out "love story 3".
<!DOCTYPE html>
<html>
 <head>
  <title>Test</title>
  <script type="text/javascript">
  var NS = NS || {};
  
  NS.Sound = function (name) {
   this.name = name;
  }
  
  NS.Sound.Variable = [];
  
  NS.Sound.Method1 = function () {
   NS.Sound.Variable.push(1);
   NS.Sound.Variable.push(2);
   NS.Sound.Variable.push(3);
  }
  
  NS.Sound.Method2 = function () {
   return NS.Sound.Variable.length;
  }
  
  function onLoad() {
   var sound = new NS.Sound("lovestory");
   var div = document.getElementById("content");
   
   NS.Sound.Method1();
   var content = sound.name + " " + NS.Sound.Method2();
   
   div.innerHTML = content;
  }
  
  document.addEventListener("DOMContentLoaded", onLoad, false);
  </script>
 </head>
 <body>
  <div id="content"></div>
 </body>
</html>

Monday, July 8, 2013

Download ISO files from IIS

Normally IIS won't allow the clients to contact unknown extensions in the server. ISO is not set by IIS default. In order to do that, we need to configure MIME Types on IIS with the following steps:
- Open IIS.
- Select the the server then select MIME Types.
- Add .iso extension as application/octet-stream.
- Ok

After that you can access ISO as octet steam which can be applied to almost any binary file.

Thursday, June 13, 2013

An example experience to manage money and reach the target (TH)

This blog here, he share his experience to manage his money and reach his target without stock trading.

Friday, May 17, 2013

How to change password policy for group and domain in Windows Server 2012

To change password policy for Windows Server, we can change by the following steps:
- Open Control Panel
- Select System and Security
- Select Administrative Tools
- Double clicks at Group Policy Management
- Under Domains tab, open Group Policy Objects
- Then will see Default Domain Policy, right click and select Edit.
- It will show Group Policy Management Editor, open the following tab Computer Configuration -> Policies -> Windows Settings -> Security Settings -> Account Policies -> Password Policy.