Thursday, November 19, 2009

Wordpress in Tomcat

First download the latest version of the following

1. Tomcat
2. Wordpress
3. Get the latest version of the Quercus, an open source Java implementation of PHP 5 from http://quercus.caucho.com/
4. MySQL Java connector http://www.mysql.com/products/connector/

Steps to install Wordpress in tomcat

1. Extract tomcat
2. Extract Wordpress to tomcat's webapps directory
3. Extract WEB-INF folder from the quercus.war file and put them in tomcat's Wordpress directory
4. Extract mysql connector jar file to wordpress/WEB-INF/lib
5. Go to WEB-INF/web.xml. Check if the following exist



6. Modified the tomcat/conf/web.xml file to the following.



7. Open wordpress/wp-includes/formatting.php. Change the js_escape() function to:



function js_escape($text) {
$safe_text = wp_specialchars($text, 'double');
//$safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
//$safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
//stripslashes($safe_text));
$safe_text = preg_replace("/\r/", "\n", addslashes($safe_text));
$safe_text = preg_replace("/\n/", "\n", addslashes($safe_text));
return apply_filters('js_escape', $safe_text, $text);
}



8. Follow http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install to install Wordpress

Sunday, November 15, 2009

MySQL - Resetting Root Password

Sometime, you may forget the root password of MySQL. Below is some extracted steps to reset the root's password in Windows

1. Stop running MySQL instance. net stop mysql
2. Save the following to a text file where MyNewPass is your desired root's new password. In this example, this file will be saved at MySQL installed home's bin folder and the file calls "reset_password.txt"



UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;



3. Go to your mysql install home and run this command




mysqld-nt.exe --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini" --init-file="C:\Program Files\MySQL\MySQL Server 5.0\bin\reset_password.txt" --console



4. If MySQL start correctly, stop the server by Ctrl-C.
5. Restart the MySQL as a window service. net start mysql
6. Test your new password by mysql -u root -p. This command will prompt you for the password.

You can reset root's password for Linux too. Details can be found in
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

Friday, November 13, 2009

C# - Convert Int to Hex String

To convert Integer to Hex String and visa versa is simple

Integer to Hex



int a = 1;
String hex = a.ToString("X");




Hex to Integer



int a = int.Parse(hex,
System.Globalization.NumberStyles.HexNumber);