Using VLC player to play Internet Radio

Agent M sent me a link to a very good online western classical radio site. In order to play the radio inside Firefox on Ubuntu the gstreamer plugins are required. The other option is to play it through VLC player.

Install VLC player
%% sudo aptitude install vlc

Open the link in VLC, Media->Open Network, enter the URL and you are good to go.

To avoid this step every time, create a launcher.

1. Right click on the desktop, "Create launcher"
2. Give it a name, "My Radio"
3. In the command use the following /usr/bin/vlc "URL"
4. You can specify a tool-tip comment as well, "ABCD Radio"
5. Click on the icon and select the icon of your choice form /usr/share/icons/hicolor/scalable

Enjoy the music

Battery monitoring from console

If you prefer to work on a console based machine (without gdm\kdm), the following script is useful if you are running your laptop on battery. It shows the current battery charge and can be used for monitoring the battery discharge.

#!/bin/sh
# While working in console mode (without gdm) this script
# tells you the remaining charge of your laptop battery
#
# Run it along with watch on a separate tty
# $ watch -n 10 ./batmon
#
# (c) Hunterwala, 2009
#
# TODO: check for error levels and buzz using pcspkr mod
# when the charge level decreases beyond that level.

PROC_PATH="/proc/acpi/battery/BAT0"

org_cap=`cat $PROC_PATH/info | grep "last full capacity" | sed "s/ //g" | awk -F: '{print($2)}' | sed "s/mAh//g"`
rem_cap=`cat $PROC_PATH/state | grep "remaining capacity" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`
message=`cat $PROC_PATH/state | grep "charging state" | sed "s/ //g" | awk -F: '{print($2)}'| sed "s/mAh//g"`

diff=$(echo "($org_cap-$rem_cap)" | bc)
total_per=$(echo "100-($diff*100/$org_cap)" | bc)

echo "Battery is" $message ":" $total_per"%"


Save this script as batmon.sh

Change the permissions chmod a+x batmon.sh

Run it on a separate tty watch -n 10 ./batmon.sh

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