Tips and tricks FAQ

This FAQ is a collection of simple usefull tricks, mostly in Linux shell

 

How to synchronize files in ~/Documents between your computers (e.g. your desktop and your laptop)?

I prefer to use unison command. First of all, you need install openssh-server as well as unison itself on each of your computers:

sudo aptitude install ssh openssh-server
sudo aptitude install unison 

Then, check that all unison versions are the same on  all of your computers:
unison -version 

Now, add .unison-profile.prf file with the follwing content into ~/.unison directory on each of your computers:

On your desktop:

root = /home/vm
root = ssh://vm-laptop

path = Documents

backup = Name *
backuplocation = central
backupdir = /home/vm/.unison-backup/
maxbackups = 4

On your laptop:

root = /home/vm
root = ssh://vmhome

path = Documents

backup = Name *
backuplocation = central
backupdir = /home/vm/.unison-backup/
maxbackups = 4

Substitute computernames (vm-laptop and vmhome) and username (vm) accordingly.

Now, you have to createrun-unison.sh in your home directory with the following content:

unison .unison-profile.prf

Change its mode with chmod +x run-unison.sh and start it with ./run-unison eachtime you need to synchronize changes on both computers.



How to find all computers in current LAN?

sudo aptitude install nmap

and then

nmap -sP 192.168.0.1-255 to find all clients in your LAN.



How to process sound with command console?

I prefer to use sox utils. First, it must be installed:

sudo aptitude install sox  libsox-fmt-all

To write sound in raw byte stream:

rec -r 48000 -s -1 -t raw record.raw

where -s is signed (two's complement) byte format, -1 is one byte per sample, -r is sampling rate, -t raw is no-header, no-compression.

To play sound from raw byte stream:

play -r 48000 -s -1 -t raw record.raw




What is the best font for xterm?

Please use fc-list command to list all installed fonts. Then, select an appropriate one. Use smth. like:
xterm -cr red -bg MintCream -fg black -fa\ 'FreeMono:style=Normal' -fs 16 -geometry 90x35 +sb
to start xterm.



What is the best VHDL simulator?

It is GHDL. I strongly recommend to use this free Open Source GCC-based VHDL compiler. It follows almost all IEEE standards, has very fast compilation time and superb performance of generated code. In Debian compatible Linux systems you can install it with:
sudo aptitude install ghdl




What can I find and where?

Online TV:
zattoo
atdhe.net
myp2p.eu



How to compile and simulate designs described in VHDL?

I assume that GHDL compiler is being used. I strongly recommend to use this free Open Source compiler based on GCC technology. Let's say we have a module which is a design under test and a testbench. One can use following commands to simulate design:

MODULE=apple_keyboard
TB=apple_keyboard_tb
ghdl -a $MODULE.vhd
ghdl -a $TB.vhd
ghdl -e $TB
#ghdl -r $TB
ghdl -r $TB --vcd=$TB.vcd
gtkwave $TB.vcd



How to hide mp3 into image file?

For example, if you have orig.gif and orig.mp3 you can do following in order to hide orig.mp3 in comb.gif:
cat  orig.gif orig.mp3 >comb.gif
You will have big comb.gif, which is actually an image from orig.gif by viewing in any image viewer. But it has hidden mp3 inside! So, you can also distribute any information appended to a GIF file.
To restore orig.mp3 all you need is to know the size of orig.gif:
split -d -b BYTE_SIZE_OF_ORIG.GIF comb.gif
mv x00 orig.gif
cat `ls -1 | grep x[0-9]` > orig.mp3



What packages are required to be installed on a fresh Linux distro in order to work comfortably with Digital Design, Signal Processing and so on?

sudo aptitude install python-numpy python-scipy \
python-matplotlib ipython

 

 

What minimal .vimrc is required?

syntax on
set tabstop=2
set shiftwidth=2
set expandtab
"behave mswin
map <F10> <Esc>:setlocal spell spelllang=en<CR>
map <F11> <Esc>:setlocal nospell<CR>
"simple cursor movements
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk


 

Spellchecking in vim?

Normally all you need is sudo aptitude install vim and then, just use :set spell and :set nospell . Mispelled words will then be highlighted. To view spelling suggestions for a mispelled word, direct cursor on a word and press z=. More info gives :help spell command.

By the way, sometimes you want to switch off a highlighting by typing :highlight clear.

 

 

Substitute/Find in vim?

Substitute all occurances of Hello to Bye: :%s/Hello/Bye/gy where % means whole file as a scope (1,23 will mean a text block from line 1 to line 23), s means substitute, g means globally, y means confirmations will be required (can be avoided). To find some patter, just press / and type your search pattern (a regular expression).

 

 

How to switch xterm into fullscreen in Gnome?

System -> Preferences -> Keyboard shortcuts ->Toggle fullscreen mode. In xfce it was Alt+F11 if I remember it correctly (I use Gnome now after many years being a user of xfce)

 

 

 

Writing scientific articles and professional technical documentation.

First, you need install following tools:
sudo aptitude install latex-beamer texlive-latex-base texlive-latex-extra texlive-latex-recommended wordnet

Second, install vim and configure it like described above in this FAQ.

During writing texts each time you need antonyms, synonyms, overview etc. you can use following commands:

wn WORD -ants{n|v|a|r}        Antonyms
wn WORD -syns{n|v|a|r}        Synonyms
wn WORD -over                      Overview of Senses

where WORD is any english word (or german if you use experimental german language base). Last letter of search option generally denotes the part of speech that the search applies to: n for nouns, v for verbs, a for  adjectives,  and  r  for adverbs.


 

Working with graphics.

You need install following tools:
sudo aptitude install qiv imagemagick