Posts

Showing posts from February, 2009

Introduction to Vim for Programmers

Vim editor:

It has 3 modes:

Ex mode <----> Command mode <-----> Insert mode.

You can never go from Insert to Ex mode directly or vice versa. You always
first need to go to command mode. Enter command mode by typing Esc and enter Ex mode by typing :.

For cursor movement:

k
h l
j
Cursor movement commands: {motion} commands:
G - Last line in file
gg - First line in file
% - Jump to matching brace (()}{[])
m{1etter} - example ma to mark a line. There can be at
max 26 marks in the file.
`{mark} - example `a to jump to the named mark.
`` - Jump to the last line where you jumped or searched from.
/expr - forward search where expr = is a regex.
?expr - backward search.
n - repeat last search in the same direction.
N - repeat last search in the opposite direction.
w - move cursor forward by one word.
b - move cursor backward by one word.
Some more cursor movement commands:
Cntl + F - move one screen forward.
Cntl + B - move one screen backward.
f{char} - positi…

A short introduction to GNU make

A make rule looks like the following:

target: prerequisite
commands
Example:

.PHONY: all
all: program1 program2
program1: a.o b.o
gcc -o program1 a.o b.o
program2: c.o d.o
gcc -o program2 c.o d.o

This tells make not to search for a file named all and to assume that this target
is always obsolete.


Defining variables:

Variables in a make file are like in an ant build script but they
can only be set once unlike ant properties and dont change value.

FLAGS = first
all:
@echo FLAGS=$(FLAGS)

FLAGS = second
other:
@echo FLAGS=$(FLAGS)

The FLAGS variable is assigned the last value which is set in the build file
viz. second and so even if we run all target, the value echoed for FLAGS
will be second.
* So, a variable should be set just once in the make file. *

VAR = value
VAR := value

The := form allows variables to reference themselves without recursion.

VAR = value
# Wrong! Causes infinite recursion
VAR = $(VAR) more

# Okay, the := prevents recursion
VAR := $(VAR) more

# A GNU extension that does the same thing
V…

VNCServer Configuration

In the ~/.vnc/xstartup we can configure vnc session to start in gnome or kde, as shown below:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &            
/usr/dt/bin/dtwm &
#startkde &
unset DBUS_SESSION_BUS_ADDRESS;gnome-session & Then start vnc server as:
$ vncserver  This will tell you the hostname:sessionnum and set the password:

$ vncpasswd Optionally you can change the screen size for your session as:
vncserver :displaynum-geometry 1920x1080 Now you are all set to connect with your favorite vnc client (i use ultravnc).

For XFCE desktop change the xstartup file to:
#!/bin/sh
# Uncomment the following two lines for normal desktop:
 unset SESSION_MANAGER
 exec /etc/X11/xi…

Port Forwarding : Accessing your home computer from work

In order to access the home ubuntu desktop from work, following is what i needed to do:
Installed open-ssh demon on ubuntu with: sudo apt-get install open-sshTested that i could use a windows box on the home lan to access the sshd using putty.Once sshd is setup, followed the instructions at http://www.portforward.com/help/pfprogression.htm, which is broadly the following:
First we need to setup static/manual IP on the host computer to which we want to forward the port(s) to. Mine was setup to obtain IP address using DHCP so i first changed that to manual.Then login to the router (mine is an Air-link AR670W) and enable Port Forwarding for the SSH application port 22 for both TCP/UDP protocols and provided the static IP of my ubuntu desktop. Saved the configuration and router reboots after that.
Then i noted down the ISP assigned public IP to my router's external interface and used that IP (external IP of my router) from a windows box to putty to. Since the SSH port 22 on router is c…