Wednesday, June 7, 2017

Dependency Inversion Principle

Dependency Inversion Principle basically says that when a class A depends on class B, do not instantiate class B in class A. Instead create a interface I that class B can implement and make class A depend on the interface I. This way we can plug in any other classes that implement from interface I in class A.

Basically the code should depend upon abstractions. By depending upon abstractions, we are decoupling implementations from each other.

Wednesday, September 17, 2014

Apparantly :P

http://myqc.wordpress.com/2012/08/13/amazon-interview-questions-cheatsheet/

Wednesday, July 30, 2014

Matrix paths from start to end traversing unoccupied cells

public class CoOrd
{
int X;
int Y;
public CoOrd(int x, int y)
{
X = x;
Y = y;
}
}

public static ArrayList getAllPaths(int[][] matrix, CoOrd start, CoOrd end)
{
ArrayList paths = new ArrayList();
getPaths(matrix, start, end, paths);
return paths; //assumings callers check the return ArrayList length
}

public static void getPaths(int[][] matrix, CoOrd start, CoOrd end, ArrayList paths)
{
if(start.X == end.X && start.Y == end.Y) //return when start meets end
{
return;
}
if(matrix[Start.X, Start.Y] == 0) //assuming 0 is an unoccupied cell and rest are occupied
{
paths.add(start);
}
else
{
/recurse right
CoOrd X1point = new CoOrd(start.X+1,start.Y);
getPaths(matrix, X1point, end, paths);

//recurse up
CoOrd Y1point = new CoOrd(start.X,start.Y+1);
getPaths(matrix, Y1point, end, paths);
}
return;
}

Adding 3 linked lists in the correct order and returning result linked list

#define E_INVALID_PARAMETER -1

int getNumber(node* root)
{
if(root == NULL)
{
return E_INVALID_PARAMETER;
}

int ret = 0;
node* temp = root;
while(temp)
{
int data = temp->data;
//checks to find data is valid
ret = ret*10 + data;
temp = temp->next;
}
return ret;
}

node * createLL(int num)
{
node* head = null;
node* prev = null;

while(num)
{
int data = num % 10;
head = (node *)malloc(sizeof(node));
if(head == NULL)
{
return NULL;
}
head->data = data;
head->next = prev;
prev = head;
num = num/10;
}

return head;
}

node * sumList (node* a, node *b, node* c)
{
if(a == NULL || b == NULL || c == NULL)
{
return NULL;
}
int aNum = 0;
int bNum = 0;
int cNum = 0;

aNum = getNumber(a);
bNum = getNumber(b);
cNum = getNumber(c);

if(a == E_INVALID_PARAMETER || b == E_INVALID_PARAMETER || c == E_INVALID_PARAMETER)
{
return NULL;
}

return createLL(aNum + bNum + cNum);
}

Wednesday, June 12, 2013

Insomnia

When thoughts suffocate your brain,
Brain unleashes the monster of imagination,
Monster spits the fire on dreams,
Dreams disclose their counterparts: nightmares,
nightmares spoil your sleep...

Sunday, June 9, 2013

Can't ask more from this weekend

Summer to Seattle is like Saturday of a week. The caffeinated blood of Seattlers craves for the Vitamin D from the Great Apollo. Some people make dedicated plans for Summer through out the year. Prices inflate, pockets deflate.

