Sunday, January 28, 2018

Vim Configuration

Image result for vim

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.

The NERDTree and NERDTreeTabs plugins make Vim much easier to use. My .vimrc file is listed below. Put it in ~/.vimrc.


" URL:
" Authors:
" Description: A minimal, but feature rich, example .vimrc. If you are a
"              newbie, basing your first .vimrc on this file is a good choice.
"              If you're a more advanced user, building your own .vimrc based
"              on this file is still a good idea.

" Features {{{1
" These options and commands enable some very useful features in Vim, that
" no user should have to live without.

" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible

" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on

" Enable syntax highlighting
syntax on

" Must have options {{{1
" These are highly recommended options.

" Vim with default settings does not allow easy switching between multiple files
" in the same editor window. Users can use multiple split windows or multiple
" tab pages to edit multiple files, but it is still best to enable an option to
" allow easier switching between files.
" One such option is the 'hidden' option, which allows you to re-use the same
" window and switch from an unsaved buffer without saving it first. Also allows
" you to keep an undo history for multiple files when re-using the same window
" in this way. Note that using persistent undo also lets you undo in multiple
" files even in the same window, but is less efficient and is actually designed
" for keeping undo history after closing Vim entirely. Vim will complain if you
" try to quit without saving, and swap files will keep you safe if your computer
" crashes.
set hidden

" Note that not everyone likes working this way (with the hidden option).
" Alternatives include using tabs or split windows instead of re-using the same
" window as mentioned above, and/or either of the following options:
" set confirm
" set autowriteall

" Better command-line completion
set wildmenu

" Show partial commands in the last line of the screen
set showcmd

" Highlight searches (use <C-L> to temporarily turn off highlighting; see the
" mapping of <C-L> below)
set hlsearch

" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
" script, <>.
" set nomodeline

" Usability options {{{1
" These are options that users frequently set in their .vimrc. Some of them
" change Vim's behaviour in ways which deviate from the true Vi way, but
" which are considered to add usability. Which, if any, of these options to
" use is very much a personal preference, but they are harmless.

" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase

" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start

" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent

" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline

" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler

" Always display the status line, even if only one window is displayed
set laststatus=2

" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm

" Use visual bell instead of beeping when doing something wrong
set visualbell

" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=

" Enable use of the mouse for all modes
set mouse=a

" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2

" Display line numbers on the left
set number

" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200

" Use <F11> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F11>

" Indentation options {{{1
" Indentation settings according to personal preference.

" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
set shiftwidth=2
set softtabstop=2
set expandtab

" Custom Settings

" Shortcuts to switch between multiple tabs.
map <C-t><up> :tabr<cr>
map <C-t><down> :tabl<cr>
map <C-t><left> :tabp<cr>
map <C-t><right> :tabn<cr>
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
nnoremap <silent> <A-Left> :execute 'silent! tabmove ' . (tabpagenr()-2)<CR>
nnoremap <silent> <A-Right> :execute 'silent! tabmove ' . (tabpagenr()+1)<CR>

" Uncomment this if using a Mac.
execute "set <M-A>=\e[A"
execute "set <M-B>=\e[B"
execute "set <M-b>=\eb"
execute "set <M-f>=\ef"
map <M-A><up> :tabr<cr>
map <M-B><down> :tabl<cr>
map <M-b><left> :tabp<cr>
map <M-f><right> :tabn<cr>
nnoremap <M-b> :tabprevious<CR>
nnoremap <M-f> :tabnext<CR>

