Tea

A picture of cups of tea
A cup of tea
Tea. Such a simple beverage. And I am not talking about the Chamomile Tea or Mint Tea or Lemon Tea or the Boba tea. I am talking about the tea you get in subcontinent especially in India. The tea that is made out of actual tea leaves, milk, ginger, and a bunch of optional spices. Yes, you got it. I am talking about the Masala Chai but also a lot more than that! At its simplest, it has only four ingredients - Milk, Water, Sugar, and Tea Leaves.

Tea is such an integral part of Indian culture and a lot of things make or break over tea. Friendships are forged, relationships discussed, marriages fixed, business deals finalized, gossip, and what not. Having tea in the middle of the day when the temperatures are soaring is not about the tea, but about a chat with a friend or if alone, just unwinding from whatever is bothering you at that time.

But in its simplicity lies the complexity. Even with just four ingredients, it is not easy to get it right. True that it is basically just boiling a cup of water, but still not everyone can get it right. In fact, I am a big fan of tea and can drink tea at any time of the day and any number of times. But till recently, I was not able to get it right. That tells you how much I love tea.

Even with just four ingredients, the quantity of ingredients added and the order they are added is very important. In quantity depends on how much tea is being made, but basically, you add one teaspoon of tea leaves to 1/2 cup of water and 1/2 cup of milk to make one cup of tea. Sugar is up to the individual's taste, but generally 1 teaspoon or less is what is recommended. Just recently I figured out the order as well and since then the tea has been heavenly.

I used to boil the tea leaves with the water thinking that the tea flavor and fragarence will steep in. But I was overcooking it and the tea was losing its taste. What you need to do is to bring the water to a hard boil and then add milk to it. Once milk is added, add the tea leaves at that time and stir the concoction and stir it well. You can add sugar anytime. When the final product is about to come to boil, that's when you add the crushed ginger and other spices. That's when the tea leaves and ginger release their flavor and make the tea, Tea.

Fix 404 errors in Laravel application authenication

Introduction

I am not a Laravel programmer by any stretch of imagination but I like to think that I am a pretty good engineer who can solve problems regardless of the situation. Recently I faced a situation where I was working with one of my clients on setting up a validated environment for their customers using a standard operating procedure (SOP). They had gotten the application developed from a third party vendor. Long story short, since their target market is highly regulated industry, they must have detailed and exhaustive documentation of all steps of setting up and tearing down of the computer systems.

It's not easy to write SOPs

There is a video where a father is asking his kids for some instructions to make a peanut butter and jelly sandwich. While for most of us making a peanut butter and jelly sandwich is highly intuitive and easy, for a person who doesn't know what is to be done, it can be stupefying. When we write instructions, we know a lot of things as we have already done the task successfully and assume that the reader is already aware of a lot of things that we know about and do not include those steps in our documentation.
Sometimes it is different. We miss some steps in our documentation and when someone else finds out and reports the gaps, we quickly make the change and do not update the documentation, hoping the problem will not recur. That exacerbates the actual problem. In case someone else has to reproduce the environment using those SOPs then they are basically stuck.
Therefore it is very important to have accurate and correct documentation updated. Admittedly, it is tedious and cumbersome, but in the long run it definitely is the right thing to do.

Laravel and Apache server

I had a Laravel application that was front ended by an Apache server and the backend was MySQL database. The developer had setup an instance and my job was to replicate the same using the SOP that they had built to ensure they are accurate and the process is predictable and repeatable. I followed the steps exactly as documented. I was able to get to the login screen. So far so good. But when I tried to log in using the test credentials, I was shown a 404 - Page not found error. Initially, I worked with the developer and they did something and fixed it. Interestingly, they failed to mention it to me what they did and neither was it documented in the SOP. So as it happened, I had to rebuild the server to try and get the SOP working. I again faced that issue and this time, instead of reaching out to the developer, I did my own research and Voila' I was able to solve the problem.
The research led me far and wide and in one of the forums I found the possible answer which suggested setting AllowOverride All on the parent directory of the application. In my case it was /var/www. The post suggested to set it at the main Apache configuration file. But I always try to localize these solutions and not make global changes if I can help it in order to keep the installation secure. So I added a Directory directive in the VHost configuration file which enables AllowOverride All for that VHost only while leaving the original configuration untouched.

