Category Archives: Blog

Decimal numbers to other integer base

A decimal number can be easily converted to any other integer using the method of repeated division.

Repeated Division

  • Divide the decimal number by the desired base. Write down the integer quotient and keep the remainder.
  • Convert the remainder to its equivalent in the new base (0-9 for bases 2-10, then A-F, etc. for higher bases).
  • Repeat steps 1 and 2 with the quotient, treating it as a new decimal number. Stop when the quotient becomes 0.
  • Read the remainders in reverse order. This will be your number in the new base.

Example1: Convert 255 to base 8 (octal).

  • 255 ÷ 8 = 31, remainder 7
  • 31 ÷ 8 = 3, remainder 7
  • 3 ÷ 8 = 0, remainder 3

Therefore, 255 in octal is 377.

Example2: Convert 255 to hexadecimal.

  • 255 ÷ 16 = 15, remainder 15 (F)
  • 15 ÷ 16 = 0, remainder 15 (F)

Therefore, 255 in hexadecimal is FF.

Python Global Interpreter Lock (GIL)

Some notes on Python’s GIL:

  1. It is basically a mechanism in the CPython interpreter (the most common Python implementation) that ensures only one thread can execute Python bytecode at a time.
  2. The GIL prevents multiple threads from modifying reference counts at the same time, which could lead to memory corruption.
  3. This limits the performance gains you can achieve with multithreading for CPU-intensive tasks.
  4. But threads often spend time waiting for I/O operations (like network requests or file access), which can allow other threads to run even with the GIL. So, multithreading can still be beneficial for I/O-bound tasks.
  5. If you need true parallelism for CPU-bound tasks, use the multiprocessing module to create multiple processes, each with its own interpreter and GIL.
  6. Some libraries, like NumPy and Cython, release the GIL during certain operations, allowing better performance for multithreaded code.
  7. Alternative Python implementations like Jython and IronPython don’t have a GIL, but they have their own limitations and trade-offs.

Numpy Broadcasting

Broadcasting is a powerful feature in NumPy that allows you to perform arithmetic operations on arrays of different shapes. It essentially stretches the smaller array to match the dimensions of the larger array, enabling element-wise operations. This avoids the need for explicit looping and makes the code concise and efficient.

Let’s study it using some examples:

Example 1: Adding a scalar to a 2D array

Python

import numpy as np

scalar = 5
array = np.array([[1, 2, 3], [4, 5, 6]])

