Count Lines of Code in C#

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 4th, 2007

When I am programming I often wonder how much code I have actually typed. Sometimes when I get in the zone, have a well thought out design and have auto-completion helping, I can generate code pretty quick. Although there are quite a few programs out there that will count the lines of code some are a bit more intelligent than others.

At the most basic level a simple command in DOS can count the lines of code in a file or directory. But, I often want to a little more than just the the number of lines in each file. I want to know things like the lines of code vs empty lines and the number of lines that contain comments. Fortunately, there is a plug-in for Visual Studio that will do just that. Since, I am normally using Visual Studio to write any program in C# this is a very logical place to have this tool.

C# count lines of code

My next mission will be to find a good line counter for Java. Anyone know of any?

What Is the Best Email Client?

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 1st, 2007

Determining the best email client is not a clear cut decision as there are quite a few ways one might manage their email. Although, I do think it is interesting that Thunderbird comes up first when searching Google for the phrase What Is the Best Email Client. I have to admit I agree with Google on this one Thunderbird is really good!

The thing I love most about Thunderbird is it’s IMAP support. I believe IMAP is the best way to read email since the email is kept on the server. This allows the email to be accessed from any computer (home, work, friends house, etc). With that definition it doesn’t sound like it is much different than a web based email client (SquirrelMail, GMail, Hotmail, etc) but it is!

The main feature that makes me believe that Thunderbird is better than a web based email client is the way email accounts are accessed. I can have 10 different email accounts that exist on 10 different servers and only need 1 application (Thunderbird) to access them all. Also, since the application is running on my computer it tends to run a little faster than a web site that will need to reload the page anytime I click something.

GMail does have a good user interface and page load time is pretty quick with their use of ajax.  Although, if you are using dial-up Internet you will definitely notice a difference as the first time Google loads it can take quite a while which can be seen in the screenshot below.

GMail slow startup when using dialup

GMail is probably my favorite web based email client but I really like to have more control over my email than what Google gives me. I like to know that if my email starts consuming 100 gigabytes of space that I won’t have a problem. Since I run my own mail server, I like knowing that my email is backed up and where it is backed up. So I don’t have to worry about Google one day saying sorry we lost half of your email. I also like knowing that I have control over my email and Google can’t one day decide to hold my email for ransom (not that I really believe Google would).

Google has recently started offering IMAP support (where they were only offering pop). I have been waiting for that feature for a few years and am very glad that that started supporting it. Now I can access my GMail account in Thunderbird too!

So, what about other email clients like Outlook, Outlook Express, Windows Mail. Although, I do like a lot of the features that Outlook has like managing appointments and contacts. It’s support for IMAP is pretty bad. Since IMAP is what I like using there really is no good competition.

Actually, I can think of one other email client that I have considered moving to in the past due to its speed and quick access keys. That client is Pine developed by the University of Washington. It is a text only email reading client and it supports IMAP. I love how fast I can read my email’s in Pine and I also love that I don’t have to wait for large HTML email’s to load or worry about some hidden link (phishing) or virus that could be hidden in the HTML. Unfortunately, I also like reading some email’s that come in an HTML only format. So, that one reason alone is enough for me to not use it.

That said, I would love to hear what email client you are using and why you have chosen to use it?

Extra Update Center Module - Netbeans 6 beta 2

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
October 25th, 2007

In the nightly build of netbeans there is a module that can be installed called “Extra Update Center Module”. This can be made available in Netbeans 6 beta 2 by going to Tools–>Plugins–>Settings and clicking the “add” button. Then use the following url:

http://deadlock.netbeans.org/hudson/job/javadoc-nbms/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz

Click “ok” and you should now have access to the “Extra Update Center Module”. Of course the plugins that are provided by this module could be unstable. That is why it is only included with the nightly builds.

Extra Update Center Module

touch with DOS commands

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
March 20th, 2007

I often use Cygwin to get access to a few linux style commands that I need. The command touch is one of those commands. In case your not familiar with it it will create/update the creation and modification times of a file to the current time. If the file specified does not exist it will also create an empty file.

The problem I recently encountered though was I needed the touch functionality but on a computer that did not have Cygwin installed. Of course I could have just put together a quick little C# or Java program to do the trick but I still would have to install the app onto this other computer.

The solution to this delimia was to use the following dos command which will create an empty file:
copy /y nul file.txt

Count number of lines in a file using DOS

Vote This Post DownVote This Post Up (+1 rating, 1 votes)
Loading ... Loading ...
February 25th, 2007

