Category Archives: Technology

qmake: command not found…

QT - qmake I have started to learn QT and when I tried to compile my first practice program. I could not. qmake was missing. It was a silly oversight on my part or too late into the night. Nevertheless I am sure I am not the only one and someone might find this useful.

So you have installed QT and all the necessary libraries and every time you tried to run qmake, you  got  the “command not found” error message? Well…. it is not necessarily missing.

This exact problem happened to m and I couldn’t figure out for the life of me why it didn’t work. I was a little frustrated and decided to call it a  night when I did the simplest of things. I hit the tab key after typing qm and there it was:

qmake-qt5

You may have a different version, but it seems that the issue has been there for some time. Either use that command or create a symbolic link:

sudo ln -s `which qmake-qt5` /usr/bin/qmake

You may want to create the link somewhere in your home directory and add the location to your PATH. I have a local bin directory in ~/.local/bin/.

AWK: Sum of a Column

Imagine you have a file with multiple columns and you need to quickly get the total of a column in command line in UNIX. The easiest way is to use AWK in the command line.

Let’s take the following file:
datafile.txt

1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 11 12

To get the sum of column number 7 execute the following command:

awk '{sum+=$7} END {print sum}' datafile.txt

You will get the sum of 7, 8 and 9

24

Let’s now write a small script to calculate the sum of a column and also print a running total.

Input

2010 191 291 391 491 591 691 791 891 991
2011 144 286 391 491 591 691 791 891 991
2012 112 254 354 454 554 654 754 854 954
2013 191 291 391 491 591 691 791 891 991
2014 191 291 391 491 591 691 791 891 991
2015 178 291 391 491 591 691 791 891 991

Program

#!/bin/awk -f
# scriptname: calc_sum
# input: column number, data file
BEGIN {
    printf ("\tValue\tRunning total\n")
}
{
    sum += $colnum;
    printf ("%s:\t%.2f\t%.2f\n", $1, $colnum, sum)
}
END { 
    printf ("Total:%.2f\n", sum)
}

Command

$ calc_sum colnum=8 datafile.txt

Output

        Value   Running total
2010:   791.00  791.00
2011:   791.00  1582.00
2012:   754.00  2336.00
2013:   791.00  3127.00
2014:   791.00  3918.00
2015:   791.00  4709.00
Total:  4709.00

Of course you can run the above program from the command line, but it is neater and readable this way.

MTPuTTY: Not just a Multi-tabbed PuTTY

I was looking for multi-tabbed PuTTY or a replacement for PuTTY with multi-tabbing capability when I came across MTPuTTY. I immediately started using it and let me tell you that it is great. It is not just about opening PuTTY sessions in multiple tabs in one window, but much more:

  •  You can open unlimited number of sessions in one window so your taskbar is not cluttered
  •  You can dock and tile windows. Place windows in different location on your screen under one windows
  •  You can detach a PuTTY tab and convert it as normal PuTTY window or reattach it
  • You can automatically log in if you save your username/password
  • Native Win32 code without relying on .NET or any other libraries
  • Easily accessible list of servers on a sidebar, which can be relocated on the screen
  •  It is free of charge

I generally work remotely with Vi(m) and now I can easily place windows so that I get the IDE look and feel and not worry about splitting in vim and mucking around with resizing, etc.

You can download it from TTYPlus website.

Adding Code Formatting Tools in Notepad++

I am a big fan of beautiful code, not only in terms of quality of programming but also formatting the code nicely so that it is easy on eyes.

If you are using a full-blown IDE, they come with their own formatting facility, but if you are using a multipurpose editor such as Notepad++, then you may have to use a plugin to format your code. There are many 3rd party programs that can be used with Notepad++ that will help you format your source code without going through a lot of effort.

I use different tools for different languages. I use PerlTidy for formatting my Perl code, and AStyle for certain other languages. Here are the steps taken to add AStyle to Notepad++. Please check the AStyle website for further information on AStyle and its options.

First you need to make sure you have NppExec plugin added to your Notepad++ by going to Plugin menu.

NppExec Menu
NppExec Menu

Download AStyle. The zip archive includes all the source and an  executable. You can simple copy the executable to a suitable location (For this demo, I am copying it to H:\tools\AStyle.exe. Or you can recompile from the source.

Go to NppExec under Plugin menu and click on Execute or hit F6. You will get the Execute dialogue box.

Execute Dialogue Box
Execute Dialogue Box

Select ” from the dropdown box if it is not already selected.

Type in the following commands in the window:

npp_save
h:\tools\AStyle --style=allman "$(FULL_CURRENT_PATH)"
npp_open $(FULL_CURRENT_PATH)

The first line saves the file. If you do not save first, then it might format the last saved version of your file (Thanks arduinoparty for pointing out). The 2nd command formats the code and saves the file. The view doesn’t get refreshed, so we need to reload the file from disk, and npp_open does that in the above. Note that I am using AStyle with –style=allman flag which uses broken brackets.

Hit the save button and it will ask you for a name, just type an appropriate name and hit OK to run.

Execute AStyle
Execute AStyle

You could stop right there and every time you need to run the command, just go to Plugins -> NppExec -> Execute… But let’s go one step further.

Under Plugins, go to NppExec and click on Advanced Options.

NppExec Advanced Options
NppExec Advanced Options

Select “Run AStyle” from the Associated Script drop down menu and then hit the “Add/Modify” button. Make sure the “Place to the Macros Submenu” is ticked.

This will add a new option in Macro Menu.

 

Notepad++ Macro Menu

That is it. Hope you have found this short tutorial useful.