Showing posts with label Software. Show all posts
Showing posts with label Software. Show all posts

Wednesday, August 13, 2008

Gedit as an Editor for Programmers

Gedit is a lightweight and powerful text editor. It is included in Ubuntu Linux. Gedit supports plugins, so you can add some plugins to extend your editor. With plugins, Gedit is not only a simple text editor.
As a programmer's editor, it should show line numbers, enable automatic indentation, etc. Open "Edit" -> "Preferences". There are for tabs in the dialog. You'd better go to "View" tab and check "Display line numbers" and "Highlight matching bracket". Next, check "Enable automatic indentation" in the "Editor" tab.

"Plugins" tab is used for enabling and disabling Gedit's plugins. Open "Plugins" tab, then you can find the installed plugins. So please check which plugins you have installed firstly. If what you need has not been installed, please visit http://live.gnome.org/Gedit/Plugins. To install a plugin is very easy. Just extract the files to ~/.gnome2/gedit/plugins/ then restart Gedit. I think the following plugins are useful for programming:
  • Code comment: It adds "Comment code" and "Uncomment code" to the "Edit" menu. It can help you comment and uncomment code quickly.
  • Color Picker: If you enable this plugin, "Pick color..." will be added to the "Tools" menu. It opens gcolor2 to help you to choose color. If you don't have "gcolor2", you need to run "sudo apt-get install gcolor2" to install it first..
  • Embedded Terminal: It adds a terminal frame in the bottom pane. You can use "Ctrl+F9" to toggle it.
  • File Browser Pane: It adds a simple file browser into the left pane.
  • Indent Lines: After turn on this plugins, you will find "Indent" and "Unindent" options in the "Edit" menu. It can increase or decrease indentation quickly.
  • Split View 2: "Toggle Split View" will be added to the "View" menu. You can split the document frame and see more that one file at the same time.
  • Symbol Browser: It is added to left pane. When you open a source code file, it can show the classes and functions, etc. It is very useful for programming.
  • Tag List: Some common tags for HTML, XML, etc.
Gedit plugins can be written in C or Python. If you want to write your own plugins, read C plugin howto and Python plugin howto.

Sunday, August 10, 2008

Some Problems of Tomcat on Ubuntu 8.10

I found that Tomcat 5.5 package of Ubuntu Linux had some serious problems.

Normal users can't control Tomcat server. If you want to start/restart/shutdown Tomcat, you must use "sudo". For developers, restarting Tomcat is very frequent, therefore, typing "sudo" again and again becomes a dirty work.

Problems about MySQL connection. The default bootstrap of Tomcat is /etc/init.d/tomcat5.5 and it starts Tomcat server automatically. But the serious problem is: Tomcat con't connect to MySQL database! I don't know why. However, if I start Tomcat with /usr/share/tomcat5.5/bin/startup.sh, Tomcat can connect to MySQL. Why the two methods to start Tomcat are different?

Class loading problems. I wrote my first servlet that can connect MySQL with JDBC and found some strange problems. I create three files:
  • Database.java: the database class, which encapsulates some database operations;
  • DBTestServlet.java: the servlet class that calls Database class to operate database.
All files (class file, jar file, web.xml, etc) are located in proper directory. But Tomcat said it can't find the JDBC driver class (Database class has a method that calls DriverManager.getConnection() to get a database connection), although I had put mysql-connector-java-5.1.6-bin.jar in WEB-INF/lib. But if I used JDBC API in DBTestServlet class directly, no problem happened. However, the stranger is: if I started Tomcat from root account (I need to enable root accout and use "su" to switch to root, see Enable and Disable "root" on Ubuntu Linux) instead of using "sudo", no problem happened, even if I used Database class. That's very strange.

I don't know why Ubuntu's Tomcat package has so many problems. Perhaps the best solution is to download Tomcat from http://tomcat.apache.org/ and extract it to a directory instead of using "sudo apt-get install tomcat5.5".

Tuesday, August 5, 2008

Unix Searching Tool -- find

The command "find" exists on almost all Unix. It is used for searching files. "find" can help you find files with specified attributes. In many conditions, "find" can work with other programmes well. Here I will take some examples to show the power of "find".

Suppose you have a directory named "shop" which contains many PHP files, but it contains some sub-directories, so you cannot use "ls *.php" to show all the PHP files. "find" can solve the problem:
find shop -name '*.php'
"find" searches all the sub-directores recursively and find all files whose names match the pattern "*.php" and print their paths. The argument "-name" means matching the filename.

