Pages

Java Compile and Run in Notepad++

Notepad++ is an excellent text editor. It supports syntax highlighting of many programming languages besides Java. Unlike Eclipse and Netbeans, it is light-weight and it can be launched from Windows Explorer easily by right-clicking on the file you wish to edit.

The following steps describe how you can extend the capabilities of Notepad++ to include compiling and executing Java programs from Notepad++ itself.

First, create a file called JavaCompileRun.bat. You can do this by right-clicking on your Windows' Desktop and then click New and Text Document. Then, key in "JavaCompileRun.bat" as the new file name. Right-click on this file and click Edit. Put in the following codes and save the file.
cd /d "%1"
javac %2
if errorlevel 1 goto finish
java %3
:finish
pause
Next, copy the file JavaCompileRun.bat to your Notepad++ program folder, usually at C:\Program Files\Notepad++.

Open Notepad++. Select the Run menu and click on Run.... A dialog box will appears. Key in the following command.
$(NPP_DIRECTORY)\JavaCompileRun.bat "$(CURRENT_DIRECTORY)" "$(FILE_NAME)" "$(NAME_PART)"
After keying in the above command, the dialog box should look something like this...


Click on the Save... button. In the Name: text box, key in "Java Compile and Save" as shown in the figure below.



Click OK and then click on the Run! button. Your Java program should compile and run if there is no error.

Now to compile the current Java program, make sure you have saved the file. Then, in the Run menu, click Java Compile and Run as shown.


A Command Prompt window will appear and the results of your Java program will be displayed.


There is however one serious limitation with this method. Only Java programs with default package will compile and run.

App_Code Folder in ASP .NET 3.5

In Visual Studio Professional 2008, you can still create the App_Code folder by right-clicking on the Web Project and selecting Add, then Add Folder. Rename the new folder to App_Code.

Contrary to some recommendations on the Web that you should not use the App_Code folder because you cannot place common Web UI codes or classes in this folder, you can do so by setting Build Action of each class to Compile. Suppose this step is not done, the classes defined in this folder will not be visible to your other codes. This explains why people recommended against the use of App_Code folder in VS 2008.

Suppose you have a class called WebCommon.cs in this folder. All you have to do is to right-click on this file and select Properties. A properties window will appear. Set Build Action to Compile. Viola! The class can be accessed exactly like what you have seen in VS 2005.

Using IronPython in ASP .NET VS 2008

Download Microsoft ASP.NET Futures (July 2007) from Microsoft and follow the instructions for installation closely in the download page especially you are installing it on Windows Vista.

The installation should work for Visual Studio 2005, Visual Web Developer 2005 Express Edition, Visual Studio 2008 or Visual Web Developer 2008 Express Edition. Start up Visual Studio, create a new website. You should see IronPython in the Language drop down box.

Storing Passwords in MS SQL

In MySQL, storing users' passwords is easily done by the function SHA1. Assuming a table usertable exists with two columns userid and passwrd.
INSERT INTO usertable(userid, passwrd) 
VALUES('johnlim', SHA1('SECRET'));

To retrieve the user's record,
SELECT * FROM usertable
 WHERE userid = 'johnlim'
   AND passwrd = SHA1('SECRET');

Is there an equivalent in MS SQL Server? Yes! Recently, MS SQL Server 2005 has nicely built-in support for hashing and the function is called HASHBYTES. This function takes in two string parameters. The first determines the algorithm used to provide the hash. Possible values for the algorithm are MD2, MD4, MD5, SHA and SHA1. The second takes in the value to be hashed.

Hence the equivalent SQL statements for MS SQL are
INSERT INTO usertable(userid, passwrd) 
VALUES('johnlim', HASHBYTES('SHA1', 'SECRET'));

SELECT * FROM usertable
 WHERE userid = 'johnlim'
   AND passwrd = HASHBYTES('SHA1', 'SECRET');

The only difference is that the passwrd column in MySQL is VARCHAR while in MS SQL is VARBINARY.