Conclusion

They say that Laravel is a programming language for coding artists with elegant frameworks. But these issues are pretty simple and will be prevalent in all applications that require authentication. Why is this not better documented? More importantly why does the authenticate or login action in Laravel return a 404 error?
I wonder...

Responsible and Trustworthy AI

Introduction

Smart City Powered by AI
A futuristic view of Smart City powered by AI
Recently, AI technologies have seen explosive growth. With more genAI applications being built it is important to understand the impact and consequences of AI. I saw an interesting quote recently: "We wanted AI to do our mundane tasks so that we could focus on creativity and not that AI to do creative tasks so that we can do our mundane tasks”.

There is also a risk of using AI as GenAI is exciting and will open up many opportunities to add to the global economy. But it also opens up a lot of risks and dangers to corporations and individuals alike. Responsible GenAI is not only the government's responsibility, but we all are collectively responsible for generating more benefits with genAI. I built a genAI-powered application to provide educators with a platform to develop personalized lesson plans. That experience gave me a first-hand perspective of the power of genAI and the responsibilities that come to us as technology leaders to ensure we use AI safely and that it is trustworthy.

Problems with AI.

As AI’s power increases, it also opens up several risks and problems. This is in no way a comprehensive list but I am just scratching the surface.

  • Inappropriate use: A technology can be used beneficially or maliciously. We have seen a lot of issues come up with deep fakes and misinformation that are known. There are several which are unknown.
  • AI Race: We have seen the negative consequences of the arms race and if governments get into an AI race who’s to say where it will end? The impact of the arms race was visible and I am afraid that with AI technology, we won’t even see the impact as it can be highly targeted and obfuscated.
  • Rogue AIs: Humans have been trying to build an autonomously intelligent robot for several decades. While the objective is to benefit the human race and planet Earth, the risk comes from if and when the AI becomes truly autonomous and humans lose control over them.
  • Misalignment: For now, the AI is a robot that does what it is told. If the instructions provided are not accurate and aligned with the desired objective, the results could be unexpected to catastrophic.
  • Hallucinations: GenAI LLMs are compared to parrots. Sometimes they listen / read other people’s work and parrot it back without any validation even if it is incorrect. There was a very famous and hilarious incident where the chat bot declared that Australia didn’t exist.
  • Conformism: Even today, the AI LLMs conform to human intelligence. I asked the bot what 20+20 was and it correctly responded that it is 40 and confirmed it when I asked if it was sure about it. However, when I said that I think 20+20 was 42, it corrected itself and said that it made a mistake. If the bots can do this with absolute truths, then I am worried about the veracity of the results in subjective situations.

Conclusion:

AI and Machine Learning (ML) has made a lot of progress in the past few years, but it still has a long way to go. Especially the LLMs. There are other key and more impactful applications of AI, but the risks of using AI at this time can be extremely dangerous for humans. AI and ML can help in accelerating and eliminating mundane tasks, but it requires strong human oversight to ensure the results are not only accurate and actually helpful for people but also solving the intended problems and not creating a cobra effect.

My views on 70 hour week

Bottom Line on Top (BLOT): I am against Mr. Murthy's missive that people should work for 70 hours or more to be productive. People can stop reading here. The rest of the narrative just explains my thought process. If interested, read on!

