Configure your Belkin N150 router for BSNL broadband

  1. Login to your router dashboard. It should usually be at http://192.168.2.1.
  2. Now under “Inertnet WAN” click on “Connection Type”.
  3. Here select “PPPoE” and click on Next.
  4. Provide your BSNL username and password. Leave the “Service Name” field blank.
  5. For “VPI/VCI” field provide 0 and 35 as values.
  6. For “Encapsulation” field choose “LLC”.
  7. Leave all other fileds to their default values.
  8. Now Apply Changes. It will take around 30 seconds for the router to restart.
  9. Notice the top-right corner of the page and check the status. If it says “Connected”, then you are good to go.
  10. Else click on the “Home” link near that. On the home page click on Connect button.

Now you should be able to use this Wifi router with your BSNL broadband. Happy surfing. 🙂

PS: Now you no longer need to use your computer to dial the BSNL connection and login. Your router has your BSNL username and password, it will do the dialing and logging in.

Calculate Root of Any Whole Number in Java

The following Java program can find any root of a whole number. The logic is simple. Start by guessing some number and check if that is the correct value. If that overshoots then subtract some from the guess number else add to it. We add or subtract some fixed constant. If that constant is too big then we divide that constant by 10 to get a finer number.

#!java
public class CubeRoot {

    public static void main(String[] args) {
        System.out.println(String.format("%.2f", cubeRoot(0, 2)));
        System.out.println(String.format("%.0f", cubeRoot(8, 0)));
        System.out.println(String.format("%.4f", cubeRoot(10, 4)));

        System.out.println(String.format("%.4f", root(10, 2, 4))); // Square Root
        System.out.println(String.format("%.4f", root(100, 5, 4))); // 5th Root
    }

    private static double cubeRoot(int n, int precision) {
        return root(n, 3, precision);
    }

    private static double root(int n, int root, int precision) {
        double x = n / 5.0; // 5 is better than 4 since this will have bigger
                            // step. 3 is very bad choice since there are some
                            // no.s which will never have rational output when
                            // divided by 3, e.g. 5.
        double powX;
        double d = 10;
        double lastX = 0;
        double lastLastX = 0;
        do {
            powX = Math.pow(x, root);
            if (matches(powX, n, precision))
                return x;
            else {
                if (matches(lastLastX, x, precision)) {
                    // If the lastLast x value is same as current then we are
                    // trapped in a loop, since the current d is not small
                    // enough. We need to now step at finer precisions.
                    d /= 10;
                    if (matches(d, 0, precision + 1)) {
                        return x;
                    }
                }
                lastLastX = lastX;
                lastX = x;
                if (n < powX) {
                    x -= d;
                } else {
                    x += d;
                }
                // System.out.println("(x=" + x + ", d=" + d + ")");
            }
        } while (true);
    }

    private static boolean matches(double a, double b, int precession) {
        return ((int) (a * (long) Math.pow(10, precession)))
                - ((int) (b * (long) Math.pow(10, precession))) == 0;
    }

}

Google really finally allows India to sell Android apps

There were reports a month back I suppose when Google mistakenly added India to the list of approved countries. Later that they removed India from the list, apologizing for the mistake.

Now finally all India Android devs can rejoice. India is finally in the list. I just enrolled today. Check the below official link to confirm.

Supported locations for merchants – Google Play for Developers Help.

Django-Select2 version 3.1.1 released

Just released Django-Select2‘s version 3.1.1.

The key changes are:-

  • Updated Select2 Javascript library to versino 3.2. This new version fixes a lot of bugs, along with providing a high resolution icon image, to be used in Retina displays.
  • In my last release (version 3.0.2) I introduced some new template tags but unfortunately I did not update the setup.py and Manifest.in files to include that directory. That directory was missing in the released package. Now it is included and installed.

If you see the Changelog then you will notice that I jumped from version 3.0.2 to 3.1.1. In fact there was a version 3.1.0 in-between, but that was again a faulty package. That package had the templatetags directory but that does not install that. That was again due to some missing code in setup.py.