Archive for the ‘programming’ Category
New theme on the blog
Setup Multiple Virtual Host in Apache (Windows)
Recently I need to maintain multiple websites’ source code (PHP) at the same time at local host. Every time I need test another website, I need to modify the httpd.conf configuration file and restart the Apache server. After some researches on the internet, I manage to find a way to setup multiple virtual host.
Install Apache Httpd in Windows Vista
Just bought a Dell notebook installed with Windows Vista recently. I tried to install the Apache Httpd web server in Windows Vista but failed and keep getting “error” box every time the computer is started up.
Enhanced WordPress DB class
I frequently see WordPress blogs encounter mysql connection lost or exceeded user connections limit error when I’m browsing their websites. This problem normally happens on a WordPress blog that hosts on a shared hosting, especially those busy server where too many users sit on the same server.
Enable .htaccess and url rewriting in Apache for Windows
When I try to setup PHP and Apache in my notebook, I try to enable the .htaccess setting in apache’s httpd.conf. After I tried for a few hours (YES, a few hours) at my notebook and google-ing on the internet, finally I found the complete solution.
I record the steps here so that it can help those who want to enable .htaccess and url rewriting in Apache for Windows and also for my own reference in future.
1. Make sure you have setup apache and php correctly. Make sure that you can run php scripts without any problem.
2. Use notepad to open httpd.conf config file. Make use the line “LoadModule rewrite_module modules/mod_rewrite.so” is un-commented.
3. Under “<directory XXX></directory>” section, change the line “AllowOverride None” to “AllowOverride All“.
4. Change the line “AccessFileName .htaccess” to “AccessFileName htaccess“. This is because in Windows, we can’t have a file with filename that starts with a dot.
5. Save the changed file and restart Apache Windows Service. You can then use the file htaccess to process your url rewritting.
Renovation for my blog
I uploaded my new theme last few days and it runs without any problem (so far).
I also deleted the “Archives” page because I already added it at my sidebar.
I also deleted the “Wordpress Theme” page because I feel the old theme is quite ugly.. hehe.
I also added a “About” page.
Just now when I browse to my “About” page, I saw a Google Video Ads. This is the first time I see this type of ads and somemore it is on my own blog :)

PHP security problem
I just knew this problem a month ago when one of my friend’s website on my server being hacked and installed a background program. The background program generate huge and useless image and movie files at server.
After hours of inspection at my server, I found the background progam ran under apche’s process. The background program called “footer.gif”. Smart huh? They name the background program as a image file’s name so that people can’t find it.
Simple programming trick
How do we swap values of two integer variables?
Normally we will introduce a third variable as the temporay storage. For example in C/C++:
int a = 123456;
int b = 567890;
int temp;
temp = a;
a = b;
b = temp;
Ok the question now is: How do we swap values of two integer variables without third variable?
Here is the trick:
int a = 123456;
int b = 567890;
a ^= b;
b ^= a;
a ^= b;
Don’t believe? You can try it out yourself.
Note:
- only for integer values (eg. 8, 16, 32, 64 bits integers)
^means eXclusive OR (XOR)
Explaination:
When a value is XOR with another value, the result is actually “storing” value of two values. When one of the original value is XOR again with the result value, you will get the another value. For example:
int a = 123;
int b = 456;
int resultOfXOR;
resultOfXOR = a ^ b; // "storing" 2 values
resultOfXOR ^ a; // return value of b
resultOfXOR ^ b; // return value of a
From the above code
int a = 123456;
int b = 567890;
a ^= b; // storing a^b into a. a becomes result of XOR
b ^= a; // get value of original a by resultOfXOR^b and store into b. Now b = 123456.
a ^= b; // get value of original b by resultOfXOR^b and store into a. Now a = 567890.
// Finally b = 123456 and a = 567890
That’s the beauty of XOR.
Recent Wordpress Posts in Sidebar
I had tried out the code Recent Wordpress Post in Sidebar suggested by EngLee. Although the code did shows the recent posts correctly but some functions (eg: is_page() and is_home() are not working properly when it is after the portion of the code. My guess is the wordpress loop in the code modified value of some global variables.
I have a workaround for it. Before using the is_home() or is_page() function, I save the returned in a temporay variable, call the recent posts loop, and use the temporary variable later when neccessary.
Today when I search for wp_get_archives() in Wordpress WIki, I found that I can generate recent wordpress posts in the more easier way. Here is the code:
<li>
<h2>Recent Posts</h2>
<ul>
<?php wp_get_archives('type=postbypost&limit=10'); ?>
</ul>
</li>
Simple and tidy :)
Wordpress 2.0 upgraded successfully
Just upgraded this blog to Wordpress 2.0 few minutes ago withouth any problem. I have also developed a 3 column theme for it. It is now running on this blog.The theme still in testing phase. If everything is done, I will make it public :)
Note: Plug-in that do not work with Wordpress 2.0 so far:
- Auto-TrackBack by Category
I will try to make my Default Trackback works more reliable later when I’m free.
Blogtal.com Enhancement - Feed for Categories
Added feed for each category in www.blogtal.com
For example:
Technology:
http://www.blogtal.com/categories/technology
Feed for Technology
http://www.blogtal.com/categories/technology/feed
For a better performance purpose, all feed entries (up to 20 latest pings) are loaded from cache. Therefore there is no database query when the feed is loaded. Later, I might need to increase the size of cache to cater more pings for categories.
Blogtal.com Enhancement
Two main enhancment has be done to blogtal.com. The first one is to enhance the site’s performance and the second one is the site’s add-on feature - RSS feed.
Bugs Fixed
An bugs has been found on blogtal.com’s trackback. The problem is due to yesterday’s update - Optimized SQL and Table Index on duplicated pings. This causes some pings were missing. The bug has been fixed and you can now start pinging to Blogtal.com.
TurboDbAdmin
Found this PHP scripts at K3NT’s post: TurboDbAmin. Good finding Leo!
http://www.turboajax.com/turbodbadmin.html