Background: The legendary Mr. Narayan Murthy - one of the founders and Chairman Emeritus of Infosys created a debate in the white collar professional world by stating that people should not think twice even they have to work 70 hours a week. He also mentioned that the young people today are lazy and India's productivity has gone down. Predictably, it created a huge uproar with folks coming out in support of and against Mr. Murthy in equal measure. Known personalities supported Mr. Murthy by quoting examples of Sachin Tendulkar, Virat Kohli, Amitabh Bachchan and how they created their position by working hard and not just for 8 hours a day. I agree. You can't be the GOAT without a great deal of sacrifice.

My Perspective: Let me first start by saying that I myself have worked for 80 hours or more with my previous company. Not for a month or two, but for 3-4 years at end. While I progressed professionally, I ended up moving out of that organization. So you can imagine how that ended. And it also hurt me personally. I missed a lot of events in my children's lives and my wife was left raise our children as a single parent which is not a good experience for anybody.

When I look back at those years, I ask myself, for whom did I work this hard and sacrificed what I did? What did I get in return for my sacrifices? Yes, I was promoted and my salary increased, but honestly was I compensated commensurate with the effort I put in? I was working for a global corporation who made impressive profits. All I got was 2-3% annual raise and a capped bonus. Sometimes not even that and we got maybe 70 cents on the dollar instead of the expected bonus.

As opposed to the majority of the workforce, Mr Murthy was working for himself after he quit his job and started Infosys with Rs. 10000. So he had everything to lose and couldn't afford to fail. Ironically, it was the same Mr. Murthy who had emailed all the Infosys staff to leave office at 5 pm and ensure that there is work-life balance. So you have to wonder what changed Mr. Murthy's opinion. Mr. Murthy's sage advice is spot on for entrepreneurs and startup employees who have a skin in the game in terms of equity as they stand to gain big if the startup turns out to be one of the rare unicorns that we hope. The average employee has no incentive to work for more than what they get paid. They have fixed salaries, the promotions are hard to come by, career prospects are bleak among other reasons. Yes, they also can work for themselves by picking up some freelance work, but companies put a clause in the employment contract and prohibit employees from doing independent work to safeguard proprietary information. They even put a no-compete clause in the contract. And wasn't it Mr. Murthy himself who spoke out against freelancing when the top leaders of the companies effectively do the same when they sit on the boards of various companies?

Conclusion: To be clear, I greatly respect Mr. Murthy and I believe he is one of the greatest minds India has ever produced. But that doesn't necessarily mean we all agree with all his views. This is just one small dissenting voice in the myriad of others. Finally I am happy to work extended hours when there is a need. But it cannot be standard operating environment.

Disclaimer: These are my own personal views and it does not represent views of my current or former employers, colleagues or even friends. If you disagree with me, I am OK with it.

Implementing nested loops with dynamic step in Python3

Introduction

The other day, my son asked me about the result of evaluation of program in Java that he had in his AP Computer Science A (APCSA) course. This course is as a part of his high school senior curriculum. The problem was quite simple of nested for loops in the control flow section. The code is as below.

    a = 0;
        for (i = 0; i < 10; i++) {
            for (k = 0; k <= 5; k++) {
                for (z = 1; z <= 16; z = z * 2) {
                    a++;
                }
            }
       }
    print a

The problem

As you can see, the problem is simple enough. I had done this kind of for loop in shell scripting and in C language when I was learning it a long time ago and somehow I thought that this was the same way you run a for loop in Python as well. Of course I know Python quite well, so I thought I would quickly port this code in Python and run it to verify the answer of the problem (My son had gotten it right by the way and through a very simple mechanism, I must add).

The for statement is used to iterate over the elements of a sequence (such as a string, tuple or list) or other iterable object. However, Python doesn't allow the developer to define both the iteration step and halting condition. Instead Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence.

The syntax for a for loop in Python is very simple and intuitive like so:

    for i in some_list:
        <do something>

