Showing posts with label techtips. Show all posts
Showing posts with label techtips. Show all posts

Wednesday, August 29, 2012

Pound sterling and Euro sign and Indian Rupee symbol on a UK keyboard

Well,
         I am in UK right now and I am going to be here for quite some time. One thing annoying about being in UK is UK keyboard. Especially once you have a habit of using a US keyboard. Thankfully, I have brought my ergonomic US keyboard with me over here. But then the trouble is what do you do if you want to type £ ? If you are a linux person like me, this is what you should do.

Create a file named .Xmodmap in your $HOME.
Put the followings in the file


add mod3        =       Mode_switch
keysym  Alt_R   =       Mode_switch
keycode 26 = E NoSymbol EuroSign cent
keycode 46 = L NoSymbol sterling cent
keycode 27 = R NoSymbol U20b9 NoSymbol

What it does is that it assigns ALT_R (Right Alt)+e to €, ALT_R+SHIFT+e to ¢, ALT_R+l to £, ALT_R+SHIFT+l to ¢ and ALT_R+r to ₹. For more details refer to 'man xmodmap'.

Now, either you logout and log back in or run

 xmodmap ~/.Xmodmap

and Voila!! You have pound sterling , euro, cent sign and Indian rupee symbols available at your finger tips!! Literally!!


Friday, October 01, 2010

Vim Trick : Search and Replace

Today I found out a cool vim trick. Not so much great, but sure it's nice to know.

For example, if you want to search for string consisting of all a's followed by all b's and then reverse it.


aaaaaabbb -> bbbaaaaaa

:s/\(a+\)\(b+\)/\=submatch(2).submatch(1)/

\(regexp\) defines an atom in vim. So the first atom is defined as a* and the second is defined as b*. In the replace pattern we are executing a vim expression. submatch(0) stands for the entire matched pattern where as submatch(1), submatch(2) stands for the strings matched by first atom, second atom etc.

So the above vim command reverses the order of a's and b's. Having a vim expression as a replace pattern gives enormous power and can be used for much more complex things :-)

Tuesday, November 04, 2008

How to : QEMU networking

Hi All,
It has been ages since I have written anything over here. One of the main reason is that I have started posting mathematical post at my wordpress blog.

Anyways, Sameer and I were trying to get our hands dirty on Qemu networking. Although there is a fairly good description is given over here, I am trying to fill in here a few missing bits.

Okay, so here is the scenario we want to create.

On one machine ( say host-A ) we want to create many guest machines ( guestA1, guestA2 ) etc. Similarly, there is another machine ( host-B ) having many guest machines ( guestB1, guestB2 ). We want to make guestA* communicate with guestB*.

I am assuming that readers are aware of how to install a guest OS on a guest machine created by qemu.

First we need to configure a ipv4-over-ipv4 tunnel for the host machines.

--host-A configuration is as follows

ip : 172.27.16.1
netmask : 255.255.255.0
default gateway : 172.27.16.254

host-B configuration is
ip : 172.27.16.2

netmask and gateway is the same as above.

--In host-A ( as root ) do the following

root@hostA# ip tunnel add tunl1 mode ipip remote 172.27.16.2 dev eth0

-- this command essentially create one endpoint of the tunnel in host-A. It says that the other end of the tunnel lies at ip 172.27.16.2. Also, the tunnel device will use eth0 as its physical device.

root@hostA# ip link set tunl1 up

-- this command will bring up the tunnel interface

root@hostA#ifconfig tunl1 10.0.1.1 pointopoint 172.27.16.2

-- guestA network will be 10.0.1.0/24 network and tunnel device should be a part of it. This command gives the tunnel device an ip address and it says that other endpoint of the tunnel will be at 172.27.16.2

root@hostA# route

--this will show you the current configuration of routing table. There might be an entry in the routing table

172.27.16.2 * 255.255.255.255 U 0 0 tunl1

--you need to delete this entry using following command :

root@hostA# route del -net 172.27.16.2 netmask 255.255.255.255 dev tunl1

--Also you need to tell routing table that guestB network ( 10.0.2.0/24) should be routed through the tunnel