As you all know, my plans are sporadic. It all started off with an email thread to go to Northern Cascades. As usual, I was excited. No replies, only pages (Amazon folks will understand this). I called every one Friday to finalize the plan. Some didn't pick up and those who did wanted me to confirm from the one who didn't :(. I wanted to break this deadlock. Had it been code, I would have used mutex. But this is more complicated than that. I came who with a hope, the I will be showered with call from those who missed. When the clock ticked 12:00AM, I lost hope.

I called my colleague who invited me to join him for the active volcano trip. I was not interested because of the plans i made with other friends. Mt. Rainier!!! I am live 100 miles away from, but never got chance to go there. I was scared that one day, its going to explode and consume only me and ignorant folks like me. He was more than happy to welcome me, but time we are supposed to start had to be digested as a sour pill. 8:00 AM in the morning. I had to say YES!!! camouflaging the laziness in me.

Woke up at 7:15 and was ready by 7:55. Waiting for them to call. 8:30, no call. I didn't call them as i felt it will be like pressurizing them. Finally my Nokia sings my favorite ring tone at 9:30. He comes with a car loaded with 4 people. i scooped in with greeting other 3 with "I am Pavan" individually. I know, it sucks addressing your self to every others individually, but we are surrounded with these social etiquette which is difficult to dodge.

Yanni and Pink Floyd dominated air in the car. Finally reached the great Rainier. Make sure you stop at the first parking lot and take some pictures at the vista point there. Do not even think about using the restroom over there. Great view of the Rainier with river flowing through your legs waters your eyes with happiness. It was paradise. Trust me.

Then we did a small trek at Narada falls on a dead river with small streams of river trying to sneak away without notice. Then the final destination was Paradise point. The highest point that can be reached by a automobile. Enjoyed the scenery and headed back, but thought we should stop at one more visitor point called the reflection lake. It was frozen, but when the water melts, one can see Mt. Rainier's reflection on it. I closed my eyes, imagined it and rolled back to our car.

Feasting eyes, doesn't fill your stomach. So, had to stop at "Naan and curry". Visitors to Seattle, make sure you go to this place. Non veterinarians, Chicken Nihari is your dish. After stuffing esophagus, it was time for some kaju kulfi. It was the best kulfi i ever had.

Back to home. Thoughts of sleep conquered my thoughts. But friends gave a surprise visit. They wanted me to come with them to Seattle and chill out. 7 of us, rolled ourself to Kells on bell town in downtown. Stick of humans filled my nose as soon as i entered. Though the night is going to be a disaster. It was too hot inside and we all filled our water glasses with our sweat. Then comes the fun part. Live music!!! Couldn't ask for more. Stayed there till 2 AM. Chatted outside till 3 AM. Headed back to house and chatted there for 2 hours and slept.

Soo much happened in one day. More has happened, but i am bored of typing. Please wish me to have weekends like this forever :)

Wednesday, May 29, 2013

Unfortunate planning that lead to fortunate destination

Planning... not my cup of tea. Somehow, my plans for trips never work out. It all started off with a plan to drive to Yellowstone National Park for the Memorial Day long weekend. I thought I grew up since this plan was scripted by me, one and half months prior to the weekend. My parents should be soo proud of me. I started bragging about the long drive, camping , rafting, trekking, all kinds of -ings that you can think of. Invited loads of people. Started an email thread.

As usual, some who said will join me raised the white flag in between, and planned some other trips. Though was disappointed, thought "Everything happens for a reason" (The saying that keeps us moving forward). Now I realize, they made a wise choice. You will understand why in a bit.

Two weeks before the long weekend. Enthusiasts like myself, met at another enthusiast's place and started sketching out the plan in much more granular fashion. Then comes the realization "YSNP is too far to drive". My heart shattered after listening to that. I was dreaming about this road trip from a long time. The friend who raised this point got an unanimous support. Next option was to book the bloody flights. I hate flight travel, when we can go to the same place driving. I surrendered to their idea, since my main motto was to have fun. And as I have said earlier, the flight prices were too costly, even for software engineers to afford. PLAN CANCELLED.

I really appreciate the words of wisdom from another friend who sprouted with the idea to make a road trip to Crater Lake. MUHAHAHA. ROAD TRIP :). My soul got a sudden dose of caffeine, after those words. I  raised my two hands to show my support. Exercise started. Started a new thread and sent invitations. People pitched in ideas. Ohh, we planned loads of fun stuff. Weather sites supported us too.

Three days to the ride. Sites predicting weather again proved to be wrong. The precipitation levels are above 70%. Very disappointing news to digest. EPIC FAIL. Plans have to change and we have to make sure that no one else plans their long weekend based on us. So, this time NO EMAIL THREAD. The default option was a short road trip to Lake Chalan. 

