Pages

Monday, June 17, 2013

code complexity tool pmccabe

whenever we write code, it is advisable to test the complexity of the code we are writing.  This will help in source code maintainability, readability etc.

The best algorithm to do the same is cyclomatic complexity. (http://en.wikipedia.org/wiki/Cyclomatic_complexity)

One of the utility implementing this algorithm is pmccabe.

This ain't any IDE also! A simple CLI utility.


install:
sudo apt-get install pmccabe

usage:
<username>@<hostname>:~~$ find ./ -name *.c | xargs pmccabe  | sort -nr | head -10
49    49    116    361    134   <file>(362):<function>

The first column indicates the complexity score of each of the functions mentioned.
The wiki suggests that the complexity score should be kept below 10, and in inevitable cases, it can go upto 15. 

vlc player, enable en queue(add to playlist) on right click

By default, on double clicking on a song in folder, the song is opened in new vlc player session. There is no "add to playlist" option. To change this settings,


  1. On the vlc player, go to tools->preferences
  2. click on 'interface' (default) on the left menu,  on the  right, click on 'instances'
  3. check both 'allow only one instance' and 'enqueue when in one instance mode'

Tuesday, June 11, 2013

blogger can't import wordpress posts!

I was on wordpress before. Thought of moving to blogger, as wordpress want me to pay for each and everything more than what they consider 'basic'.


  1. I went my wordpress dashboard->settings->export
  2. exported an xml file (selected all as an option, to include posts, tags comments etc)
  3. Then I created a blogger, went to settings->other->import blog
  4. my xml files was just in Kbs, nevertheless, the blogger went on taking hours to import
  5. What I noticed is that it was stuck on first post itself to import. Then I learnt that to import from wordpress to blogger, a conversion is needed.
  6. So, go to wordpress to blogger convertor and get your xml file converted.
  7. Try repeating step #3. 
  8. It should work!

linux: search grep all man pages

If you would like to perform some operation on linux, and is not aware of utility that need to be run, you can search all available commands man pages to search.

There is a fine utility to do so, called apropos.

For example, I want to know all commands that operate on pdf files, like conversion from pdf to something else and vice versa, I will run
uid@host:~/apropos pdf
acroread (1)         - Adobe PDF Viewer for viewing PDF files on X Window System.
dvipdf (1)           - Convert TeX DVI file to PDF using ghostscript and dvips
evince-thumbnailer (1) - create png thumbnails from PostScript and PDF documents
fix-qdf (1)          - repair PDF files in QDF form after editing
foomatic-ppdfile (1) - Generate a PPD file for a given printer/driver combo
ghostscript (1)      - Ghostscript (PostScript and PDF language interpreter and previewer)
gs (1)               - Ghostscript (PostScript and PDF language interpreter and previewer)
gsnd (1)             - Run ghostscript (PostScript and PDF engine) without display
pdf2dsc (1)          - generate a PostScript page list of a PDF document
pdf2ps (1)           - Ghostscript PDF to PostScript translator
pdffonts (1)         - Portable Document Format (PDF) font analyzer (version 3.00)
pdfimages (1)        - Portable Document Format (PDF) image extractor (version 3.00)
pdfinfo (1)          - Portable Document Format (PDF) document information extractor (version 3.00)
pdfopt (1)           - Ghostscript PDF Optimizer
pdfseparate (1)      - Portable Document Format (PDF) page extractor
pdftocairo (1)       - Portable Document Format (PDF) to PNG/JPEG/PDF/PS/EPS/SVG using cairo
pdftohtml (1)        - program to convert PDF files into HTML, XML and PNG images
pdftoppm (1)         - Portable Document Format (PDF) to Portable Pixmap (PPM) converter (version 3.00)
pdftops (1)          - Portable Document Format (PDF) to PostScript converter (version 3.00)
pdftotext (1)        - Portable Document Format (PDF) to text converter (version 3.00)
pdfunite (1)         - Portable Document Format (PDF) page merger
ps2ascii (1)         - Ghostscript translator from PostScript or PDF to ASCII
ps2pdf (1)           - Convert PostScript to PDF using ghostscript
ps2pdf12 (1)         - Convert PostScript to PDF 1.2 (Acrobat 3-and-later compatible) using ghostscript
ps2pdf13 (1)         - Convert PostScript to PDF 1.3 (Acrobat 4-and-later compatible) using ghostscript
ps2pdf14 (1)         - Convert PostScript to PDF 1.4 (Acrobat 5-and-later compatible) using ghostscript
ps2pdfwr (1)         - Convert PostScript to PDF without specifying CompatibilityLevel, using ghostscript
qpdf (1)             - PDF transformation software

run "man apropos" for extra features with it.

Sunday, June 9, 2013

ssh login without password

Generate ssh key for your host pc

=> $ssh-keygen<enter>

Copy the key generated to remote pc to where you wish to login via ssh.

=>ssh-copy-id -i ~/.ssh/id_rsa.pub <userid>@<remote ip>

that's it! you should be able to login without prompting for password.

virtualbox arch linux access via ssh

to access virtualbox guest via ssh from your host,

  1. on host do modprobe on following modules - vboxdrv, vboxnetadp, vboxnetflt
  2. If any of the modules not found, you should have installed linux-headers and virtualbox-host-dkms before on your host.
  3. keep your guest shutdown
  4. open virtualbox GUI
  5. go to file->preferences->network
  6. add a host-only network , this will add interface called vboxnet0 on your host.
  7. once added vboxnet0, on the same window, click edit , which will show you default ip settings (start ip, netmask, gateway etc)that you can make use of , to set ip manually/dynamically. If you plan to ssh to guest later, you probably want to disable dhcp server, as the ip keeps changing if dhcp is enabled. on the 2nd tab in the edit window, uncheck dhcp server.
  8. Now, go to individual guest settings on virtualbox gui
  9. go to network option
  10. You should already be seeing a NAT adapter being added. Add adapter2 as host-only network adapter.
  11. chose vboxnet0 as the interface.
  12. click ok and exit.
  13. start your guest.
  14. when you do ifconfig -a, you will observe that one more network interface is added to the existing list. if you did not find., perform step #1 and #2 on guest also.(reboot if necessary).
  15. you can assign a static ip like on any other linux host, for example, "ifconfig eth1 192.168.56.99 netmask 255.255.255.0 up".
  16. To make it work across reboot, you may need prepare a file called /etc/network/interfaces. google for format of the file.
  17. If you are using arch-linux, you will have to add file called /etc/systemd/system/network.service. Look for the format of this file in wiki.archlinux/networking
  18. usually the commands used are /usr/bin/ip addr .. etc. I installed net-tools and and added ifconfig command as in #15. Keep in mind that you wil lhave to provide full binary path for ifconfig.
  19. once added, you need to enable it. perform "systemctl enable network".  This will enable the service across reboot.
  20. if this fails, perform "systemctl status network.service" to check what's going wrong.

 

On a technical explanation side, virtualbox provides 3 types of networking facilities to guests.

  1. NAT(default). With this, any network packets from the guest is treated as a packet pumped from any process(virtualbox here) by host. Advantage is you don't need any tweaking to get this work, by default you will get IPs in the range 10.x.x.x... You will be able to access any network that your host is able to acess. Disadvantage is that the guest itself as a physical machine, is not accessible to external world(even to the host).
  2. host-only adapter: here, you will need to create an interface on host(vboxnet0). Need to load a driver vboxnetflt, that will acts as netowork filter to seprate out guest interface from host interface. virtualbox will internally create a router between guest and host, which makes host to see guest as a different machine all toghether(you can ssh to guest from host). advantage as well as disadvantage is that, guest will be visible only to host and other VMs but not to the external world as the IP is obtained form dhcp server of the host.
  3. bridged adapter: this will expose the guest as a remote PC to the external world also. Ip is obtained from the same dhcp server from which host is getting it.
  4. internal network: Only to connect VMs on the same host.
  5. bridged ad

Monday, June 3, 2013

Shell script: IF file/string operators

Shell script: IF file/string operators

bash Shell script: IF statement file/string operators

Shell script : IF file/string operators

Shell script : IF file/string operators

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

Shell script: IF file/string operators

comment multiple lines in vim


  1. keep the cursor on the first letter of first line to comment

  2. in command mode, press ctrl + v

  3. move cursor down until last line to comment

  4. press I (you may not see vim going to insert mode, don't worry, you will see cursor moving to first line)

  5. press # (you may not see # inserted yet, don't worry)

  6. press Escape ( you should see lines commented out, otherwise, press escape two times)