Every once in a while I get on a computer and I need to count the number of lines in a file. My first instinct is to open my text editor (editplus) and hit ctrl+end to get to the bottom of the document. Then I can view the status bar which will tell me the line number. This works fine when I am on my computer but not when I am on another computer that does not have editplus installed.

My next option might be to open this file in notepad and do the exact same thing. This will work fine if the file is not to large. The problem is I often deal with very large files. I need a quicker way to produce the same results.

This is where DOS comes into play. I can use the following command and let DOS quickly tell me the number of lines in the file.

findstr /R /N “^” file.txt

This command will output every line with a line number in front of it but will still take a long time given a very large file. The solution to this is to take this command one step further.

findstr /R /N “^” file.txt | find /C “:”

Now the output will only be the number of lines that are contained in the file.Again, this command could be taken a step further to tell you how many lines are in the file that contain a certain string.

findstr /R /N “^.*certainString.*$” file.txt | find /c “:”

I’m sure there are many other great uses for find and findstr. If you have found one please post comment.

Regular Expression Search and Replace via Command Line (Editplus)

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 14th, 2006

Editplus is definitely my favorite text editor but it does not entirely support Regular Expression. Below is an example of when Editplus has failed me:

Editplus-regex

So, I used the regular expression .*<table.*\n.*<tr>\n.*<td>. This unexpectedly returned everything from the beginning of the file down to the <td>. Basically it seems to have a little bit of trouble with multi-line regular expressions.

My solution to this problem was to develop a little regular expression command line program and add it as an Editplus user tool. An added benefit to creating this application is I can now do Regular Expression search and replace via the command line. At the time of creating this application I did not know about Powershell as that would have provided the same functionality. But this little application works so I will stick with it for now.

So, how does the search and replace program work? If you type SearchReplace.exe at the command line you will get the following:

Usage: searchReplace.exe “regular expression” “replacement string” file.txt

Pretty simple ehh?  Note: if you happen to have double quotes in your regular expression they will need to be escaped.

Now to set this up with Editplus just go to Tool —> Preferences —> User Tools and put in the following values:

Command: SearchReplace.exe
Argument: “$(Prompt)” “$(Prompt)” $(FileName)
Initial: $(FileDir)
Check: Run as text filter

When this user tool is run the first pop up box will be where you put the regular expression and the second will be the replacement string.

At this point I have to give a little warning that I have not thoroughly tested this program and I am not liable for any data loss caused by this program. If you happen to encounter any problems let me know. 

Determine File Encoding

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 14th, 2006

I ran into a problem where I wasn’t sure if I could trust the encoding that my text editor was displaying. I also wanted to check the encoding on about 10,000 files and determine if it was not a specific encoding. So, I created a small little program to tell me the encoding of a file. This in combination with powershell allowed me to loop recursively through all the files in a directory and create a list of the files that were not the correct encoding.

Must of the code that I used in this little application was taken from the following site:

http://www.personalmicrocosms.com/Pages/dotnettips.aspx?c=15&t=17#tip

Mute on the Command Line

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 14th, 2006

I found a nice little utility to mute computer speakers at the following site:

http://magic.aladdin.cs.cmu.edu/2005/08/01/command-line-mute/

It is now very easy for me to mute/un-mute my speakers since I have this setup with SlickRun. Basically, while working on my computer I hit ctrl+space start to type mute and hit enter. I now have toggled the sound on/off on my computer speakers. Great Little Program!

Sleep/Pause on the command line

Vote This Post DownVote This Post Up (+1 rating, 1 votes)
Loading ... Loading ...
December 14th, 2006

A quick simple way to make the command line stop executing for a certain amount of time is by put

Everyone once in a while I need a way to stop the command line from executing for a certain number of seconds. By putting the 2 below lines in to a sleep.bat file I am able to create this functionality.

@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul

In order to use this I just type “sleep 10″ which will mimic a pause for 10 seconds (really it runs a ping in the background for 10 seconds).

Intro to Windows Power Shell

Vote This Post DownVote This Post Up (No Ratings Yet)
Loading ... Loading ...
December 10th, 2006

I am just starting to familarize myself with windows Powershell. So far it sounds very powerful!

I often find myself using DOS to create quick scripts that will automate some process. Over time I have found DOS to be fairly weak when compared to a Linux shell. My solution to this problem was to download and install CYGWIN and then place the path to the files in the path. This provided me with many of the commands available to a linux shell in a DOS prompt.

From what I can tell Powershell has many of these commands available as well as a lot more functionality. It will allow you to work directly with objects. I am still a newbie at using the Powershell but I think it will be well worth the time to develop this skill.

Below are a few links to help get started using the Powershell:

Download the Powershell
Powershell Documentation
Powershell Blog
1st Chapter of Powershell in Action