root@hostA# route add -net 10.0.2.0 netmask 255.255.255.0 dev tunl1

--You need to repeat the same procedure for hostB with suitable ips ( use 10.0.1.* instead of 10.0.2.* and vice versa , replace 172.27.16.1 with 172.27.16.2 and vice versa )

--By now, your tunnel should be working. To check, try

root@hostA# ping 10.0.2.1

root@hostB# ping 10.0.1.1

--If it does not ping, it might be the case that your firewall is coming into the way. If you are expert enough, modify your firewall rules with iptables. If not, lets first save your firewall rules

root@hostA# iptables-save | cat > iptablebackup.bak

--flush the firewall rules now

root@hostA# iptables -F
root@hostA# iptables -t nat -F

--Now, that firewall is completely disabled, the tunnel should work. (Of course, you need to disable your firewall at hostB as well! ) If it still does not work, then there might be some other problem or you might not have done things right.

-- you can restore your firewall ( later ) with

root@hostA# cat iptablebackup.bak | iptables-restore

--Okay, so the tunnel is working now!! Great news!! But what next??
Next we create a tapping device - a virtual network interface - which will be visible to the guest OSes.

root@hostA# tunctl -u username

-- provide a username here. This user will be able to use this tapping device while initializing qemu process. This command would have created a tapping device (tap0) in your system

--assign an ip address of guestA network to tapping device

root@hostA# ip addr add 10.0.1.2 dev tap0

-- bring the tapping device up

root@hostA# ip link set tap0 up

-- Also create a file /etc/qemu-ifup which can look like following :
#!/bin/bash
#echo "bringing up interface $1"

-- Now start the first guestOS

username@hostA$ qemu -net nic,macaddr=macaddr1 -net tap,ifname=tap0 -net socket,mcast=230.0.0.1:9999 ....

--second guestOS can be started with following
username@hostA$ qemu -net nic,macaddr=macaddr2 -net socket, mcast=230.0.0.1:9999 ...

-- multicast socket is needed for mchines in guestA network to talk to each other

--In the guestA1 do the following :

root@guestA1# ifconfig eth0 10.0.1.3 netmask 255.255.255.0
root@guestA1# route add default gw 10.0.1.2 dev eth0

-- Note that we have given the ip address of tapping device as the gateway fo guest OSes
-- second, third etc guest machines can be configured with different ip addresses for their eth0

-- Repeat this procedure on host-B as well with appropriate ip addresses.

-- Now, you should be able to ping machines from guestA network to guestB network and vice versa. However, this does not yet allow you to connect to host network. To do that, you need to enable ip forwardng

root@hostA# echo "1" > /proc/sys/net/ipv4/ip_forward

-- perform source NAT

root@hostA# iptables -t nat -I POSTROUTING 1 -o eth0 -j SNAT --to-source 172.27.16.1

--Now, from guestA network ( 10.0.1.0/24 ) you should be able to connect to ( 10.0.2.0/24 ) as well as host network ( 172.27.16.0/24 )

-- To delete the tunnel

root@hostA# ip link set tunl1 down
root@hostA# ip tunnel del tunl1

--To delte the tapping device

root@hostA# tunctl -d tap0

--Above mentioned setup is tested with host machines running fedora core 9 and guest machines running Arch Linux, Debian etc.

If you have any queries post it as comments, I will be willing to answer if I can.

Friday, January 12, 2007

Esterel : Syntax and Indent files for Vim

The other day I was programming in Esterel with my favourite editor Vim. And it turned out that I did not have syntax and indent files which would make my life easier while using Esterel.

I could find syntax file for esterel from somewhere, and I modified, indent file for shell scripts to suit for esterel.

You must add following 3 lines to your .vimrc file :
au BufRead,BufNewFile *.strl set filetype=esterel
au! Syntax ESTEREL source /usr/share/vim/vim63/syntax/esterel.vim
:filetype indent on


Change the source where you had put the syntax file for esterel.
Ideally it should go to $VIMRUNTIME/syntax and $VIMRUNTIME/indent respectively.

Anyways, here are the links for the syntax and indent file for esterel.

