Friday, October 31, 2014

Transfer or Export your PuTTy sessions between different Machines

Below are the steps to be followed
Exporting Your PuTTy Configuration:


Putty stores its settings in the Windows registry. To save a backup of your Putty settings, you'll need to export this registry key to a file.
 
1. Click Start->Run and type "RegEdt32" in the "Open" dialog. Click "Ok"

2. One RegEdt32 starts, you'll be presented with an application which looks something like:

3. Press "Ctrl+F" to bring up the Find dialog. Enter the name of the key, "SimonTratham" in the "Find what" field, and make sure only "Keys" is checked in the "Look At" section of the dialog. Finally, click "Find Next"

4. We should never change things in the registry unless we are absolutely sure and we know exactly what we doing. When the search completes we'll see the key name for which we're looking.
 

5. Click File->Export. Give your file an appropriate name like, "putty.reg" and click "Save"

6. Save the putty.reg file at some safe location

Importing Your PuTTy Configuration to other machine
To import your saved PuTTy settings on any other Windows computer simply copy the above registry file, right click on the file and click "Merge"

Windows will ask you for confirmation that you want to import this set of registry values. We know this file is safe, because we created it but, you should never import registry information from an unknown source.

That's all we are done. All our putty sessions and configurations have been exported to the new machine now. This is really useful information when upgrading to a new PC. Take my words if you're a Software Engineer you will definitely find this post very useful and to do this few times in your Career.

Usage

If we have a standard list of servers to be connected via SSH, we can create a reference configuration on one machine and "share" it between all the team members.

Sunday, November 24, 2013

Importing Filezilla Site Manager Connections

1)      Many times there is a need to change your machine or moved to a different machine or upgrade the version of FileZilla. The first thing which you would definitely want to avoid is re-entering all server connection details. Let us see how can we prevent this hassle and easily import all the settings from our current FileZilla. Below is am image of my SITE Manager having connection to 20 different servers.




2) To start exporting our current setting First open Filezilla and go to File àExport, and select the “Export Site Manager Entries”. This will create an xml file that we will be able to upload into our new version.





3)   Transfer this xml file over to your new computer and open Filezilla. Go to FileàImport, and then select the xml file having all your previous settings. It will quickly upload and then you will have all of your previous settings ready to go.






Usage:
  • If we have a list of server to which our team need to connect to, we can share this file will everyone and save a lot of time.

Tuesday, November 13, 2012

Template Method Design Pattern


Motivation:
At times different components have significant similarities with a only a few steps in between which might vary.  Let’s take few real time examples like buying a flight ticket online. We might buy the ticket from any website from anywhere most of the steps would be the same with some variations.
  •          Login to Website (We will have different websites).
  •          Selecting the itinerary for the journey
  •          Search the ticket (Different websites will offer different carriers).
  •          Apply the Offer (Offers will vary depending on the website).
  •          Select the ticket
  •          Payment

If we want to launch a new new website to book Air Tickets, Do I need to implement all these methods? How about if you get some default template implementation where you just need to plug few thing as per your requirements!!! Sounds interesting. Watch for the Template Method Pattern discussed below.

Definition:
Defines the skeleton of an algorithm in a method, deferring some steps to sub classes  Template Method lets sub classes redefine certain steps of an algorithm without changing the algorithms structure.

Structure:
The Template Method pattern is quite simple - let's look at a class diagram representation:



The AbstractClass contains the templateMethod(), which should be made final so that it cannot be overridden i.e. the order of the steps cannot be modified. This template method calls other operations available in order to run through the algorithm. Not all operations used by this template method need to be made abstract, we can have concrete methods with default implementation.

These concrete methods are that part of the algorithm which remains common. The ConcreteClass implements all the abstract operations required by the templateMethod in the parent class. There can be many different Concrete Class implementations. Abstract methods are that part of the algorithm which will vary.
Getting are Hands Dirty with Coding !!!
We will implement the above Flight Ticket booking Algorithm with help of Template Pattern.
  
public abstract class AirTicketBookingTemplate {
      public final void bookTicket() {
            loginToWebsite();
            chooseItenary();
            searchTicket();
            applyOffers();
            selectTheTicket();
            payment();
      }
      void chooseItenary() {
            System.out.println("Select Source/Destination/Date");
      }
      void displayingAllTicktes() {
            System.out.println("Displaying All the Availale Tickets!!");
      }
      void selectTheTicket() {
            System.out.println("You have selected the below Ticket!!");
      }
      void payment() {
            System.out.println("Payment Recieved !! Ticket Confimed.");
      }
      abstract void loginToWebsite();
      abstract void searchTicket();
      abstract void applyOffers();
}
This is the abstract class in which bookTicket act as a Template Method with some concrete and abstract methods.

