A Cautionary tale about the spread operator

I have been using the ES6 syntax for making copies of objects when React/Redux demanded we return a new copy every time we made a change to the state.

This syntax is

This works great because the spread operator creates a copy of all the keys in the original object. Except… Something that is easy to forget is that it is a shallow copy.

This means that if we have a nested object, the 1st level will be copied by value but every level that’s further nested will be copied by reference! Who would have thunk?

Take a look at this example

We would assume that we get a new object to play with as we deem fit. But if we change a value that’s 2 levels deep as above, we end up mutating the original object and React/Redux will not work as expected because they depend on brand new objects that they can compare with the old objects.

Instead we could do something like

Notice we are using the spread operator at every level of nesting.

In summary, remember that the spread operator gives you a shallow copy.
Also, keep your redux state as flat as possible so you don’t have to deal with such situations.
Happy coding!

The magic of Parcel

Yo frontend web-dev world, I know it’s early for Thanksgiving, but I’m grateful for Parceljs (parceljs.org). It’s an amazing tool because of the zero-configuration approach it promises for web-dev projects.

Disclaimer – I have no affiliation with Parcel, just a dev crush.

I started learning about bundlers and task runners back when Grunt was more popular.

I slowly evolved my understanding of the fragmented and complicated world of web development and understood that to use the latest technologies and specifications wasn’t as easy as updating to the latest version of Java which came with it’s own compiler.

I soon learnt about polyfills and how Babel was the champion of the polyfill world. A polyfill, in short, is something that adds code that a browser might not know.

Long story short, I had to first learn about how to setup Babel with Webpack, and then learn about file loaders, and code splitting and build paths and entry points and so on. All necessary to use modern ES6 syntax.

I did learn it. But I didn’t like it when I wanted to quickly setup a new project that uses all these modern features.

Enter Parcel! It’s so simple that it includes all of these things pre-configured for you.

All anyone needs now is an index.html file that has a script src entry to a javascript file (say index.js). This index.js file then could include other modules and so on. Parcel understands all. Honestly that should be their tagline.

I can’t speak for large apps and production builds where you might want a specific configuration that’s not easy to achieve with Parcel. But I know that it’s going to be my go-to when I think “Oh, wouldn’t it be cool if I can make…”.

NLP Basics at NYU Makerspace

I recently had the pleasure of giving an intro talk on Natural Language Processing at NYU! My basic concepts were a little rusty so I knew this would be a great way for me to get back into the NLP game.

All of the content for my workshop is on this PDF.

TL;DR – I introduce TextBlob, simple NLP tasks like Parts-of-Speech tagging, spell-correction, lemmatization, summarization and then create a simple chatbot to help you find a job(link to Github in the PDF).

The chatbot is a watered down version of the bot I made for my NLP course in college. Joby will help you find jobs using queries like “Show me jobs in San Francisco” or “I want healthcare jobs in New York”.

NYU Makerspace also featured me on their blog – https://wp.nyu.edu/makerspace/2018/05/03/chatbot-workshop-with-karan-rajpal/ so w00t!

The last time I taught a workshop in person was an Android App Dev workshop a few years back and enjoyed presenting as a way to consolidate whatever I knew about a topic.

I realized the value of consolidating what I know because revisiting concepts while consolidating everything into a presentation really made me feel like I know those topics well.

Also I definitely can do a better job at public speaking but this was good practice!

The Business of Global Poverty

I recently watched the movie Poverty, Inc. It starts off with a paraphrased quote from Machiavelli – “The reason there will be no change is because the people who stand to lose from change have all the power. And the people who stand to gain from change have none of the power” (or are indifferent to change).

It’s only human to sympathize with people living in poverty. When we see images of poor people, our instinctive response is to help out by giving them a portion of our money or food or shelter. It appeals to our better nature, and its also what society has told us is the solution. But this doesn’t seem to be the best solution. The movie really showed me the bigger picture.

People in Africa have been getting aid for a long time now. Foreign aid has amounted to hundreds of millions of dollars, a very sizable subsidy! But this large scale aid has crippled the people of Africa – A lot of businesses in the area like rice and other crop farmers, Solar panel makers cannot compete with free. As a result, they are run into the ground and become part of the growing number of people who are poor.

A case in point is Tom’s Shoes. They had the best intentions at heart. For every pair of shoes sold in a developed country like the US, they would donate a pair of shoes in a developing country. There were so many children without shoes on their feet. Of course this seemed great! But it drove the demand for the shoes made by local cobblers straight to zero.

