a blog about nothing

LeetCode 1570. Dot Product of Two Sparse Vectors


My solution in JavaScript:

/**
 * @param {number[]} nums
 * @return {SparseVector}
 */
 var  SparseVector   = function (nums ) {
     const  x   = new  Map ()
     for  ( let  i   =   0 ; i   <  nums .length ; i  ++ ) {
         if  (nums [i ]  !=   0 ) {
            x .set (i , nums [i ])
        }
    }
     this.map   =  x
     this.length   =  nums .length
     return this
};


// Return the dotProduct of two sparse vectors
/**
 * @param {SparseVector} vec
 * @return {number}
 */
SparseVector .prototype .dotProduct   = function (vec ) {
     let  ans   =   0 ;

     for  ( let  i   =   0 ; i   <  vec .length ; i  ++ ) {
         if  (vec .map .has (i )  && this.map .has (i )) {
            ans   +=  vec .map .get (i )  * this.map .get (i )
        }
    }

     return  ans
};

// Your SparseVector object will be instantiated and called as such:
// let v1 = new SparseVector(nums1);
// let v2 = new SparseVector(nums2);
// let ans = v1.dotProduct(v2);
Read more ⟶

Kubernetes not passing full path to Nodejs


I spent hours troubleshooting why url path was getting stripped from requests in our Nodejs/Expressjs based app. The reason was this line in Kubernetes’ Ingress:

nginx.ingress.kubernetes.io/rewrite-target : /

Removing it fixed the issue. Check Kubernetes documentation

for more details.

Read more ⟶

Ask HN: Those making $500/month on side projects in 2021 – Show and tell


I love these kind of posts. Here are some interesting ideas for side-gig:

  1. Books. There are quite a few books there, books for babies, books about iOS dev etc.
  2. Mining Cryptocurrency. This comment got a lot of attention.
  3. Apps. Too many but was glad to see Mac apps generating decent income.
  4. Music. Decent income from YouTube content ID payments according to this comment.
  5. DIY biologist. Seems fun.
  6. A lot of SaaS or content sites.
  7. Flipping items from thrift stores on eBay.
Read more ⟶

ROI when using your primary residence as rental too


Calculating rough ROI on rentals is easy:

For example, let’s say one buys $500,000 single family home and rent it out for $3000 per month. Since it is investment property, they will need to make at least 20% down payment. On $400,000 loan, their monthly payment would be about $2750 at 3.25% interest rate, with $10,000 in property taxes per year and $2000 yearly insurance.

($36,000 - $33,000) / $100,000 = 0.03 or 3% return.

Read more ⟶

Ask HN: Software Engineer hitting 40: what's next?


Recent thread on Hacker News, https://news.ycombinator.com/item?id=29360119, was very interesting for me especially since I turned 40 this year.

Programming is something I enjoy and pretty good at it. I’m still not at the top of salary range for programmers but this is a tough question. I can get into FAANG but there is still a ceiling of how much one can earn as a software engineer.

This comment

says it best:

Read more ⟶

Hotel California


Hotel California is such a beautiful song. And it’s deep meaning can apply to pretty much any situation. I have been especially thinking of last line, “You can checkout anytime you like, but you can never leave.”

A lot of people think this song is about about drugs and Hollywood life that is hard to leave. But it can apply to anything. One can never leave their corporate life, they are stuck there forever because they got bills, family, and fear of going on their own. So they can mentally checkout anytime they like, but they can never leave.

Read more ⟶

Leetcode 92: Reverse Linked List II


Here is my leetcode solution in JavaScript:

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} left
 * @param {number} right
 * @return {ListNode}
 */
var reverseBetween = function(head, left, right) {
    let currPos = 1;
    let currNode = head;
    let startNode = head;
    let endNode = null;

    while(currPos < left) {
        startNode = currNode;
        currNode = currNode.next;
        currPos++;
    }

    let newList = null;
    let tail = currNode;

    while (currPos <= right) {
        const next = currNode.next;
        currNode.next = newList;
        newList = currNode;
        currNode = next;
        currPos++;
    }

    startNode.next = newList;
    tail.next = currNode;

    if (left > 1) {
        return head;
    }

    return newList;


};

Link to problem.

Read more ⟶

Ayden & Simba go to the Moon


Ayden and Simba were playing when they saw the moon. Ayden wanted to go to moon but didn’t know how. Then Simba remembered their friend Rocky the Red Rocket can take them to the moon. They went to Rocky’s house but he was not there. Simba said let me find him because he can find anyone by sniffing their smells. Simba sniffed and sniffed and found Rocky swimming in the pool. Once upon a time, there was a little boy named Ayden and he had a little dog called Simba. One day Aydne said to Simba, he lute’s go to moon. Since said that is an excellent idea. So Ayden and Simba went to their friend, Rock the red rocket’s house. They knocked on the door but no one answered. Simba sniffed and sniff and found Rocky at the pool. “Hey Rocky, how are you?’ asked Ayden. “I am good fellas, what are you guys up to” replied Rocky “We really really want to go to the moon, when you go to moon next time, can you please take us with you?” Ayden asked politely. Rocky said, oh guess what, I am going to moon right now. Let’s go now, if you can.” Simba nd Ayden got excited and they jumped in the Rocky. 3, 2, 1, Blast off!!! Rocky went into space and then landed on the moon. Moon was so beautiful, Ayden and Simba got out and started to play on the moon. It was very bouncy and it was red. And it smelled like a cheese. So Simba licked the moon’s surface and said moon tastes like cheese too. Ayden took a small bite of moon and guess what, moon is indeed made out of cheese. Simba and Ayden ate a lot of moon. They got so full. Rocky called them and said it is time to go back home. Rocky took them back home and Ayden and Simba thanked Rocky. And then took a nice big nap!

Read more ⟶

Blue Bus and Yummy Apples


One day, Blue Bus wanted to eat yummy yummy apples. He looked in the fridge but there were no of apples. He went to Target to buy apples. But Target was out of apples too. Then Blue Bus went to Red Bus but Red Bus was out of apples too. She had just eaten the last apple Blue Bus then went to Green Bus’s home. Green Bus was out of apples too. Blue Bus then went to Yellow Bus. Yellow Bus had just got back home from his work. Blue Bus asked if he had any apples but Yellow Bus was out of apples too. But Yellow Bus had just dropped Ayden at his home and Ayden had a big bag of apples. Blue Bus finally went to Ayden’s home. He asked if Ayden had any apples. Ayden said, “yes I do, right here in my pockets”. Then Ayden gave one apple to Blue Bus. Then all the buses came, Ayden shared his apples with everyone and they all ate apples together.

Read more ⟶

Broken Dreams/Bheegi Yadein by Junoon


As I turn back, my eyes dampen

When I realized my incomplete life

My life became clear to me

Broken promises

Deserted dreams

Broken promises

Seek time's tender shade

Yesterday too, was in ruins

Now is deserted as well

Life asks for a moment of support

Damp memories

Won't let me sleep due to grief

Damp memories

Won't let me live.

By Junoon

Read more ⟶