Monday, September 29, 2008

Build HTK 3.4 from Source with Visual Studio 2008

I don't know why the HTK website itself did not provide a download for Windows binary release so we don't have to rebuild it again. However, I found that the binary for HTK 3.3 is available for download at their software archive page here (you need to be a registered user first, free of charge.)

I followed the notes posted by Ivan Uemlianin. The notes suggest me to convert the HTK source files which is in Mac format to Windows format. These source files have additional characters (CR CR CR LF) instead of Windows' (CR LF.) So you need to correct them before using Visual Studio's nmake.

Convert Mac's files to Windows'

Ivan Uemlianin himself uses a Python script to convert the files. The method I used here is not involved with programming. But you need a open-source software Notepad++ instead. Download Notepad++ here.

First, I drag all the files those need to be compile into Notepad++. Then, I turn on the "Show all characters in View -> Show all characters.




Next, the most important part, replace all the (CR CR CR LF) with (CR LF.) Fill in the "Find what :" with "\r\r\r\n" and "Replace with" with "\r\n" as shown in the picture below. Notice that the "Extended (..." checkbox at the bottom of dialog is checked. When you are ready, click "Replace all in all opened documents."

It will take a while on an old computer. Mine takes around 40 seconds :(


After the process finished, press the "Save All" button. Now you are ready to nmake the source files! You can follow the readme provided with HTK from now on :)

Sunday, September 28, 2008

Google DevFest Bangkok

The registration is open now and those who are in Thailand on October 31st might want to join the event :)

Thanks to my friend, Aruj, who informed me about this.

Register for DevFest Bangkok here

What: Google will be holding a DevFest in Bangkok. Join us for a day of coding and fun, where we'll cover topics ranging from OpenSocial & App Engine to YouTube & the Google Maps API.

Who: You! We'll provide space, power, and refreshments. You just need to bring your own laptop, ideas and enthusiasm to complete the mix.

When: Friday October 31st, 2008 1:00PM-10PM

Where: Chulalongkorn University

Saturday, September 27, 2008

Syntax Highlight/Format C#, Java, PHP Code in Blogger

The method I used to put syntax highlighted code in my blog is to use the "Code Format" tool provided by Manoli.net. It works fine but I am just lazy to convert my code every time I post a new entry.

I then try to find another solution. One option is to use SyntaxHighlighter, a Java Script library that does all the syntax highlight jobs for you.

After installation, one problem I faced is that all the "new line" I wrote in "Edit Html" of Compose Page in Blogger are converted to "
". That's not very nice : (

Like everytime, I performed a search and found a good solution here, Using SyntaxHighlighter on BLOGGER. The purpose of additional script is to convert all the "
" found in the code to "new line" chracter. It works fine and here is my sample of highlighted Java code.

(Of course, I will not use silly program like Hello World for this :D )

And here is the result:



Simple, isn't it ?

Friday, September 26, 2008

The Most Simple Introduction to Artificial Neural Networks


I would like to share you a good stuff on learning the basic of Artificial Neural Networks.

Artificial Neural Networks (ANNs), often refer to as Neural Networks, is one of the most well-known tool in Machine Learning. There are many websites available which provide basic theory of Neural Networks so I will not cover them here.

The hard part about ANNs is the Mathematics involed, how to implement them, and apply them to good use. There are many articles in CodeProject.com that try to present the ANNs in a simple, reusable ways. But, in my personal opinion, they are all hard to understand and reuse. I had read some of these articles once and I found that most of the content are too advanced. I just need to know a very basic part of ANNs and put them into good use, in short time.

I also have to admit that, sometimes, Object-oriented and Reusability are what make the code more harder to understand than it should be. I just need a "top-to-bottom" code in single method that explains what is going on. Distributing the data and logic in OO style is just not suitable for the purpose of learning algorithm.

Then, I came across this page: Implementing a Neural Network in C. This page explains very briefly everything you need to know and implementing an ANNs. And, most of all, the code is in non-object-oriented C language! That makes it is easy to learn and understand. I then followed the article with Java and everything was fine. I could adapt it to my homework problem at the university and got quite good result.

Finally, I really recommend this page to everyone who need to get started with ANNs, quick :)

Monday, September 8, 2008

Build a member system in ASP.NET 2.0 without using the Providers

ASP.NET 2.0 Provider Model

If you search for something like "authentication, authorization, member, role, user with ASP.NET," the first thing that is likely to come up is the famous ASP.NET 2.0 Provider Model.

A provider is a software module that provides a uniform interface between a service and a data source. Providers abstract physical storage media, in much the same way that device drivers abstract physical hardware devices.

To make things simple, providers are interfaces those represent ASP.NET 2.0 services: Membership, Profile, Role, Sitemap, Session State etc. The implementing classes of these providers are responsible for storing state data in storage media that maybe a SQL Server database, MySQL database, XML file or even a plain text file. We can say that the Provider Model is somekind of Strategy Pattern.



One of the providers is Membership Provider which standardized the way ASP.NET developers implement a member system in ASP.NET 2.0. By using Membership Provider, many benefits are gained. For example,

  • Every ASP.NET programmers implement the member system the same way. So it is easy to understand/work across different projects.
  • Easy to migrate to other database. Just change/reimplement the provider!
  • Can take advantage of ASP.NET's ready-out-of-the-box Login controls: Login, PasswordRecovery, CreateUserWizard, ChangePassword etc.
So, What are the problems ?

While there are so many benefits, ordinary developers suffered from Provider Model from many reasons.
  • It takes too much effort to implement a provider. Take a look at Implementing a Membership Provider. I just don't want to waste time reading this document just to build a member system on my small website.
  • The Login Controls looks inflexible to many developers. It gives the impression that they will not allow the developers to do things the way they want. Despite the fact that these controls are highly customizable ... with some efforts.
  • It has too steep learning curve. In a time-crisis situation, developers may consider implementing member system the manual way.
This makes some developers turn back from Provider Model and implement their own logics.

The member system we are going to implement is simple, utilizing only the FormsAuthentication in ASP.NET 1.x style.
  • Create new user
  • Login and Logout
  • Restrict access to pages in directory according to user's roles
Note that the readers' experience on ASP.NET and ASP.NET 2.0 are assumed :) and most of the code comes from "Role-based Security with Forms Authentication" by Heath Stewart.

Create new user

This is straight-forward. Just layout some fields and add some validators. The initial user data is then inserted into the database.

Login and Logout

We must first have the logic for authentication. For example, the person with username and password pair are queried from database.



We then need to modify the web.config file to indicate the authentication method and the location of login page. Add these lines under <system.web>



Next, for the login logic, here is my sample code.



In this case, every succeeded authentication will give the current user the role of "Customer."

Finally, add the Global.asax file to your project if none exists. You can add the Global.asax file from Add New Item Dialog. Overrides the Application_AuthenticateRequest method like this:



Restrict access to pages in directory according to user's roles

To protect a directory, add a separate web.config files containing these lines to each directory.



The allow tag specifies roles those can access the directory.

You can now also use ASP.NET's Login Controls
  • LoginView Control: To display different message to users those have been logged in and those not.
  • LoginStatus Control: To display Login/Logout link.
  • LoginName: To display username of current user. Same as using HttpContext.Current.User.Identity
Hope this post help those ASP.NET developers, especially for those with time-constraint :)