The movie also brings out an interesting perspective on Colonialism – The idea is that the countries who provide the aid also get to dictate how the aid money is spent. If they decide to favour certain businesses, the receiving country has to abide. This means that the receiving country is never free to pursue its own agenda and the government isn’t incentivized to make any changes to reduce poverty because they would lose all the free money and resources they’re getting. In addition, the NGOs that are part of the equation working with the government in different capacities would be out of a job. Why would they want that?

The Poverty Industry

The Poverty Industry as shown in the movie

Of course, it doesn’t mean that there aren’t innovators who genuinely care. A lot of people have realized how dangerous simple donation is to the economies of developing countries. The right thing to do is to partner with these countries and local businesses and help them grow. The movie tells us the story of an American couple who move to Haiti and helps many local women and men make simple jewelry that they then sell to big retailers in the US. Her employees began to feel empowered and soon realized they could fend for themselves and buy their own small homes and care for their children.

Helping local artisans make jewelry
Helping local artisans make jewelry

It’s one of those things that seem obvious in hindsight – but if we really want to help, we should teach people how to fish, not just give them fish.

This movie shines a very realistic light on the state of our world and I recommend it for anyone remotely interested in social welfare. It shows us how everything is connected from celebrities to orphanages.

Having a heart for the poor is easy; having a mind for the poor, thats the challenge..

Watch the Trailer – https://www.youtube.com/watch?v=aqGQ1IRhdzg

My Concert Collection

My first concert was Iron Maiden at Bangalore in 2009. I remember almost losing my shoe and getting up on my friend’s shoulder for Fear of the Dark. Fast forward 9 years, and many concerts later, I’ve realised the energy at Indian concerts is significantly higher than US concerts.

As an Indian who grew up listening to a lot of Classic Rock, getting a chance to see many of my favourite bands in concert cured me of some of my fomo!

Guns N Roses (with Slash) – Really good show but Axl’s voice was better in Bangalore and nothing could beat being in the 2nd row in Bangalore.

Coldplay – Great music complemented with a great light display.

Queen + Adam Lambert – I think this was the best concert I’ve been to from a music standpoint. Adam Lambert voiced out my feelings exactly – “Is this real life, or this just fantasy?” Nobody can really be like Freddie Mercury but I’m so glad that they had the concert anyway.

Roger Waters (Us & Them tour) – It was like a dream to actually be in a Pink Floyd concert. I knew around 70% of the songs played that night but everything was still very enjoyable. The show brought out their renowned lavish visual experience that included a giant Factory, a giant Pig and a slew of political messages.

The Classic East (Eagles, Steely Dan) – Steely Dan wasn’t what I expected. Maybe I didn’t know enough of their songs to appreciate the music but they played only a few of the ones I knew which were just average.

The Eagles were amazing! So many songs were more enjoyable than expected. Big fan of their live performance.

Hans Zimmer – Inspirational movie soundtracks had me in goosebumps many times that night. The Pirates of the Caribbean piece was exquisite. The title track needs no reference but this was from one of the newer movies – https://www.youtube.com/watch?v=oeK4HMak-q0. Hair-raising!

Iggy Azalea – Good morning America’s free concerts had me up at 7 AM to get Iggy Azalea’s concert in Central Park. It was ‘Fancy’ to say the least.

Blink 182 – My 2nd GMA concert was a lot more crowded and I was part of my first mosh pit here. It was fun being occasionally crashed into by a pumped-up American goon.

Galantis – I had heard 4 or 5 songs of their and assumed thats all they’d play. But instead a I realised a live EDM concert is fairly different from their studio produced songs. Tried to make the most of enjoying in an environment designed for 18 year olds with extra money.

Metallica – The energy levels at Bangalore was insane. I joined the horde of metal-heads to head-bang to everything from Master of Puppets to Fuel. The line to enter the stadium literally went down the main road for around a kilometre and into a field where people were using a corner of the field to relieve themselves before the long evening of musical mayhem that lay ahead.

Cover bands and live shows

Appetite for Destruction & Rocket Queens – This 2 band show cranked out really good GnR magic.

Fleetwood Macked – Good cover band covering one of my favourite bands of all time!

Cafe Wha‘s House band had some really great sounding covers when I went. Hopefully I catch more live music there!

I’m sure I’ve missed a couple of small shows here but I’m so glad I got to see these awesome bands!

Train trip in America!

Of late, I’ve realized I’m going to be in the US for a short time so it makes sense to see more of this giant country before leaving it.

Before coming to the US, I read this blog post about someone traveling across the country by train and experiencing the true beauty of the land. I am a person who takes my recommendations serious, and stirred.

My college roommate, KM and I got onto our first US train that snaked up North alongside the Hudson. Like absolute noobs, we chose seats on the right hand side of the carriage while the pretty river and mountains ended up being on the left. The train was heading to Poughkeepsie, so I ended up doing this

