Iterate and Initialize all sub classes in python

In various situations, we need a mechanism to Initialize all Sub classes for a given Super class. For instance, let’s assume that we have a Super class called ArithmeticOperation and another 4 classes derived from it (Addition, Subtraction, Multiplication and Division).

One way of doing it is Initializing each Sub class separately.

But if there are hundreds of Sub classes, we need to think of another mechanism.  That’s where .__subclasses__() becomes very useful. We can use that method to Iterate and Initialize all Sub classes for that given Super Class. You can do it like this,

Hope this post helped someone who’s looking for a way to Iterate and Initialize all Sub classes for a given Super Class using python. 🙂

 

IPTABLES nat PREROUTING does not work on localhost

Let’s assume you have to use IPTABLES to redirect a PORT to another PORT (I.e. : Redirect connections on port 80 to port 9191). Then you probably use a IPTABLES rule like this:

This will work perfectly for external clients. But if you try to access the port 80 from the same machine (localhost), you will end up getting a connection refused error or port not been redirect correctly.

This happens because PREROUTING isn’t used by the loopback interface. Therefore, you have to add an OUTPUT rule along with the PREROUTING rule.

How to Make Free Calls using Google Hangouts

Google announced that Google Voice calls would integrate with the Hangouts service. People who don’t prefer calling over their carriers’ cellular network, can now use Hangouts and make free calls over WiFi or Data-plan. And the best part is new Hangouts don’t even need a SIM card in your phone in order to make a call.This will allows you to reach out to your loved ones even in WiFi-only situations.

Moreover, Google Hangouts now features free calling on Android, iOS and the Web to any US or Canadian phone number, or to any other Hangout user. But International calling does cost, but they say their rates are so low that you probably won’t even notice spending any money.

If you are interested of making free (or cheap) calls, follow this steps;

Continue reading How to Make Free Calls using Google Hangouts

How to install New Firefox on Ubuntu

This simple step by step tutorial will explain you how to download and install Mozilla Firefox on your Ubuntu PC / Laptop.

  1. Download Mozilla Firefox from their downloads page (Since now they support both 32bit and 64bit architectures, make sure to download the correct version): Click Here
  2. Once you have downloaded, go to that download directory and extract the downloaded tar.bz2 file
  3. Then move that extracted content (firefox folder) to /opt/ directory
  4. Now create a link in /usr/share/pixmaps/ pointing firefox icon. (in-order to use with desktop entry)
  5. Now create a desktop entry for ease of access.
    1.   Create a new .desktop file for firefox
    2. Copy and Paste below content to opened firefox.desktop file
    3. Now save that file
  6. That’s it. you are ready to go. Now you can simply search in Ubuntu dash for firefox.

If you find this useful, Please leave a comment below.

How to use ( set, get, delete ) cookies in JavaScript

In this post you can find to how to set, get (retrieve) and delete cookies using JavaScript. This might comes in handy when you want to securely  store small amount in the client side.

 

Working example : click here