Sunday, February 16, 2014

Removing old linux kernel images in Ubuntu

To see how many linux kernel image versions you have, do ls /lib/modules. You will see a list of directories (e.g. 2.6.32-51-generic, 2.6.32-52-generic, etc.)---one directory per kernel image version.

Note down the versions that you want to remove (usually, you should keep the last two versions---the last one for normal booting, and the previous one as a fallback).

Open Synaptic. Search for the version number (e.g. "2.6.32-51"). Scroll down the entries for the kernel image and kernel headers, e.g.
  • linux-image-2.6.32-51-generic
  • linux-headers-2.6.32-51-generic
  • linux-headers-2.6.32-51
Usually three entries of the kind mentioned above will be shown as installed in Synaptic. Choose each one, and "Mark for Complete Removal". Apply the changes.

After the Synaptic finishes applying the changes, you can see that the corresponding directories have been deleted from /lib/modules. The next time you start Ubuntu, the removed kernel images will not appear in the (GRUB) boot menu.

Wednesday, February 5, 2014

Using bc in calculations

To use the linux command bc for calculation in shell programs, do the following:
  • Add the line scale=2 to the file ~/.bcrc.
  • Then use var1=`echo "($var2+$var3)/$var4" | bc` to set var1.
Here
  • The scale parameter tells bc to use 2 decimal digits.

Monday, November 25, 2013

Very Quick File Server

Just cd into the desired directory, and run python -m SimpleHTTPServer. You get the message "Serving HTTP on 0.0.0.0 port 8000 ...". Now go the browser and type localhost:8000, and start browsing files/folders in that directory. Share the link http://<your IP addr>:8000 to let your friends browse as well.

[Tested on Ubuntu 10.04 (64-bit) with Python 2.6.5.]

Wednesday, October 16, 2013

Piping stderr

To pipe stderr (instead of stdout) use `|&' instead of `|'. This works from Bash 4 onwards. It is shorthand for `2>&1 |', which redirects bytes sent to stderr (2) to stdout (1), and then pipes it (|).

[Courtesy stackoverflow.]

Saturday, October 5, 2013

Simple Java development setup

A simple setup for small Java development projects could be:
  • Create the source directory ($PROJ_HOME) which will contain all .java files.
  • Create the directory $PROJ_HOME/proj_name which will contain all the .class files.
  • Add $PROJ_HOME to the CLASSPATH.
  • During development, keep a terminal open with working directory $PROJ_HOME, and run "javac *.java -d ." to compile all source files and store the class files in proj_name.
  • Run a class from anywhere using java proj_name.ClassName [args].
In addition:
  • Store metadata files etc. required by the code in $PROJ_HOME/meta. If they need to be passed by command line arguments, you can pass $PROJ_HOME/meta/datafile.txt as an argument wherever you are running the class.
  • Store sample test data files to quickly test the code in $PROJ_HOME/test.

Saturday, September 7, 2013

Enabling Indic transliteration on web pages

Enable typing in Indian languages in web pages using Pramukh IME. This javascript library is very easy to integrate into your website, and supports 20 Indian languages.

Also, it is open source; so you can add new languages, or change the keyboard layout for existing ones.

Tuesday, August 6, 2013

Rendering math in blogs

To render LaTeX-style mathematical formulae in blogs, use MathJax, as shown here. Once set up, you can do
  • \( <math text> \) for inline math
  • \[ <math text> \] for equations