If you need to calculate how many PHP files there are in the "shop" directory, just need use "wc" command to count the number of lines that "find" produced.
find shop -name '*.php' | wc -l
It proves that Unix "pipe" is very powerful and useful.

Beside matches file name, find can accept other conditions, for example, last modified time. In my computer, Tomcat (a JSP/Servlet container with a web server) generates log files on /var/log/tomcat5.5/. If I want to show the log files which are modified more than 2 days ago, I can use "-mtime" argument:
find /var/log/tomcat5.5/ -mtime +2
"-mtime" means "last modified time" and "+2" means "more than 2 days". Furthermore, I want to delete all the Tomcat log files which is generated more than 2 days ago. I can use "xargs" to combine "find" with "rm":
find /var/log/tomcat5.5/ -mtime +2 -print | xargs rm -f
"find" also supports logical operators. For the example above, if I need find the log files whose last modified time is more than 5 days or less than 3 days, I can use "find" as below:
find /var/log/tomcat5.5/ -mtime +5 -or -mtime -3.
"find" supports three logical operators: -not, -and, -or.

Certainly, the functions of "find" are too many to talk about. All the information about "find" can be finded by "man find", although it is not easy to read.

Monday, May 26, 2008

Foxit Reader: A Better PDF Viewer

I have used Adobe Reader as my PDF viewer many years. But Adobe Reader became fatter and fatter recently. Today when I opened three PDF files with it, my computer became very busy and slow. I open the task manager of Windows. To my surprice, the Adobe Reader used over 100 MB memory space! So I wanted to look for another PDF viewer.

I found Foxit Reader just now. Many people think it's better than Adobe Reader because it's smaller and faster. I have tried it. Very fast even I open five PDF files. That's it.
Foxit_Reader

The disadvantage of Foxit Reader is the font is not as clear as Adobe Reader. I don't know why it is.

Thursday, May 22, 2008

PowerShadow: Protect Your Computer

PowerShadow is similar to recovery card. When PowerShadow is running, it seems that you are working on a 'shadow' of the operation system. All changes of files on the hard disk will disappear after rebooting the computer. So you don't afraid of virus any more. Here is a screenshot:


The current edition of PowerShadow costs $39.00. If you don't mind the older edition, you can use PowerShadow 2.6, it is free to use. Mine is PowerShadow 2.6. It can be downloaded from my box.net. Click here.

The free registration information is:
Username: PowerShadow
Serial Number: VVR29E-R4WCK2-K4T111-V1YHTP-4JYJDD

PS: PowerShadow is not anti-virus software. It can only protect your files from being changed or deleted. It can't guarantee that your private information not to be leaked out.

Friday, May 2, 2008

Running PHP In The Console

When you test a small PHP script, you need run a web server, such as Apache, then open a browser to see the result. How dirty the work is! The simple method to run a PHP file is to call PHP interpretor in the console.

For Unix/Linux, the only thing you need to do is enter such line in the console:

php -f your_php_file


For Windows, the best way to run a PHP script is to call PHP interpretor from a text editor or IDE. I like SciTE, a powerful text editor for programming. Open html.properties from options menu, then add these lines in the bottom:

PHP_Bin=D:\xampplite\php
command.go.$(file.patterns.php)=$(PHP_Bin)\php.exe -f "$(FileNameExt)"
command.compile.$(file.patterns.php)=$(PHP_Bin)\php.exe -l "$(FileNameExt)"


"PHP_Bin" specifies where the PHP interpretor is. After doing that, when you open a PHP file next time, you can run it in SciTE just select "Tools" -> "Go" or press F5. If you select "Tools" -> "Compile" or press Ctrl+F7, PHP interpretor doesn't run the script but check syntax instead.

Monday, April 28, 2008

Windows Live Mail is Good

This morning I downloaded Windows Live Mail, an Email client software. Since I received an Email from Microsoft that told me Outlook Express wouldn't support Hotmail in June a few days ago, I decided to try Windows Live Mail. Here is the interface, very beautiful:
Windows_Live_Mail

Beyond my expectations, I feel this software is very good. When I added a 163.com Email accounts, I needn't to set the POP and SMTP server even! The design of the interface is also very friendly to users, at least much better than Outlook Express.

Do you want to try it? Click here to learn more.

PS: It is my 20th birthday today. Happy Birthday to me!