Monday, June 4, 2012

JAVA: Generics

Courtesy : http://java.sun.com/docs/books/tutorial/java/generics

public class Box {

    private T t; // T stands for "Type"          

    public void add(T t) {
        this.t = t;
    }

    public T get() {
        return t;
    }
}

During compilation, all generic information will be removed entirely, leaving only Box.class on the filesystem.

A declaration of Box, for example, would generate an error on the second occurrence of T, but Box, however, would be allowed.

The most commonly used type parameter names are:
  • E - Element (used extensively by the Java Collections Framework)
  • K - Key
  • N - Number
  • T - Type
  • V - Value
  • S,U,V etc. - 2nd, 3rd, 4th types

Static, when to use

Ever wondered when we see STATIC modifier in code, "what is it?". This article explains when to use it and beauty of it. A MUST go through for all who love to write aesthetic code.

http://www.codeproject.com/Articles/15269/Static-Keyword-Demystified

Summary: Declare methods or variables or properties as static when you think you don't need an object to access the corresponding. Static classes are different in different languages. In C# declaring a class to be static means that it contains only static members. So, recommendation is that write all generic and helper functions in a static class.

Friday, March 23, 2012

interview questions

Source: careercup

What happens when you type a URL into a browser?

1. Browser contacts DNS to resolve IP address
2.DNS replies back with the IP address of the site
3. Browser opens TCP connection to the server at port 80
4. Fetches index.html file from /home directory.!
5.Displays the content in browser
6.Stores the IP in DNS cache for future use.
7.When broswer closed, TCP conn is terminated..!!!

win7 usb/dvd download tool

win7 usb/dvd download tool is super sexy in making bootable dvd's and usb's. Awesome UI. Try it once and you will become a fan of it. Use the following link to download. http://www.microsoftstore.com/store/msstore/html/pbPage.Help_Win7_usbdvd_dwnTool. My next blog will be how to create a VHD and install win8 consumer preview on it. I am excited to finish that blog.

Friday, March 16, 2012

Some shortcuts

In cmd prompt u might have faced this issue many times. 1. You "cd" to a folder location. 2. Now you have to go to a folder location in different volume. 3. You "cd" to it. 4. Now, you have to go back to the previous folder. If I have to deal with these situations, I prefer using multiple cmd prompts. But that may turn out to be a hassle. This trick may help you out in those situations. >pushd . //pushes the current directory location into a stack. >popd //takes you back to that folder that is on the top of the stack Hope this helps. :)

SSD vs HDD

http://www.bing.com/videos/search?q=difference+between+ssd+and+hdd&view=detail&mid=DC8212ACD004D6E8054EDC8212ACD004D6E8054E&first=0 Very good read about difference between SSD and a HDD

MBR vs GPT

http://www.tomshardware.com/forum/233291-32-what-difference Good read about the differences between Master Boot Record and GUID Partition Table

Monday, December 5, 2011

chopping off last word in a sentance: perl

$cn=~ s/\s*\b\Q$word\E\b(?!.*\b\Q$word\E\b)//s; will do

sqlite multiple statements in a single query

Using sqlite, for inserting in specific columns it is insert into 'test1' () select ('') as '' union select ('') union select ('');

Wednesday, November 23, 2011

web:apache permissions

Apache 2.0 changed the default DocumentRoot permissions to be very restrictive. While I can’t argue this is a better security paradigm than less restrictive default permissions, in the real world upgrading a server with 300+ domains, it can be a pain to script permissions changes in all of the config files. AllowOverride None Order Deny,Allow Deny from all Change the default permissions to be less restrictive with this instead: AllowOverride None Order Deny,Allow courtesy: http://damonparker.org/blog/2007/01/06/apache-error-client-denied-by-server-configuration/ I donot take the ownership of this content

Saturday, March 5, 2011

Differences betn Java and C++

http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html