Skip to main content

Posts

Showing posts from February, 2014

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