Monday, February 22, 2016

Configuring X11 Forwarding on CentOS to Mac

I have a linux machine on Azure which I am able to SSH into, however many applications needs to throw a UI on my mac and it is important to configure X11 Forwarding on the CentOS machine to make sure I can see that UI. 
I managed to make it work after googling stuff for around 2 hours. Here's a quick guide if you are in a similar situation. 
You need to do things on both your mac and your CentOS machine to make sure that the forwarding works. 

1) On your mac you need to install XQuartz. This is the daemon which would listen for the forwarded requests from your CentOS and render a UI on your mac. 
2) On your CentOS you need to edit /etc/ssh/sshd_config and add the following entries to it

  • AddressFamily inet #this entry ensures that SSH is not messed up over IPV6. My forwarding was not working till I made this entry. 
  • X11Forwarding  yes #this entry will ensure that the forwarding happens from CentOS. 
3) Next install a package called xauth on your CentOS machine. you can use yum to install it. 
  • yum install xauth 

4) restart the ssh daemon 
  • sudo service sshd restart
5) Install an app like xeyes to test if the X11 forwarding is working or not. 
  • yum install xeyes
6) logoff from the CentOS and login again using -X flag this time 
  • ssh -X user@host
7) Run xeyes and you should be able to see the eyes coming up on your mac screen :). 

Happy coding!!!

Abhishek 


Tuesday, January 5, 2016

Pitfalls of Object Oriented Programming

As I try to understand Javascript as a language one of the things which I need to unlearn is Object Oriented Programming. With Ecmascript 6 and tools like TypeScript from Microsoft, so far I have managed to write a lot of object oriented programs in Javascript which essentially is a functional language. 
So first thing which I need to do is unlearn OOPS. Here are a few pitfalls of OOPS : 

1) A Class is a collection of Data and Methods which operate on this data. As a programmer trying to learn OOPS this was very unintuitive, but once you start practicing OOPS, it becomes the obvious choice and all the apprehensions like why exactly should I keep my data definitions and  Functions together goes away. Going back to my learning days, I once again find it unintuitive. 

2) The way a function behaves in a class can be totally dependent on the state of the object which can be hidden from the consumer of the class. e.g. I can easily write a class which like 
public class Calci{
    private var toggle = false;
    public int Add(a,b){
        toggle = ! toggle;
        if(toggle) return a + b;
        return a - b;
    }
}
The behavior of method Add totally depends on a the state of the Calci object which is hidden from the consumer. So understanding what a method does in object oriented program can be tricky sometimes. Although this is an advantage when compared to Procedural language where the behavior of the function can be dictated by a global variable which is declared somewhere in a different file. But then I have visibility in the scope and if I try it hard I can figure it out. 

3) No Class Hierarchy is correct : No matter how much thought one gives into create a right class hierarchy. One does end up in a situation where the hierarchy is not correct. This is one of the major reasons for refactoring the code while developing projects. As the code size grows it becomes rather difficult to refactor as the change impacts all the ecosystem. 

4) You get a lot of rings and bells attached with any class which you choose to reuse. e.g. If I derive from a Car class I get the method Drive for free even though I may not want to drive an auto-drive car. 

As one learns javascript one should ensure that we don't fall back on the knowledge we acquired while learning OOPS and try to apply them in this new paradigm. Next up is to figure out what kind of inheritance is possible in javascript, how we can use it, and how it differs from classical inheritance of OOPS.