# Broadcasting adds the scalar to each element of the array
result = scalar + array
print(result)
Output:
[[6 7 8]
 [9 10 11]

In this example, the scalar 5 is added to each element of the 2D array array. Broadcasting automatically stretches the scalar to match the shape of the array, resulting in the output array.

Example 2: Multiplying a 1D array with a 2D array

vector = np.array([1, 2, 3])
array = np.array([[1, 2, 3], [4, 5, 6]])

# Broadcasting multiplies the vector element-wise with each row of the array
result = vector * array
print(result)
Output:
[[1 2 3]
 [4 10 18]]

In this example, the 1D array vector is element-wise multiplied with each row of the 2D array array. Broadcasting automatically stretches the 1D array to match the number of columns in the 2D array, resulting in the output array.

Example 3: Adding two arrays of different shapes

array1 = np.array([[1, 2, 3]])  # 1D array
array2 = np.array([[4], [5], [6]])  # 2D array

# Broadcasting stretches the 1D array to match the 2D array shape
result = array1 + array2
print(result)
Output:

[[5 6 7]
 [5 6 7]
 [5 6 7]]

In this example, the 1D array array1 is added to the 2D array array2. Broadcasting stretches the 1D array to match the shape of the 2D array, resulting in the output array.

Dot vs Element-wise multiplication

Dot Multiplication

Properties

  • It is performed via numpy.dot or using the @ operator.
  • It represents the traditional matrix multiplication.
  • Involves summing the products of corresponding elements in rows and columns.
  • Output shape depends on the input shapes:
  • For matrices A (m x n) and B (n x p), the output is (m x p).
  • For vectors, it produces a scalar (single value).

Example

import numpy as np
a = np.array([[1, 2], [3, 4]]) #  [[1 2]
                              #   [3 4]]

b = np.array([[5, 6], [7, 8]]) #  [[5 6]
                              #   [7 8]]

result = np.dot(a, b)  # Or result = a @ b
print(result)  # Output: [[19 22]
             #           [43 50]]

Element-wise multiplication

Properties

  • It is performed using numpy.multiply or using the * operator.
  • It implies multiplying corresponding elements of arrays directly.
  • Output shape matches the input shapes (if compatible).
  • Broadcasting rules apply for different-shaped arrays.

Example

a = np.array([1, 2, 3])
b = np.array([4, 5, 6]) 
result = np.multiply(a, b) # Or result = a * b
print(result) # Output: [ 4 10 18] 

Pixel Buds Pro Review

In the past I have used AirPods (not Pro) 2nd generation for almost 3 years and I was very happy with it. They were light weight, fit my ears perfectly and no doubt sound quality was great. Basically I had no complaints. I have also used Bose QuietComfort 35 which are pretty good too but their range is very bad.

But I have been using a Pixel phone for more than 2 years so I couldn’t reap and use many of its features that were only available in the Apple ecosystem. Thus I wanted to try something new which resonated well and provided more goodies in an Android environment.

So when I saw Google launching Pixel Buds Pro, I knew I had to try it. The specs and all the features looked great during the launch but I wanted to try it for real before sharing my thoughts. And I think I am ready to provide honest and absolutely unbiased review after using it for almost 2 weeks:

  1. Pixel Buds Pro are not gigantic. When I saw these earbuds during the launch, my first impression was they looked large but when I actually held them in hands their size was just perfect.

  2. Speaking of form factor, these earbuds are extremely lightweight, so much so that I often don’t even feel that I am wearing those while using them.

  3. The thing which I have been completely blown away is its touch controls which work seamlessly and provide complete control to do almost anything without pressing any button:
    • You can easily control the volume directly from the Pixel Buds Pro.
    • Needless to say but you can pause and play anytime.
    • You can skip to the next track.
    • You can go back to the previous track.
    • You can activate noise cancellation (ANC).
    • You can enable transparency mode.
    • And you can still use Google Assistant on the fly.

Using all the touch controls is very intuitive and requires no learning curve. The best part is that you can configure touch controls and customize touch & hold such that you are able to perform all of the above actions without having to pick one over the other.

  1. I was also very impressed with the ANC quality overall. My previous headphones always had ANC but I didn’t use it often. But with Pixel Buds Pro, I am using ANC more than I have used it in the past. Partly because it is so easy to activate/deactivate it and also because they do a pretty good job weeding out the noise.

  2. The Multipoint feature also works pretty reliably and I have been using it very effectively while switching between my Pixel phone and MacBook Pro. I no longer have to disable and enable Bluetooth or use any button to switch between the devices like I had to with my previous headphones.

  3. One simple and common feature which is worth mentioning is in-ear detection. Not only did it work as expected with my Pixel phone but it also worked flawlessly while using YouTube and YouTube Music on MacBook Pro.

  4. I didn’t experience any connectivity or latency issues whatsoever. As a matter of fact it has pretty good range and I am able to use them even when my phone is in some other room which my Bose headphones were not good at.

  5. Automatic updates are enabled by default and it has been working without any friction or needing my attention. I also tried to manually update the firmware once through the app and it again went pretty smoothly.

  6. The shape and texture of its case are so smooth that it draws your attention and will make you hold it more frequently just to feel its surface and perhaps play it like fidget.

  7. The earbuds are also easy to put into the case and very easy to take out as well. Also they sit well into the case and don’t fall out with the lid open and case being upside down.

  8. I was also able to wirelessly charge the case using my Pixel phone so that is a good feature to have if you don’t have the charging cable.

  9. Some of the features which I haven’t tried yet are:
    • Finding the device using the location or ringing the device.
    • Audio switch which lets you automatically switch between compatible Android devices.

  10. Also, I haven’t yet tried these earbuds while running or doing any physical activity but will update this post once I have some data to share.

Now these were the things which I really loved about my Pixel Buds Pro but was there anything which I didn’t like? Actually none to be honest but if I had to still pick then I would say that:

  1. It took me a while to learn how to correctly put and fit them into ears. This involved learning how to correctly insert the earbuds into the ears and then rotating it. But once I mastered the technique there was no looking back.

  2. I also have a feature request for Pixel Buds Pro which is to be able to mute/unmute the phone calls and video meetings using some touch control combination.

Market vs Timing

There are two very famous quotes in investing circles:

  1. You cannot time the market.
  2. Time in the market > Timing the market.

Now I would also like to add third rule to the above list:

  1. Time of the market matters.

In my opinion, time of the market is slightly different than timing the market and time in the market. By time of the market I mean the ability to see where the market is currently i.e bull market, top of the market, bubble, bear market, recession or “near” bottom. Being able to have this skill will play a very important role in deciding how long you can stay in the market and what your returns will be.

So although it is difficult to time the market but you want to be experienced enough to be able to see the time of the market especially if the prices have gone bonkers and if you are top of the pyramid or perhaps there is extreme fear in the market and things are trading at bargain prices. Any investor who experienced the dot-com crash should have been able to call out the Covid Stock / SPAC / Crypto madness.

Timing the market doesn’t necessarily mean finding the bottom. But you definitely don’t want to buy at the top of the bubble and then see your asset fall by 30-40% or even more than 50%. It is one thing to say that you are comfortable seeing your portfolio can experience 10-20-30% drawdown and it is altogether a different thing to experience it in reality. Same goes with the bubbles, bear market and recession. True lessons are learned not by reading about it but by experiencing it first hand.

In a bull market, prices usually go up but in a bubble burst, bear markets or recession it may take many years to recover and in some cases it may never recover. For e.g, it took almost 10 years for AMZN to get back to its dot-com price whereas some stocks like SUN (Sun Microsystems) were never able to recover the dot-com price. Thus it would have been impossible or extremely difficult for shareholders to hold either AMZN or SUN from 2001 to 2009 if they bought it at the top of the bubble.

And this was true even for S&P 500 where it took 7 years for it to go back to go back to dot-com price. It then fell back again during the 2007-2009 recession and then took another 5 years to go back to dot-com highs.

So if you were not able to see the time of the market (in this case bubble of the market) then your time in the market would not have mattered for almost 10+ years even if you were holding SPY.

Quick thoughts on M1 Pro

Note: Don’t use this review to decide if you should buy the M1 Pro or not. Regardless of my thoughts, it is a great product and at par with previous MacBook Pros (MBPs) or might be even better.

Some background, I recently upgraded to M1 Pro from my 2019 MacBook Pro as the touch bar stopped working as shown below:

So what is my first impression of the M1 machine?

To begin with, the 16 inch space gray model looked absolutely gorgeous the moment I unboxed it. Few other things which caught my immediate attention: the keyboard is a breath of fresh air compared to previous models, loved the giant Esc key and the best part, it doesn’t have the touch bar. Also, the display and notch are beautiful, especially the few extra inches of screen real estate which this model provides.

However there are certain things about the new M1 pro which are worth mentioning:

  1. It is quite thick and on a bulkier side. So if you are used to using light and thin MBPs then this might take some time for you to get used to.
  2. It only has 3 USB-C ports as opposed to 4 USB-C ports. I actually found 4 USB-C ports to be very handy and used them all. But with one port now gone, I would have to probably buy a new connector to extend my USB ports. Not a big deal but kinda annoying as you have to always carry that extra connector.
  3. On the other hand it has an HDMI port unlike previous models. However, by now all the good/new monitors have started supporting direct USB-C connection for the display. Also most users now have the HDMI to USB-C port connector. So perhaps the HDMI port was not needed and I bet as the form factor of the M series MBP will improve, this HDMI port would again get replaced by the missing USB-C port.
  4. And yes, it also has a USB-C to MagSafe connector to charge the laptop which is good but to be honest I have got used to charging via USB-C and find it to be more convenient.
  5. Coming to the performance, my workloads are pretty straightforward so I don’t think I have a valid payload to conduct any benchmarking tests. Also, I haven’t experienced any slowness or hang with this new M1 Pro so it seems to have performed very well so far.

To summarize, it is a great laptop and will not disappoint you but it might take a while to get accustomed to its new form factor.

What matters in life

Peace
Don’t trade your peace of mind for anything else. Without peace of mind you won’t scale.

Focus
Have a razor focused presence of mind. Your attention span is your greatest skill.

Time
Time is your only currency aka YOLO so make every second count.

Learn
Get out of your comfort zone and learn something new everyday.

Build
You learn more when you build something. And it is also the best way to earn more.

Kids
Spend time with your children, help them become more curious and teach them to be kind.

Karma
Go above and beyond to help others and life will help you to get all the luck and timing you need.

Health
Importance of health is realized when it’s gone. No health, no wealth as simple as that. Also, your health is mostly what you eat.

Sleep
Sleep is the best medicine and also the best reset machine so sleep as much as you can.

Cook
Cooking and eating a healthy home cooked meal daily is an underrated skill. Learn to cook yourself and also teach it to your kids.

Read
Books are your best friends, best teachers and best degrees so read books everyday.

Write
Write something everyday.

Hustle
Work insanely hard while moving from one failure to another without losing your heart.

Workout
Workout not only improves your health but it also improves your attention so just do it.

Urgency
Great execution is all about showing and acting with urgency.

No sugar
It is an addiction that not only hampers your health but your productivity too so just don’t do it.

No social
Don’t waste your time on social media counting likes, views or reading comments, gossip and fake news.

No anger
Your anger only destroys you. Just forgive and forget.

No anxiety
Do your part by doing the right thing and giving your best but don’t be anxious about the results.

No shortcuts
Just like there is no free lunch, there are no shortcuts in life. What comes easy, goes easy.

No distractions
Don’t get distracted by your temptations, failures and naysayers.

No desperation
Don’t be desperate in your deals but also don’t play zero sum games. Let others win too.

No comparisons
Keep your head down, compete with yourself and become a better person everyday.

No disappointments
No matter what happens, don’t get disappointed and lose your will to fight.

My favorite books of 2021

I want to end the year by sharing my favorite and recommended books of 2021:

  1. Liftoff: Elon Musk and the Desperate Early Days That Launched SpaceX by Eric Berger
  2. The Cult of We by Eliot Brown
  3. Play Nice But Win by Michael S. Dell and James Kaplan
  4. The Code Breaker – Jennifer Doudna, Gene Editing, and the Future of the Human Race by Walter Isaacson
  5. The Minimalist Entrepreneur by Sahil Lavingia

As always, you can find my entire reading list here whereas a subset of my all time favorite and recommended books can be found here.

Life equations

I recently heard a great question, what mental model/framework do people usually use while choosing between convenience and frugality? It is a simple question yet it makes you ask many other questions about yourself. For instance, what is more important to you and in what order? Which things can you or cannot compromise?

So after I heard that question, I wanted to do some self-reflection and revisit my weaknesses, strengths, priorities and values. It actually didn’t take much time for me to sort my resources on what I call the number scale of life and then come up with some life equations.

Disclaimer: I have two very active kids so most of my rules are centered around them and how it impacts their day. In other words, it may not necessarily apply to you so please take my rules with a grain of salt. With that being said, here are my current set life equations (not saying that they are correct but just sharing what I currently follow):

Time > Money

E.G: If there is a job which will take me an entire day but if a contractor can finish it in an hour then I would rather hire the contractor (provided his hourly rate is not astronomical compared to my hourly rate). And then utilize my extra time on things which I enjoy and which will make my kids less cranky.

Happiness > Money

E.G: After having kids, I don’t mind paying extra to make my travel experience good, safe and less tiring for my kids. But if I didn’t have kids then I would probably go absolutely frugal on things like travel since I can always utilize my time listening to audiobooks or reading books while traveling.

Peace > Money

E.G: I try to avoid FOMO while buying assets. I would prefer to sleep peacefully at night rather than worrying how much more I would lose the next day. So I only invest in what I understand, when there is a dip and when I am not paying a premium price.

Health > Peace > Time > Money

If you are not healthy then nothing else matters. All your time and money would be of no use if you are not healthy. So eat healthy, stay fit and sleep well. Also if you are not at peace then you would just not be able to give your best and utilize what you have. So avoid things, jobs and relationships which steal away your health and peace of mind at the cost of time and money.

Happiness = Health + Help + Hustle

Without health, you cannot achieve anything else so you absolutely need that. After health, you need to hustle to be able to utilize your time and available resources. You also need to help others to learn compassion and have a little bit of luck. This luck will help your hard work succeed. So once you have health, efforts, luck, compassion and success, nothing can stop you from being happy.

But what about money?

Well money is just a byproduct of your hustle to happiness.