Most common use case is to iterate some operation a certain number of times. And the easiest way to do it is to use the range function. In the range function, the structure contains the start point, end point and the step. The step takes an integer as an input and it does not accept an expression as a step. Similarly as Python doesn't allow the developer to define the iteration step in the for loop, it posed a problem for me as I the program above required to have the step in the powers of 2 for each loop.

The research

I tried various combinations and options to change the step size in range function, but as the step is a positional argument and doesn't accept either keyword argument or an expression, the choices were limited to only integers (Range also accepts floats but it for another day). I searched far and wide for a solution but to no avail. Finally I hit on the a possible solution on (where else) Stack Overflow.

The person who asked the question had a similar goal as me. The answer to the question was kind of cryptic, but I was able to figure it out as the answer pointed me in the right direction.

The solution

The solution in the end was embarrassingly simple. Here's the final code for this: There are certain commented statements here which I have left here that I used to debug and understand what was going on.

    #########################################
    # Implement nested for loops in Python  #
    # Programmer: Mukul Dharwadkar          #
    # Date: 24 September 2021               #
    #########################################

    a = 0
    for i in range(10):
        for j in range(6):
            c=1
            for k in range(1, 17, c):
                while c < 17:
                    # print(f'Index c is {c}')
                    c = c * 2
                    #print(f"Index i is {i}")
                    #print(f"Index j is {j}")
                    a += 1
                #print(f"The value of a when is i, j, k and c is {i}, {j}, {k}, {c} is {a}")
    print(f'The value of a is {a}') 

As you can see, I needed to initialize a new counter c that would then be used as the step size. In the innermost for loop, I needed to create a stop condition as the counter was completely independent of all other variables. The while loop above creates that stop condition. Inside the while loop, I am incrementing the counter by the powers of two.

The actual operation of interest is the value of a which is incremented by one everytime the loop is executed. So essentially, the easy way once you figure out how many times each loop is executing is to multiple all those values (5 times 6 times 10 in this case) and arrive at the final answer of 300.

    The value of a is 300

I’m here for you – By Nandini Dharwadkar

Be kind to all

A brand new day. A brand new life. Only ten cars were zooming on the streets, which was the only noise left in the city of Fremont. At least, outside. Inside of hospitals and clinics, the only sound that could be heard was the moaning and groaning of suffering patients, and the soothing voices of the nurses and doctors that worked hard to cure the sick. Everyone noticed this change. Everyone knew. But not everyone cared. The rich were just taking this as a chance to relax.

Coronavirus was taking over people’s lives. And taking them away. And no one could be more affected by this than 15-year old Lily. She wanted some way to help the underprivileged people who couldn’t provide for themselves, the ones without a job because of the lockdown, because they are the ones who need help the most. Lily watched out of her window as she observed a man stuffing his trunk to its maximum capacity with cans of food. Corona Virus

Food, she thought, there will never be enough. For the the higher class with a lavishly decorated home, and the ones with a plain blanket and hard, cement bed. I need to make it enough, especially now.

And watching the man with his cans, Lily knew exactly how to help...

An hour later, Lily had persuaded her sister and had gathered a few friends with her to help other people during this time of distress and were walking around the streets carrying large trash bags. Filled with food and supplies in it that they had pooled out of their own homes. It wasn’t much, but it was worth it. And everyone around the world knew that.

They walked down Thornton Avenue, where they saw an old lady sitting at the edge of a gas station, who was watching them nervously. Her eyes said it all. But as they approached, the woman’s gaze fell to the sidewalk, but Lily knew what the lady’s heart wanted.

Lily kneeled in front of her, and tried to ignore the deadly smell circling the woman. Trying not to scrunch her nose and be rude, Lily said benignly, “How are you doing, Ms….?”

The old woman seemed to trust the teenagers who were silently watching, and said in a croaky voice, “Gibson. Ms. Gibson. What are you doing here? And why are you outside?”

