A Developer's Diary

May 6, 2017

Ubuntu: Add new screen resolutions

Many times, the default resolution provided by your new Ubuntu installation is not compact enough.
In order to add a new resolution if not listed in your display drop down already, execute the following commands sequentially

Get the mode of the resolution you want to add
sudo cvt 1600 900 60

Copy the complete string after Modeline. This will be used to create a new mode
pankaj@pankaj-ubuntu:~$ sudo cvt 1600 1200 60
# 1600x1200 59.87 Hz (CVT 1.92M3) hsync: 74.54 kHz; pclk: 161.00 MHz
Modeline "1600x1200_60.00"  161.00  1600 1712 1880 2160  1200 1203 1207 1245 -hsync +vsync
Create new mode
sudo xrandr --newmode "1600x1200_60.00" 161.00 1600 1712 1880 2160 1200 1203 1207 1245 -hsync +vsync

Add the new mode created above to the list of displays in the dropdown
sudo xrandr --admode 1600x1200_60.00

Get the display name
sudo xrandr -q

For more details on the above, please watch the video below


Read more ...

Oct 2, 2013

Automatically registering the jdbc driver

A jdbc driver can be registered with the Driver Manager in four ways.
1. Automatic Registration
2. Using Class.forName("DRIVER_NAME")
3. Using property -Djdbc.drivers=DRIVER_NAME
4. Explicit registration using the new operator

Automatic Registration
Starting JDBC 4.0, the DriverManager methods getConnection() and getDrivers() have been enhanced to support automatic registration of the driver using the Service Provider mechanism.

Read more ...

Sep 2, 2013

Find depth of the deepest odd level leaf node in a binary tree

Write a program to find maximum height of the odd level leaf node of a binary tree. The problem has been picked up from GeeksforGeeks

A quick solution will be to use the solution for finding the max depth of the tree and modifying it to calculate the depth using only the odd level leaf nodes.

Read more ...

Aug 29, 2013

Find max height of a binary tree

Program for finding maximum depth or height of a binary tree

/**
     * find height of the tree recursively
     */
    public static int maxHeight()
    {
        return maxHeight(root, 0);
    }
 
    private static int maxHeight(Node node, int h)
    {
        if (node == null)
        {
            return h;
        }
 
        int lh = maxHeight(node.left, h + 1);
        int rh = maxHeight(node.right, h + 1);
 
        return (lh > rh) ? lh : rh;
    }

Read more ...

Aug 25, 2013

Creating a binary search tree using iterative approach in Java

Program for creating a binary search tree using iterative method

private void addNode(Node node, int n)
{
    while (node != null)
    {
        if(n < node.data)
        {
            if(node.left != null)
            {
                node = node.left;
            }
            else
            {
                node.left = new Node(n);
                return;
            }
        }
        else if(n > node.data)
        {
            if(node.right != null)
            {
                node = node.right;
            }
            else
            {
                node.right = new Node(n);
                return;
            }
        }
        else
        {
            System.out.println("WARNING: Elements are equal");
            return;
        }
    }
}

Read more ...