64 bit division

If you are trying to do this inside the kernel:
unsigned long long arg1, arg2;
arg1 = arg1/arg2;


and you get this error:
Unknown symbol __udivdi3

You ought to do this instead:
unsigned long long arg1, arg2;
unsigned long temp = arg1;
do_div(temp, arg2);
arg1 = temp;

Installing RPMs on Ubuntu

Method 1

1. Install rpm
$ sudo aptitude install rpm

Along with other things it would install rpm2cpio. (RPM and initramfs use the CPIO archiver)

2. Extract the contents of the RPM
$ rpm2cpio < some-package.rpm | cpio -i --make-directories --verbose

3. Copy over the required files to the different directories.



Method 2

1. Install alien
$ sudo aptitude install alien

2. Covert the .rpm to .deb
$ sudo alien --to-deb --scripts --verbose some-package.rpm

NOTE: Alien internally uses rpm2cpio, so make sure you have installed rpm.

--scripts : If the .rpm has scripts then you need to include those

3. Install the .deb file.
sudo dpkg -i some-package.deb

The advantage of converting it to .deb and installing using dpkg is that you can manage the install\uninstall\reinstall and version using apt\aptitude.

LCD monitor resolution

Got a new Samsung 22" 1920x1080 monitor and the default resolution being shown was 1280x800. Now with 8.04 I used to do dpkg-reconfigure xserver-xorg and it would redo the X11 configuration.

In Jaunty, the above command just configures the keyboard setting. In order to get the monitor to work with the correct resolution do

$ xrandr

This would probe the monitor and display the resolutions, then do the following

$ xrandr --output VGA --auto --above LVDS

emacs - indent entire buffer

c-set-style {chose the mode}
C-x h
C-M \


Line 2: selects the entire buffer
Line 3: changes the indentation

20 great GDM screens for Ubuntu

Awesome GDM screens for Ubuntu, here

Installing is very easy:

1. Click on the theme you like and download the archive.
2. Right click on your name on the upper right-side toolbar and select "Setup login screen"
3. Click on "Local" pane, then on the "Add" button, browse to the folder where you downloaded the archive (tar.gz) and then select the theme.

Bingo! you are done. logout and log back in!!

The best part is that you can select "Random from selected", pick the best ones and every time you login, it would be a different theme!

emacs client

When one instance of emacs is already running and you want to open files from command line into the same instance, use emacs client.

First, start the emacs server. Add the following line in your .emacs file:
(server-start)

Start emacs, and use emacs client from the command line to open the files in the already open emacs instance:
emacsclient -n filename

It helps to create an alias:
alias cemacs='emacsclient -n'
alias emacs='emacs &'

new system

Just installed a new system with a fresh Ubuntu install? Install all the packages in one shot,

~$ sudo aptitude install build-essential ddd insight kdbg kdevelop eclipse eclipse-cdt eclipse-jdt kompare kate bless kile lyx cscope global octave kmplot vim emacs virtualbox-ose pdfedit scribus inkscape checkgmail kompozer manpages manpages-posix easytag gtkpod vlc libncurses5 libncurses5-dev dialog curl sun-java6-jre sun-java6-jdk wireshark qt4-dev-tools qt4-assistant qt4-designer qdevelop monodevelop umbrello git git-core gitk git-gui graphviz doxygen doxygen-gui

Apart from that, install the individual .deb for

1. Google Chrome (dev channel)
2. Skype for 32 bit (64-bit still shaky)
3. Picasa for Linux

Before installing new packages, do
~$ sudo apt-get update; sudo apt-get upgrade

sudo first

Check if you running your script through sudo.

if [[ $(/usr/bin/id -u) -ne 0 ]]; then
    echo "Not running as root"
    exit
fi

Linux Kernel design patterns

Linux kernel design patterns, part 1, part 2 and part 3.

Gnuplot - resources

Very useful gnuplot resources
  1. The official gnuplot documentation and demos (The demos are really useful as they give the scripts that can me modified to suit your plot)
  2. Introduction to gnuplot 
  3. Creating graphs with gnuplot part1, part2 and part3

Git

Started using git.. this page would get more info as I learn more.

1. A very good presentation\video - here
2. Git documentation guide\book - here
3. Understanding Git, another tutorial - here

Tweet from the command line

Do this from the command line

curl -u username:password -d status="the message" http://twitter.com/statuses/update.xml

Add the following function in your .bashrc file.

# function to tweet
tweet() {
  flag=0
  if [[ -z "$1" && -z "$2" ]]; then
    echo "Usage: tweet password \"message\""
    echo "Make sure the message is within quotes"
    flag=1;
  fi
  if [ ${flag} == "0" ]; then
    echo "Sending message...."
    curl -u username:$1 -d status="$2" http://twitter.com/statuses/update.xml
  fi
}


and then do
$tweet password "The message goes here"

[Source]

more vim

Useful stuff to put inside your ~/.vimrc file

" Set tab width
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set smartindent
set expandtab
set cursorline

" Show line numbers and cursor position
set ruler
set number

" Disable default splash screen
set shortmess+=I
set guioptions-=T

" Show tabs and trailing white spaces
set list listchars=tab:-»,trail:·,extends:»

" Don't generate backup files
set nobackup

" Set default color scheme to something
colorscheme something


If you don't have it, create a folder ~/.vim/colors and put the color scheme inside.

Color schemes are available here