Skip to main content

Posts

Showing posts from 2014

Rich - poor divide in Vietnam

There is a major rich-poor divide in Vietnam these days: people in high-income areas continue to have a much better chance of living longer than those in low-income area. For example, a boy born in 2012 in a high-income area can expected to live to the age of around 76, which is 16 years longer than a boy born in a low-income area. For girls, the gap is wider - 19 years separates life expectancy in high-income (82 years) and low-income areas (63 years). So there is a corresponding uptick in life expectancy if the income is higher.

Recomender system

In next e-commerce project at Softfoundry, I would like to implement the recommendation system which recommend the suitable products for customers. In my thesis of the university, I also experienced with the recommendation algorithm and tried to implement some of them. It must be a fascinating topic to talk about.

Command Prompt VS 2010: Fix MSVCRT.lib(MSVCR100.dll) : error LNK2005: xxx already defined in LIBCMT.lib(xxx.obj)

One of my task is to use Command Prompt of Visual Studio 2010 to evaluate the assignments of students. This assignment is about pointer and memory management in C++. The students are required to use new and delete operator in C++ to manage the memory and they need to ensure that the number of new callings must be equal to the number of delete callings. I overload the new and delete operator, build it into a static library (.lib file) and require student to use this .lib file when implementing the assignment. There is no problem when building the .lib file in VS 2010 project, but there are errors when compile the source code if I link the source code to the above static .lib file. Here is the format of error: MSVCRT.lib(MSVCR100.dll) : error LNK2005: xxx already defined in LIBCMT.lib(xxx.obj) Fortunately, I found 2 ways to fix this error on the internet. The first one is to remove the default lib when compiling the source code, it's libcmt.lib, because this libcmt.lib alread

HTTP_REFERER

A friend of mine ask me if a server can know where we come from before we go to that server (referal link). YES. This information is the field "HTTP_REFERRER" in $_SERVER of the coming request. Here is an example: http://113.161.96.198/referal/ For the reason of SEO, some guys do not want any server know about this referal link that points to their own server. Here are some solutions: HTML5: Add norefer attribute   No REFERRER PHP redirect: <?php header( 'Location: http://113.161.96.198/referal/ ' ) ; ?> .... lot of solutions lol

Create openvpn certificate remotely

VPN (Virtual Private Network) is using in my management system. As a requirement, the administrator can create the certificate (crt file) for VPN client remotely, the information as well as the files of these certificates should be stored in database so that the admin can download them from web UI. I installed the open source OpenVPN, this tool is simple but robust enough to provide the access from the server VPN to client VPN. However, the disadvantage is that you can only use terminal to generate the crt file :(. Here are some solutions but I suppose none of them is acceptable. The first solution is to using ssh to remote access the VPN server then manually create the crt files. Also, create a service to scan the keys folder of VPN to update these files into database. This solution is the easiest way to do but there is no provision of user friendly. The second solution is to write an bash script file which contains all the manual command to yield the certificate. However, how to

Calculate the execution time of multi-thread program

Indeed, multiple-thread program helps improve the performance of the application. One of the best ways to test if the performance is really improved is the execution time. In Java,  System.currentTimeMillis();  is usually used to calculate the execution time of a code block. long startTime = System.currentTimeMillis(); <code block here> long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; But if the code block contains multiple threads inside then this calculation is not true. Usually, the elapsedTime will be calculated before the longest thread completed, as a result, the elapsedTime will be incorrectly calculated. To cope with this problem, CountDownLatch is a simple tool to be used. The general idea is that this object will set a countdown number, called stopWatch , equal to the number of threads. In run() function of each thread, stopLatch is coutdowned. Outside of the code block, stopWatch calls await function, which mean that the m