Tuesday, June 14, 2005

Cutting and Joining video clips through mencoder ( mplayer)

to cut, use

mencoder uncut.avi -ss 0:20 -endpos 10 -ovc copy -oac copy -o cut.avi

-ss is for starting position and -endpos is for ending position. Use man pages for more detail.

For joining, I have got this script from somewhere, I never tried it myself though :-)

#!/bin/bash
#
# $Id: join-avi-files,v 1.3 2004/09/26 16:10:36 thor Exp $
# Tom Moertel
#
# Usage: join-avi-files outfile.avi in1.avi in2.avi ...
#
# This program joins the given movie files in1.avi, in2.avi, ...
# and saves the result as outfile.avi. Although the name is
# join-avi-files, this program will join any kind of movies,
# provided that mplayer knows about them and that the movies
# all use the same codecs, resolution, stream rate, etc.

# COPYRIGHT AND LICENSE
#
# Copyright (C) 2004 Thomas G. Moertel.
# All rights reserved worldwide.
#
# This code is licensed under the GNU General Public License, version
# 2 or greater. It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.


# CODE

# preflight inputs

if [ $# -lt 2 ]; then
echo Usage: $(basename $0) outfile.avi in1.avi in2.avi ... 1>&2
exit 1;
fi

# shift the output file from the command line

outfile="$1"
shift

# as a safety precaution, make sure the output file doesn't already exist

[ -f "$outfile" ] && {
echo "$outfile already exists; aborted." 1>&2;
exit 2;
}

# create a temporary directory in which to do our work

tmpdir=$(mktemp -d join-avi-files-XXXXXXXXXX)
[ -d "$tmpdir" ] || { echo "can't make tmp dir" 1>&2; exit 3; }
mkdir "$tmpdir/in" || { echo "can't make in dir" 1>&2; exit 3; }
mkdir "$tmpdir/out" || { echo "can't make out dir" 1>&2; exit 3; }

# make sure the temporary directory is cleaned up

cleanup() { rm -rf "$tmpdir"; }
trap cleanup 1 2 3 5 13 15

# massage each input file into valid form

counter=100000
for infile in "$@"; do
echo
echo === SCANNING INPUT: $infile ===
echo
base=$(basename "$infile")
mencoder -idx "$infile" -ovc copy -oac copy -o "$tmpdir/in/$counter-$base"
counter=$(( $counter + 1 ))
done

# merge the massaged input files

echo
echo === WRITING OUTPUT: $outfile ===
echo

outbase=$(basename "$outfile")
cat "$tmpdir/in/"* > "$tmpdir/$outbase"
mencoder -noidx -ovc copy -oac copy -o "$outfile" "$tmpdir/$outbase"

# clean up and exit with success

cleanup
echo
echo Done!

exit 0

Monday, June 06, 2005

Exporting sound and display in linux

Hi,
well, i knew long ago how to export a display from a remote terminal. this helps to get display for graphical applications that one may want to run on remote machines.

At the end where you are sitting (server) the thing that you have to do is

$ xhost +
which will disable access control and any client can connect to the running X server.

at the client side ( where you have remotely logged in )

$ export DISPLAY="servername:terminal"

terminal numbers start from 0.0.
If you are not sure of which terminal you are using just run the following command on the server

$ echo $DISPLAY

which will give you the terminal number that you should be using at the client side.

Alternatively, a very simple method for doing all this in just one shot is that while logging in to a remote machine

# ssh -X remotemachine

this will do all the above mentioned thing for you.

for sound also the procedure is the same.

on server
# artsd -p portnumber -u

you can select any portnumber which is greater than 1024 and not already in use by some another application. -u will disable the access control. for more options
# artsd -h
this will provide you all the available options for arts deamon.

whereas on the client side
# export ARTS_SERVER="servername:portnumber"

you can also provide IP addresses instead of giving names in the environment variables.

If your mplayer still does not produce sound than you should check which audio output mathod it is using. one can specify a particular audio output mathod using

# mplayer -ao arts filename

Now, you can login to remote machines and enjoy the songs/movies etc. :-)