Wednesday, January 4, 2017

Making a vagrant box for RHEL

One of the assignments at work is getting me into creating a vagrant box for RHEL, as I would want to create and destroy RHEL VMs multiple times in a day. 
This blog summarizes the steps to create a vagrant box for RHEL. The software I have are 

1) Oracle VM Virtual Box
2) An ISO file with RHEL 7 setup rhel-server-7.0-x86_64-dvd.iso

Let's begin by creating a baseline VM 

1) New Machine -> Give a Name, Type is Linux, Version is Red Hat 64 bit
2) Memory is fine at 1024 MB
3) Create a Virtual Hard Disk. I chose VDI as my hard disk type, Dynamically allocated size is better for me, and the size for HDD is set to 100 GB. 
4) Go ahead and mount the iso file to the VM. This can be done by selecting the machine settings -> Storage -> and mount the iso on the optical drive. 
5) Start the machine and select to install the RHEL O/S. Walkthrough the wizard and install the RHEL on the VM.  While installing the OS I also chose to create an additional user 'abhishek' on it.
6) Register with the subscription manager by using subscription-manager register
7) sudo visudo and comment the line "Defaults .requiretty"
8) Create a user called vagrant and set the password as vagrant. Commands to use are useradd vagrant. And passwd vagrant. 

Once done let's package this VM as a vagrant box 
1) vagrant package --base BaseRHEL 
2) vagrant box add test 

and now you have a vagrant box for the machine. Enjoy creating as many VMs as you want :). 

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!!!


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.

Wednesday, May 13, 2015

Why Database is not suitable for a Queue

There are many applications which use database as a queue in order to orchestrate a long running business process. While it is enticing and easy to do so here are a few reasons about why the developer should avoid doing it...

1) Work distribution : As the number of messages flowing through the system increases the work distribution has to be managed by using locks or by using a Z axis scaling i.e. partition the message table and let different processes handle it. It becomes difficult to manage the failure cases e.g. if the process responsible to manage a particular partition goes down how do I bring up another process to pick up that partition. This is a problem which can be easily solved by event driven queues with horizontal scaling. 
2) Database loads : As the messages passing through the system increase the load on the database starts increasing. This means that the database needs a scaling which is much more costly then scaling a queue bases solution. 
3) Deleting and archiving the queue related tables is expensive as they are indexed. 
4) Database has to be polled to see the pending work items while an event driven queue can simply call the worker process when a new message pops into the queue. 

So while it may be enticing and easy to use database to orchestrate queue related workflows one should refrain from taking this technical debt as it would be really hard to pay it back in the future...


Tuesday, November 19, 2013

My struggles with a Mac

For the first time in my life I am away from a PC. I recently got a Mac and I have my struggles going on now... To begin with there were a few usability issues like the trackpad tap not working as a click which were simple preferences tweak. Then came the big one 
1) The Eclipse installation on Mac was not picking the proxy from the Safari settings so I had to set them myself. That can be done by downloading the Pac file from the automatic configuration script URL and then setting the right proxy in the Eclipse Network Connection Preferences section.
2) My Lync for Mac is not working for some reason. This still needs to be figured out. I will update this section once I am able to sort that out. 
3) There is no Propose New Time functionality in the Outlook Calendar. (Sad :()
4) The Outlook Calendar in Mac shows 1 hour slot as big as 2 hours in my Outlook Calendar in Windows which I am used to. This can be changed by going to Organize Menu and playing with the Scale. 

There will be more and I will keep updating this blog post for the small tweaks :). 


Wednesday, September 25, 2013

Server Side Image Generation from SVG

With SVG gaining so much traction lately many people are using that as a de-facto rendering technology in HTML world. This allows you to create awesome graphs and charts to visualize data using libraries like d3. 

There's one little problem which keeps you awake though and that is the fact that sometimes there are requirements to send the same graphics in and email as a image or a pdf and that becomes impossible because of the fact that there are no headless webkits available on the server side to do the rendering and convert them to image. Faced with this problem I explored a few options. The path I chose is 

1) Use EnvJS as a server side DOM.
2) Using EnvJS create a Batik SVGDOM everytime you encounter a SVG Element. 
3) Use Rhino to host EnvJS (the server is a java server)
4) Use Batik to convert the Batik SVGDOM into an image.

And it works just fine.. 

Happy Coding!!


Thursday, September 13, 2012

ACS With Windows Azure Webrole

I always wanted to make the ACS work in an Azure webrole. Somehow I was not able to put a sample together.

Seems like someone else has done it for us Smile. Check for step by step guide on how would you deploy azure ACS authenticated webrole on Azure.