Thursday 23 February 2012

Using SCLC (Source Code Line Counter)

Well, it is really very simple. Here you go:
  1. Download the file. You can get it from here.
  2. Double click it. It should open as any other normal application.
    1. If it doesn't open as expected or opens WinRAR/WinZIP/7-Zip or any other archiving software, follow here:
      1. Right click the file and point to Open With.
      2. Click on Select Default Program.
      3. Java should be here in the list of programs. If it isn't then click browse and locate your java installation. It should be in C:\Program Files\Java\jre7\bin\java.exe
        1. If you dont have any folder called Java in Program files, then go to www.java.com and download and install it first.
        2. Once Java is installed, follow step 2.
      4. Click OK. Follow step 2.
  3. Click on 'Add File' button to add files to it. A dialog box will be presented.
  4. Locate your source code files. You can select more than one file by selecting one file and then holding the 'Ctrl' key and selecting other files. Alternatively, if you wish to select all files, you can press 'Ctrl + A' to select all files in the directory you are in.
    1. Make sure that you do not select any executable files. This may cause an error.
  5. Click OK/Open.
  6. You should see list of files in the list above 'Add File' button. If you wish to add more files, follow step 3.
  7. Once you are done, click Start. It will start counting lines in the files you have selected.
  8. You're done! The table will display number of code lines in each file and below the table you'll find total line count and line density. 
I hope you like it. If you do/don't, give me feedback by commenting below. Have fun!

Count lines of code you've written!

For those of you who enjoy programming, having a curiosity about knowing number of lines of code that you've written is very common. It is easy to know that by simply scrolling down and looking at the last number. However, if your code is distributed into different classes, knowing total lines of code would be very hard. I had the same problem and hence to solve that, I created an application in Java. You simply add files whose lines you want to count and click the start button. The application will display number of lines in each file, total line count and average line density in each file. This is very simple, effective and accurate way of counting lines of code that you have written. You can download the file by clicking download below:


For usage instructions, click here.
I hope you like it. Enjoy!

Monday 13 February 2012

Conditions in Linux Shell Script

If statements are important in any programming language. I had a bit of hard time while doing if statements in linux since they are different than those in a conventional programming language. First of all, an if statement to compare whether a value in a variable val1 is equal to 5 is like:

val1=5
if [ $val1 -eq 5 ]
then
     Code here to do some stuff
else
     If above condition is false, then code here gets executed
fi
Note that spaces are important when defining condition. $val1 refers to the variable and -eq simply implies equal to operator to compare if the $val1 is equal to 5.


Seems pretty easy? It is. Other conditional operators are:


Conditional OperatorLinux Equivalent
Greater than-gt
Less than-lt
Equal to-eq
Not equal to-ne

Now, if I want to compare strings, for instance, if variable answer is equal to "yes" then the code will be as follows:


if [ "$val" = "yes" ]
then
     Code here to do some stuff
fi


Again, spaces are important here.
In here, '=' can easily be replaced by conventional conditional operators like '>' or '<' or '!=' etc.

Variables in Linux Shell Script

Well, this has been a bit tricky for me so I decided to put it on my blog so that it can be helpful to you guys.

First of all, How to define a variable?


count=0

There! I've just defined a variable count with 0 as its initial value.
Now, How do you print value of a variable?

echo "$count"

or

echo $count

Next. How do you perform calculations on a variable?
Okay. So assume that you have two variables called val1 and val2 with values 3 and 4 respectively. Now, you want val3 to have the addition of val1 and val2. So,


val1=3
val2=4
val3=`expr $val1 + $val2`

Similarly, to do subtraction:

val4=`expr $val1 - $val2`


Note that spaces are very important here.

Now, if you wish to assign value returned by a command to a variable, then it works by doing:

wcount=`wc -w myfile.txt`

anything between ` and ` will be executed as linux command and the value returned by that command will be assigned back to the variable to left.

Sunday 12 February 2012

How did I solve my problem of viewing images quickly...

I've been quite busy lately. If you are a curious PC user, then you might have noticed that the photo viewing programs that your PC comes with aren't as efficient and fast as they should be. I was extremely annoyed when the Windows Live Photo Viewer took 2 minutes to load my photo. It does have features like photo editing etc but I rarely use them. All I want is to view my pictures one by one. I don't think I should wait 2 minutes for the program to load features which I am not going to use. Hence, to solve this problem, I used, an uncommon approach. I designed my own image viewing software. I think that the best way to solve your problem is to create your own solution, rather than finding a solution.
This new software that I just created in one hour simply shows your pictures. You double-click a picture and it will open in Image Viewer. It opens in a flash and I love it. You can also open the image viewer and open a picture by clicking on Open button. Also, once you open a picture, it loads all pictures in memory and allows you to navigate through.
I will be publishing the source for this software soon so that it can be useful to you guys.

Try out the Image Viewer now!

Instructions:
  • The download is an EXE file.
  • No setup is required. Simply double click the EXE file and that will run the program.
  • If you wish to attach the program to a picture file, then right click the picture > Open With... > Select default program. Click on browse and locate the EXE file. Make sure that the checkbox below is checked and click Ok. 
Post any bugs or suggestions in comments below. Thanks!