Tuesday, June 30, 2015

Concatenate or Convert audio or video files

In Ubuntu Linux, install the utility ffmpeg:
sudo  apt-get  install  ffmpeg

Say you want to convert all the mp3 files in a directory to a single file called output.mp3. Then do the following. 
1. cd  to the directory
2. ls  *.mp3  >  list.txt
3. ffmpeg  -f  concat  -i list.txt  -c  copy  output.mp3

Sunday, June 28, 2015

Avoid shutdown or sleep when lid is close on Ubuntu Laptop

To avoid the Ubuntu laptop from shutting down when lid is closed, open the file '/etc/systemd/logind.conf' and add the following line at the bottom.
HandleLidSwitch=ignore
Then restart the following service:
sudo restart systemd-logind

Tuesday, June 16, 2015

Date Command with Format

Date command in Linux shows the results as below:
#date
#Tue Jun 16 16:18:50 EDT 2015

But if you want to display the date say in the format 16-06-15 then use the following format option with date command:
#date +"%d-%m-%y"
#16-06-15

Choose vi editor to open with crontab

Generally "crontab -e" opens with nano editor or gives an option to choose editor when opened for the first time. 
If you want to change the editor later on, enter the command "select-editor" and choose vi. This will force crontab to use vi.

To find your ip address

To find your local IP address type the following command:
  • ip addr | grep global | grep 'inet ' | sed -e 's/\/.*//' -e 's/.*inet //'

To find your global or internet ip address, type the following command:
  • curl -w '\n'  ident.me
or
  • curl http://icanhazip.com 

Monday, June 8, 2015

To find the time response of a website

Using the command 'curl', the time response of a website or a webpage can be found. The following is an example to find the response time for the website 'www.w3.org'

curl -s -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\nTotal time:\t%{time_total}\n' -o /dev/null www.w3.org

The response will be:
Lookup time: 0.004
Connect time: 0.062
PreXfer time: 0.062
StartXfer time: 0.123
Total time: 0.248



Thursday, June 4, 2015

Python Interpreter - Removing leading dots.

Create a .pythonrc.py file with following lines in the default home directory (~):

import sys
sys.ps1 = '>>'
sys.ps2 = ''

Add the following line in .bashrc or profile file to export variable.
export PYTHONSTARTUP="~/.pythonrc.py"


Wednesday, June 3, 2015

Use string variable or string to call a function

In python locals() return a dictionary representing the current local symbol table with all functions as dictionaries.
Say you have a function called  "Func()". The locals() will return a dictionary with "Func" as shown below:
{....., 'Func': <function Func at 0x7f9ff50a5268>, ...........}
Now you can the call the function 'Func()' by the calling the dictionary key as below:

Direct String Substitution:
     locals() ['Func'] ()

Variable Substitution:
    F = "Func"
    locals() ['F']

 You can also use globals() instead of locals() if you need global system table. 

If the function is part of a class then use getattr(class,"function")()

Monday, June 1, 2015

VIM HTML Documentation

How to Install and Launch VIM Documentation in HTML:

#1. First install the package vim-doc in your linux system.
#2. All the html files get installed at location /usr/share/doc/vim-doc/html/
#3. Open a browser and copy paste this link to get the main page. 
file:///usr/share/doc/vim-doc/html/index.html