Changing Template in Blogger

I had been a casual blogger until of late when I am seriously exploring how Blogger works. One of the things which I sought to do was to change the template to something more professional. I have tried many templates without success. The cryptic errors reported by Blogger on various occasions were bX-si9ejx, bX-aoj9qb, bX-hq2u5m and etc.

Many other bloggers also experienced these problems and the solution commonly suggested was to delete all browser cookies and temporary files, and then upload the template again. This solution didn't work for me. I also tried changing browsers from FireFox to IE to Chrome and even Opera.

After many hours of research and experimentation, I've finally understood the problem. I came to the understanding that the template not only defines the skin and the layout of the blog, it also stores information about the widgets which I've created. The definition for each created widget is stored in this template. And along with this definition, Blogger also automatically assigns an id with each created widget. By the way, for the uninitiated, widgets are page elements which make up a blog. These are your blog archives, labels, feeds, links and etc. Basically, they are different sections of your blog.

For each template downloaded from popular sites such as Our BLOGGER Template, the template also consists of pre-defined widgets . As mentioned above, each widget is defined by its id. Most of the time unfortunately, the ids of these widgets clash with your existing widgets. In another words, they have the same name. This is where the problem lies!

To overcome this problem, before you upload the template, you should resolve these name conflicts. Common names of widgets are blog1, feed1, label1, etc. You probably need to rename all these other names, (such as blog111, feed111 and label111 etc) in order to avoid the problem altogether.

Take for example the Professional Template downloaded from http://www.ourblogtemplates.com/2008/11/blogger-template-professional-template.html.
These are the lines in the template which should be changed. You can open this file using WordPad and search for "widget id". You need not rename every instance. Only those instances that have name conflicts with your existing widgets need to be renamed. But for simplicity, just rename every widget id.
<b:widget id='Header1' locked='true' title='The Professional Template (Header)' type='Header'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'>
<b:widget id='Profile1' locked='false' title='About Me' type='Profile'>
<b:widget id='Label2' locked='false' title='Labels' type='Label'>
<b:widget id='Image1' locked='false' title='' type='Image'>
<b:widget id='Text2' locked='false' title='About This Blog' type='Text'>
<b:widget id='Text3' locked='false' title='Lorem Ipsum' type='Text'>
<b:widget id='Text4' locked='false' title='Lorem Ipsum' type='Text'>
<b:widget id='Text5' locked='false' title='Lorem' type='Text'>
<b:widget id='LinkList1' locked='true' title='Linkbar' type='LinkList'>
<b:widget id='LinkList2' locked='false' title='Links' type='LinkList'>
<b:widget id='BlogArchive1' locked='false' title='Blog Archive' type='BlogArchive'>
<b:widget id='Feed1' locked='false' title='Our Blogger Templates' type='Feed'>
The following lines show the renamed ids. E.g. Header1 → Header111.
<b:widget id='Header111' locked='true' title='The Professional Template (Header)' type='Header'>
<b:widget id='Blog111' locked='true' title='Blog Posts' type='Blog'>
<b:widget id='Profile111' locked='false' title='About Me' type='Profile'>
<b:widget id='Label222' locked='false' title='Labels' type='Label'>
<b:widget id='Image111' locked='false' title='' type='Image'>
<b:widget id='Text222' locked='false' title='About This Blog' type='Text'>
<b:widget id='Text333' locked='false' title='Lorem Ipsum' type='Text'>
<b:widget id='Text444' locked='false' title='Lorem Ipsum' type='Text'>
<b:widget id='Text555' locked='false' title='Lorem' type='Text'>
<b:widget id='LinkList111' locked='true' title='Linkbar' type='LinkList'>
<b:widget id='LinkList222' locked='false' title='Links' type='LinkList'>
<b:widget id='BlogArchive111' locked='false' title='Blog Archive' type='BlogArchive'>
<b:widget id='Feed111' locked='false' title='Our Blogger Templates' type='Feed'>
Have a productive time changing your blogger templates!