Auto-mounting drives on Ubuntu at startup

Find out the device name of the partition you want to mount. Check under /dev or open the partition in nautilus (Ubuntu's file browser/explorer) and run the "mount" command in terminal to identify the device name e.g. /dev/sda3

Go to Ubuntu dash (top right) -> Startup Applications


Add a new startup application as shown in the image below and you're all set! Command : /usr/bin/udisks --mount /dev/sda3


The drive will be mounted automatically when you login to Ubuntu. This solution works on Ubuntu 11.10 (Oneiric), Ubuntu 12.04 (Precise Pangolin) and Ubuntu 12.10 (Quantal Quetzal).

For further details, more advanced settings and system-wide mounting, check - https://help.ubuntu.com/community/AutomaticallyMountPartitions

Changing the default editor in Ubuntu

  • Open terminal (ctrl + alt + t) and type "sudo update-alternatives -–config editor"
  • This will show all available editors 
  • Enter the number of the editor that you want to set as default and press the Enter key (and you're done!)

Another way to do this via the GUI is described here - http://www.addictivetips.com/ubuntu-linux-tips/2-ways-to-change-default-text-editor-in-ubuntu/

Changing the sudo timeout in Ubuntu

By default, Ubuntu remembers the sudo login for 15 minutes - this means you won't be prompted for your password for performing sudo operations for 15 minutes following a successful sudo login. This could be risky and can be changed so that the sudo password will be prompted for on every sudo login irrespective of the duration/timeout -
  • Open terminal and type "sudo visudo"
  • Locate the "Defaults ...." line as shown in the image below
  • Add this to the end of the line - ",timestamp_timeout=0"
    • Setting the timeout to 0 will prompt for the sudo password on every login. Alternatively this timeout can also be set to a number - e.g. setting it to 5 will remember the sudo password for 5 minutes.
  • Save the file and exit


Further reference

Preventing/Disabling Automatic Shutdown/Hibernate on Critical Battery Level in Ubuntu

In Ubuntu 11.10, the critical battery level behaviour can be controlled view the Settings -> Power. But it has 2 options only - shutdown & hibernate. Either of these options will immediately shutdown/hibernate Ubuntu on critical battery level.


To gain more control over this  -
  1. Install dconf editor. This is available on Ubuntu software centre as well
  2. Open the dconf editor (terminal > type dconf-editor)
  3. Navigate to org > gnome > settings-daemon > plugins > power
  4. Set the critical-battery-action option as required.
Settings the critical-battery-action to interactive will display a popup asking you what to do as shown below with a automatic-shutdown-timer of 60 seconds -


Edit: This option works for Ubuntu 12.04 (Precise Pangolin) and Ubuntu 12.10 (Quantal Quetzal) as well.

Generic excel file processing with Apache POI

I'm assuming that you already have a working knowledge of Apache POI. If not, here are some good starting points -

Generic?
Generic here stands for a single piece of code that can read both xls (Excel 2003 and prior) and xlsx (Excel 2007 and onwards) files.

How?
POI provides different components/models for working with xls and xlsx files - HSSF for xls and XSSF for xlsx. These components are further divided into models which differ in the way they process files. A comparision between these is shown in the image below (borrowed from here) -


The SS model lies on top of HSSF and XSSF models and provides the genericity we're talking about here. POI code written using the SS model will work for both xls (HSSF) and xlsx (XSSF) files.

Code
There's just one catch that needs to be taken care of - loading the excel file generically. For this we'll use the SS model's WorkbookFactory class which automatically detects the type of excel file and loads it.

(Note - Code borrowed from Java Dev Tips )

public List<List<String>> parseSpreadSheet(InputStream inputStream) {
    Workbook workBook = null;
    try {
        workBook = WorkbookFactory.create(inputStream);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Sheet sheet = workBook.getSheetAt(0);   
    List<List<String>> rowHolder = new ArrayList<List<String>>();
    int cellNum = sheet.getRow(1).getLastCellNum();   
 
    for (int i = 0; i <= sheet.getLastRowNum(); i++) {
        Row row = sheet.getRow(i);
        List<String> cellHolder = new ArrayList<String>();
 
        for (int j = 0; j < row.getLastCellNum(); j++) {
            Cell cell = row.getCell(j);          
            String cellValue = parseCellValue(workBook, cell);
            cellHolder.add(cellValue);
        }
 
        //add empty cells to the end if required
        while (cellHolder.size() < cellNum) {
            cellHolder.add(null);                  
        }
        rowHolder.add(cellHolder);   
    }
    return rowHolder;
}