Now let us have a look at our First Concrete Class:
public class MakeMyTrip extends AirTicketBookingTemplate{
      void loginToWebsite() {
            System.out.println("Welcome to www.makemytrip.com !!!");
      }
      void searchTicket() {
            System.out.println("Searching Jet Airways/Air India/Kingfisher/Indigo");
      }
      void applyOffers() {
            System.out.println("Current Offer is Buy one Ticket Get Another Free !!!");
      }
}
Another counterpart of MakeMyTrip which has really become popular these days is Goibibo. Let’s have a look and check how will they serve us. The booking algorithm or process is almost the same but it offers better Offers and gives us more number of choices to book the Ticket. Code is present below. 

public class GoIBiBo extends AirTicketBookingTemplate{
      void loginToWebsite() {
            System.out.println("Welcome to www.goibibo.com !!!");
      }
      void applyOffers() {
            System.out.println("Current Offer is Rs 200 off on one way 400 on return !!!");
      }
      void searchTicket() {
            System.out.println("Searching Sahara/Air India/Jet Lite/Go Air/SpiceJet/Jet Airways/Indigo");
      }
}
Oh…Finally I will be able to the book the Flight Ticket
public static void main(String[] args) {
      MakeMyTrip makeMyTrip = new MakeMyTrip();
      makeMyTrip.bookTicket();
      System.out.println("-------------------");
      GoIBiBo goIBiBo = new GoIBiBo();
      goIBiBo.bookTicket();
}
Output:
Welcome to www.makemytrip.com !!!
Select Source/Destination/Date
Searching Jet Airways/Air India/Kingfisher/Indigo
Current Offer is Buy one Ticket Get Another Free !!!
You have selected the below Ticket!!
Payment Recieved !! Ticket Confimed.
-------------------
Welcome to www.goibibo.com !!!
Select Source/Destination/Date
Searching Sahara/Air India/Jet Lite/Go Air/SpiceJet/Jet Airways/Indigo
Current Offer is Rs 200 off on one way 400 on return !!!
You have selected the below Ticket!!
Payment Recieved !! Ticket Confimed.
Getting Hooked with the Template
Hook is a method that is declared in abstract class, but only given empty or default implementation. This gives the subclasses the flexibility  to modify or hook into the algorithm at various points, if they wish. Subclasses are free to ignore the hook method if not required. 

Bigger Question here is when to use abstract method and when to use hooks?

Use abstract methods when your subclass must provide the implementation. Choose hook when it is optional for subclasses to implement it.
Let us understand Hooks inTemplate Design Pattern with a simple diagram below:
We will see how we can Hook in various features in our Daily Morning Walk.

We have placed two Hooks in our Morning Walk, one is to for Music lovers and other is for people who have house hold resposibilites as well. But let me tell you these are not mandatory. We can still enjoy our morning walk without any of these.
Let us know enhance our Flight Booking Example with some Hooks:
Here we have given a hook complimentaryMeal () which returns false by default  i.e. the no free meals will be served on the flight. But if a website prefers, it has all the right s to feed it’s hungry passengers for free.

public abstract class AirTicketBookingTemplate {
      public final void bookTicket() {
            //All the previous code here
            if(complimentaryMeal()){
                  chooseYourMeal();
            }
            payment();
      }
     
      abstract void chooseYourMeal();
      boolean complimentaryMeal(){
            return false;
      }
}

public class GoIBiBo extends AirTicketBookingTemplate{
      boolean complimentaryMeal() {
// This can also be based on Off Season or some Statistical Data to more profit
            return true;
      }    
      void chooseYourMeal() {
            System.out.println("Kindly Select the Complimentary Meal");
      }
}

Output:
All the lines are same as above only the highlighted part is different
Kindly Select the Complimentary Meal
Payment Recieved !! Ticket Confimed.

Hollywood Priciple:

The Template Method pattern makes use of the Hollywood Principle: Don't call us, we'll call you.  We will cover this topic in some other post.

When to Use Template Pattern?

 

·   When behavior of an algorithm can vary, you let sub classes implement the behavior through overriding
·       You want to avoid code duplication, implementing variations of the algorithm in sub classes
·         You want to control the point that subclassing is allowed.