Lily pulled out six large cans of beans, tomatoes, vegetables, and chicken that her mom had saved up. She lined them up in front of the woman. “For you,” she said, and took the old woman’s hand and squeezed it. “We’ll get through this. Coronavirus will be kicked away by vaccines that our doctors will discover. Stay strong. You’re not alone. We’re here for you. I’m here for you.”

Ms. Gibson was speechless. “You’re here for me,” she repeated. “You’re here for me.”

For two hours Lily and the other teenagers walked around Fremont passing out food to homeless and needy people. Other residents noticed the group with large bags as they passed out food. Soon, almost everyone in Lily’s community had joined in the heroic act, and were chanting, “We’re here for you. I’m here for you” to everyone they provided supplies.

Lily looked back at the size of her group and grinned. It took one small act of kindness to prove that the coronavirus could not kill off the kindness people felt for each other, despite the lockdown. All people had to do to prove that was to say four simple words: “I’m here for you.”

Updating a DynamoDB attribute with a hyphen or dash (-) in the name using CLI or SDK

Background

As a part of my personal growth plan and work commitments, I am working on the AWS Certified Developer - Associate certification using the Linux Academy platform. In one of the lab exercises that I was doing on DynamoDB, there were requirements for updating DynamoDB attribute using SDK and perform conditional updates and atomic counters on the tables. Being what I am, I did not use the examples they had provided, but created by own table to create a database of books I own and proceeded to create my own attribute names for the items.

The problem

As it happened, I created attributes like book-title, book-author, book-price, etc. which in itself is not a problem. However, the lab exercise had me perform the item updates using the BOTO3 Python SDK which got me excited to learn new things. I used the example files that the trainer had provided and modified it to suit my environment and ran the script.

UpdateExpression='SET book-price = :val',
ExpressionAttributeValues={
    ':val': {'N': '15.37'},  
    ':currval': {'N': '0'} 
},
ConditionExpression='book-price = :currval',
ReturnValues="ALL_NEW"

To my dismay, I started encountering errors.

Traceback (most recent call last):
  File "conditional_write.py", line 18, in 
    ReturnValues="ALL_NEW"
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 626, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Syntax error; token: "-", near: "book-price"

The Solution

I reviewed my code to ensure that I had not introduced any bugs myself. After ensuring that I had not introduced any bugs by adding new attributes to an item without any dashes and running the script successfully, I starting practicing my Google-Fu. There I found this awesome post on stackoverflow along with a link to official AWS documentation. The official documentation however only talks about a dot being a special character and it doesn't list a dash (-). After following the instructions from the stackoverflow post, my new code looked like this:

UpdateExpression='SET #bp = :val',
ExpressionAttributeValues={
    ':val': {'N': '15.37'},  # Make sure we keep this line the same
    ':currval': {'N': '0'}  # What was the current value?
},
ExpressionAttributeNames={
    "#bp": "book-price"
    },
ConditionExpression='#bp = :currval',
ReturnValues="ALL_NEW"

And once I implemented this code it all started working correctly. I have left a feedback for the AWS documentation team and hopefully they will update the documentation. I just want to make sure that all the cases are at listed and documented so that developers and wannabes like me are not stuck.

Thumbs up to Apple on Inclusion and Diversity

Apple hosted their annual fall product launch yesterday in the Steve Jobs theatre in the Apple campus. The event had its regular razzmatazz of new products and self-described superlatives for its own products. There was something different about the event this time and no it was not the iPhone 11 Pro. This time, the presenters were from diverse backgrounds and were inclusive. Thumbs up to Apple on Inclusion and Diversity and making a real effort towards it.

Historically, the presenters of the events were white males (and to some extent females) who would boast the features and performances of the products. This time around though, we saw Asians doing the keynote presentations, females in actions but sadly still not blacks. I am fairly certain that it is just a matter of time where every company and organization will make Inclusion and Diversity their priority.

But for now, I think I will enjoy the launch and wait for the availability of iPhone 11 Pro. It is a great product and Apple has managed to excite me after 5 versions of the phone.