" This tip is for loading project files that you know the names for, but do not remember their paths.
" Use :find filename.ext to find the file. 
" For linux systems use path=$PWD/**.
" For windows systems use set path=.\**
set path=$PWD/**.

" Wildmenu enables a menu at the bottom of the vim/gvim window.
set wildmode=list:longest,full

" NERDTree related
execute pathogen#infect()
call pathogen#helptags()

" Start NERDTree-Tabs on startup.
let g:nerdtree_tabs_open_on_console_startup=1

" NERDTree-Tabs open/close nerdtree window.
map <Leader>n <plug>NERDTreeTabsToggle<CR>

" NERDTree-Tabs switch to/from nerdtree window.
map <F1> <plug>NERDTreeFocusToggle<CR>

Bash Aliases

Image result for bash

GNU Bash is a Unix shell. It is the default terminal that comes with Apple OS X and Ubuntu.

To make it more useful, I recommend you update your .bashrc file under your profile's home directory (~/.bashrc) by adding the aliases below.

# Directory aliases.
alias ll='ls -l'
alias la='ls -la'
alias l='ls -CF'
alias c='clear'

# Project aliases.
alias dev='cd ~/dev/'
alias apps='cd ~/apps/'
alias arto='dev && cd arto_dev'
alias pdev='dev && cd python_dev'
alias jdev='dev && cd java_dev'
alias ndev='dev && cd node_dev'
alias g='gradle'

# Build aliases.
alias m='mvn clean install -U'

# Run aliases.
alias runjetty='mvn jetty:run -Djetty.http.port=8085'
alias erun='DEBUG=myapp:* npm start'
# PATH environment variable.
export PATH="$PATH:"/new/directory/""

Thursday, March 17, 2016

Git Client & Server Intranet Configuration How-To

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. There are websites like github and bitbucket that host repositories but you can also have your own local repository on your intranet quite easily and for free. Below are the instructions for setting up a Git Client and Git Server on networked Windows 7 machines.

Git Server Setup

1. Install Windows 7 32-bit or 64-bit. Set computer name to gitserver. Set IP address to
2. Create user accounts for each git user. All should have administrator privileges.
3. Log on with an administrator account.
4. Right click Windows Explorer icon and select "run as administrator".
5. Create repository directory "c:\repositories".
6. Share repositories directory. Right click "repositories" then "properties"" then "sharing" then "advanced sharing" then click "share this folder".
7. Make sure all users have permissions to use the repositories directory.
8. Download Git for Windows (aka Git Bash):
9. Install Git for Windows (use default configration options during installation).
10. Open Git Bash.
11. Navigate to the repositories directory ("cd /c/repositories"").
12. Create a bare repository ("git init foo_project --bare").

Git Client Setup

1. Install Windows 7 32-bit or 64-bit. Set IP address to
2. Download Git for Windows (aka Git Bash):
2. Install Git for Windows (use default configuration options during installation).
3. Log on with an administrator account.
4. Right click Windows Explorer icon and select "run as administrator".
5. Map network drive as G:, type in "\\gitserver\repositories". Use the same credentials as the user account you setup on the Git server.
6. Open Git Bash.
7. Navigate to where you want to store your working copy repository ("mkdir /c/dev" then "cd /c/dev").
8. Create a Git repository ("git init foo_project").
9. Create remote repository link ("git remote add origin file://localhost/g/foo_project").
10. Push your working copy of the repository to the Git server ("git push origin master").
11. If you want to checkout the latest copy from the Git server repository type "git clone file://localhost/g/foo_project"

Git Clone

To clone a repository as a user on the Git Server type the following:
1. Navigate to directory where you want your cloned copy to reside: "cd /c/checkouts"
2. Clone the project: "git clone file://localhost/c/repositories/foo_project"
3. Now you have a clone of the project in the "c:/checkout/foo_project" directory.

Thursday, December 17, 2015

dB vs. dBW vs. dBm Tutorial

Alexander Graham Bell, after which the bel,
and therefore the decibel, is named.


The decibel (dB) is a dimensionless unit used for quantifying the power ratio between two values. The unit is useful for describing the gain or loss in a system. It is used when characterizing amplifiers, attenuators, mixers, or RF chains as a whole. It is based on the bel and is defined as follows:

A power ratio is defined as:

power ratio = ouput_power / input_power

A bel is defined as:

power in bels = log10(output_power / input_power)

A decibel is 1/10 as large as a bel so ten decibels make up one bel:

1 bel = 10 decibels

And therefore power in decibels is defined as:

power in decibels = 10 * log10(output_power / input_power)

The table below shows the loss/gain as a power ratio compared to the loss/gain in decibels for several different values:

The table below shows a amplitude ratio, power ratio (which is just the amplitude ratio squared), and associated dB value. Note that the dB range for corresponding power ratios is much smaller, i.e, -100 dB to +100 dB corresponds to 0.0000000001 to 10000000000 power range. That makes the use of dBs desirable when dealing with large power ranges. An example would be a satellite communications system where transmit antenna signal power is +14 dBW and receiver antenna signal power is -160 dBW.

dBpower ratioamplitude ratio
100  10 000 000 000100 000
901 000 000 00031 623
80100 000 00010 000
7010 000 0003 162
601 000 0001 000
50100 000316.2
4010 000100
301 00031.62
10 10
63.9811.995 (~2)
31.995 (~2)1.413
−30.501 (~1/2)0.708
−60.2510.501 (~1/2)
−100.10.316 2
−300.0010.031 62
−400.000 10.01
−500.000 010.003 162
−600.000 0010.001
−700.000 000 10.000 316 2
−800.000 000 010.000 1
−900.000 000 0010.000 031 62 
  −1000.000 000 000 10.000 01
An example scale showing power ratios x and amplitude ratios √x and dB equivalents 10 log10 x. It is easier to grasp and compare 2- or 3-digit numbers than to compare up to 10 digits.

As you can be seen from the table above, 1 dB is approximately 26% power gain, 3 dB is approximately 2× power gain, and 10 dB is 10× power gain. This is useful to know for "back of the envelope" power calculations.


dBW is an abbreviation for the power ratio in dB of the measured power referenced to one watt (1000 mW):

power in dBW = 10 * log10((output_power_watts) / 1W)

For 1mW of power, you get -30 dBW.

For 2mW of power, you get -27 dBW.

For 1W of power, you get 0 dBW.


dBm, also written as dBmW, is an abbreviation for the power ratio in decibels (dB) of the measured power referenced to one milliwatt (mW):

power in dBm = 10 * log10((output power in watts)/1mW) = 10 * log10((output power in watts) / 0.001)

For 1mW power, you get 0 dBm.

For 2mW power, you get about 3 dBm.

For 1W power, you get 30 dBm.

So doubling the power is equivalent to about a 3 dBm increase.

dBm to dBW Conversion

We know the following:

power in dBW = 10 * log10(output power in watts/ 1W) = 10 * log10(output power in watts)


power in dBm = 10 * log10(output power in watts/ 1mw) = 

                        10 * log10(output power in watts / 0.001) = 
                        10 * log10(output power in watts * 1/1000)

So we need to divide the dBW power ratio by 1000 to equate it to the dBm power ratio. But we know that 10 * log10(1/1000) is -30 dB. 

And since we know: 

log10(X * Y * Z) = log10(X) + log10(Y) + log10(Z) 

we can just subtract 30 dB from the dBm value instead of dividing the power ratio by 1000 to arrive at the dBW value. 

So for example, 50 dBm - 30 dB = 20 dBW.

Both dBm and dBW are used for measuring absolute power.


Wednesday, December 2, 2015

Matlab Standalone Installer How-To

I have a Windows 7 PC that does not have Internet access. I need to install Matlab on it but the Matlab website will not allow me to download a standalone installer. The only option they offer is to download a smaller installer that will then connect to their site and download and install Matlab.

Here's a little bit of backstory. As of R2014a, License End Users do not have the ability to download their software without installing it.  Currently, only the Administrator and the Asset Managers have the ability to download only or to download and install the software. With a little work I was able to achieve a workaround.

I've detailed the steps below to download the installer so that you can install Matlab on a PC that does not have Internet access.

Navigate to the Mathworks License Center:

Click "Activation and Installation"

Click "Activate"

Fill out the activation form with the information for the PC where you want to install Matlab. Download the License File and save the Activation Key to a text file. They'll be used for the standalone installation later on.

Next download Matlab by purchasing a license or using an existing one as shown below:


Which will bring you to the actual download page. Save the executable to a known location, in this example we'll be using the c:\downloads folder.

Once you've downloaded the executable, run it. It will extract files to a directory named c:\downloads\Matlab_R2015b_win32_Installer" or something similar depending on the version you've downloaded. This folder will be used later. 

Let the installer download and install Matlab on your PC. Don't worry about activation as you won't be using it on this PC anyhow. Once downloading is complete navigate to c:\downloads (or whatever download directory you used). There will be a directory in there called Mathworks. This directory contains Matlab installation files. These files will have to be combined with the files from the c:\downloads\Matlab_R2015b_win32_Installer directory to create the standalone installer. 

Copy all of the files from c:\downloads\Mathworks\archives\common\*.* to c:\downloads\Matlab_R2015b_win32_Installer\archives\common
Copy all of the files from c:\downloads\Mathworks\archives\win32\*.* to c:\downloads\Matlab_R2015b_win32_Installer\archives\win32

I like to keep my installers in c:\software. So I copied over the c:\downloads\Matlab_R2015b_win32_Installer folder to c:\software and renamed it to Matlab R2015b for simplicity.

Now you can burn the "Matlab R2015b" folder to a DVD / flash drive along with the Activation Key and License File downloaded above and you'll be able to install Matlab on a PC that doesn't have Internet access. Just click on the setup.exe file to launch the installer.