Friends reference anyone?

We navigated through the pleasant town of Cold Spring to reach a really serene and mostly deserted part of the Hudson River.

Onward to the calorie burning hike that was on the agenda.

I realized I like hiking very recently when we I went on the arduous Angel’s Landing hike in Zion National Parks. I’m kicking myself for not hiking enough in India and I hope to see more nature when I go back.

We proudly fitted ourselves with makeshift walking sticks and eventually got to the top where the view was pretty inspiring.

Our success warranted some cave man inspired shenanigans by the ever sportive KM which honestly was the best part of the day.

Here is another picture of us trying to rock some shades at the highest point

Amidst life observations, the second leg of our hike led us deeper into the forest to a completely deserted babbling brook. It sounded amazing! We stopped to take in this tranquil setting and to recharge body and mind with a banana and a book apiece.

On the way back, we decided to help me check-off an item from my mini bucket list and hitchhiked with a stranger back to the town. Fortunately, or unfortunately it was pretty uneventful.

We ended this awesome fat burning day with a heavy meal from Saravana Bhavan thus providing balance to the world.

The Yaaaay Lady

Recently Google had a giveaway for the Google Home Mini. While waiting in the line to enter the pop-up donut themed shop, there was a Google employee at the doors. She made the event all the more memorable because she would go “Yaaaaaaaay” whenever anyone came out with a Google Home Mini!

I feel like she was on something.

She had the kind of excitement someone should have when people start using what you make. I hope I’m as excited about people using something I helped make.


Blog posts don’t all have to be super insightful, right? Here is one of those small-joys post.

I discovered Magie today. Magie is a song by the German artist Nena.


I don’t understand anything she’s saying but the song really struck a chord with me. It’s one of those things that songs can do for you. I can’t explain it but a good song lets you feel deeper than you can feel otherwise. A good song can help you run the last half mile of your run or inspire you to go out and make today super productive; or just give you goosebumps.

Because I’ve been listening to songs by Nena (and other German artists thanks to Spotify’s recommendation engine), I’ve been fascinated by Germany. Hopefully I can visit sometime soon! Ok bye.

Advice and Self Identity

Advice is a big part of social interaction with other humans. Sometimes you’re looking for advice and sometimes people just give it to you anyway. Parents have to instruct their kids from an early age in the ways of the world and it becomes a habit for them to give their children advice as they grow up and even when they’re older. Many a times people get advice from friends. Knowing how to sift through the advice and imbibe all the good stuff is something I really value. Society works largely on recommendations from others – shopping reviews, movie ratings, what place to eat at, what college to go to and so on. But when it comes to more personal things, heeding advice gets harder.

A big part of acting on someone’s advice is being able to socially identify yourself with it. For example, say I have a friend who is a gym buff. He tells me to start gymming, and follows it with a very sensible explanation of how excercise is helpful and so on; I’m only inclined to follow his advice if I am ok to take up somebody else’s passion(his) and start parading socially that it is also mine. My relationship with this person also matters because I am now indebted to him for convincing me to join the gym so I might not be able to fully “own” this passion with him out “owning” me.

This is obviously not the case for a large number of people who would take up their friend’s advice to join the gym. This happens because he/she is open minded and motivated enough to try something new in the first place. Another reason that people listen to other people is social inclusion. “Let me join the drama club cause thats what all the cool kids are doing” or “Let me try alcohol cause everyone else has”. It’s also important to respect the person giving you the advice and publicly regard them as more knowledgeable on that matter. This is tough to do with some parents because of obvious parent-child dynamics where the child is always on rebel-against-everything-even-if-it-makes-sense mode.

This post is pretty rough around the edges and it feels disorganized but hey, atleast I now identify myself as a writer.

Why I’m Blogging

Alexa what’s the date today?

“Today is Sunday, September 24th”

I’ve been shunning writing because of the effort it takes to actually put my thoughts down on paper. It’s really slow compared to actually just thinking those thoughts or even talking to people about it. But I realized that most of the opinions or ideas in my head never graduate to “Level 2”. By this I mean, if I have an initial instinctive theory about something, I acknowledge that and am happy with my learning but I am not able to do anything useful with it or get deeper into that topic.

I am reminded about Dumbledore’s Pensieve. He had so many thoughts and memories in his head that at times he had to store it somewhere so he can examine it better. I’m hoping I can do the same with this blog.

I want to record my experiences so I can look back and remember them with more detail. I also want to record my outlook on life. I’m expecting most of my blog posts to be about experiences or opinions 🙂