Are we becoming the mice of NIMH?

Introduction

Some time ago, I had written about people behavior and civilization. Those thoughts sparked from how people behave in less than optimal situations like a crowded train. But that's nothing compared what's happening around us nowadays. Last week there was yet another mass shooting in a public place in the US. This time the shooting was at the Gilroy Garlic Festival. There have been 248 mass shootings in US in 2019 and at this pace, it will easily surpass the 323 mass shootings that took place in 2018. Are we becoming the mice of NIMH?

Social Issue

What is the society now coming to? Are we really becoming the mice of NIMH where we are unable to handle the bounty that nature and our society is providing us? The video below is very distressing and is that a harginger for human society. All the indicators so far point in that direction only.

Will this human behavioral trend mean that all the social gatherings will cease to happen and everything will become virtual? Already the today's kids don't like to go and hang out together. Rather they choose hanging out together in virtual chat rooms like Google Hangouts, Facebook Messenger, or Discord. Messenger website even has a catch-phrase, "Be together, whenever."

Messenger Message
Is it worth it?

These kids are missing out on all the personal contacts gained by actual interaction. This kind of social interaction is not preparing them for the rigors of the real world and they become socially awkward. Will they become "The beautiful ones"? Only time will tell, but I am worried.

Already the upcoming social events like the Fremont Festival of the Arts will have enhanced security after the Gilroy incident. In that case, people immediately start viewing each other with suspicion and instead of what should be a celebration of art, culture and human interaction, the ambience becomes acidic and caustic and an ordeal. I have already made up my mind to not go to the festival.

Conclusion:

I just hope that good sense will prevail and human race will address this issue and halt the seemingly inevitable march towards doomsday.

Elections in the new world

Context:

A long running episode has just turned an important page right now. Robert Mueller finally testified in front of the congress and as I expected provided almost nothing to the lawmakers outside his report. The focus of media and most of the public was around collusion and obstruction of justice. Indeed, that was the most newsworthy story but in my opinion not the main story or threat to the democracies of the world. It was only Rep. Adam Schiff brought out the question of integrity and security of elections. Director Mueller had already highlighted it in his monologue of a press conference in May 2019. How will the elections look like in the new world?

Subtext:

It is an important aspect that all the democratically elected governments of the

Elections
Elections in India

world should be really worried about. In fact there are questions being asked of the validity of the Brexit referendum vote and even some of the assembly Elections results in India. Now defunct Cambridge Analytica is being suspected as being involved and even instrumental in altering the outcome of both the results.

Just imagine if the Pakistani intelligence agency ISI decides to engage itself in Indian politics. It can ensure a party that is sympathetic towards Pakistan comes to power. Or even worse, it can ensure that an incompetent leader becomes the prime minister of India. That would be a disaster not only for India but to the stability of the region and I daresay, even the world. I can't think of India being ruled by Congress party led by an inept leader like Rahul Gandhi.

With the world becoming more and more digital and online, governments of the world should take infinitely more care about ensuring the data security and integrity to ensure fair and correct results. We all see in day to day life how easy it is to hack any computer system and bring it down. The private companies of the world realize it and spend a fortune on securing their IT infrastructure. The governments also should realize it. The bureaucrats must eliminate of reduce bureaucracy to a large extent and actually care about the security and integrity of the election process and the integrity of the results.

Conclusion:

It is very easy to ensure the security of elections in the new world if you think about it. First of all, Government must appoint competent people to key positions with reasonable autonomy to perform their function. As a result of strong and fair oversight, it will ensure that the right policies and procedures are implemented. Politicians must be kept at more than an arms length from the entire process. State of the art technology should be implemented. Most importantly, the people involved in the process at the grass roots level should be provided training and right incentives.

This is the just the starting point. But we don't have a lot of time to get it right. The bad actors are already off the blocks and the race is on!!!