Book Review — Grokking Algorithms by Aditya Bhargava


The word 'grokking' refers to 'understand (something) intuitively or by empathy' and it is the intuition part that this book attempts to impart via some really awesome illustrations.


First off - this is not a book for people who have completed Computer Science or have learnt algorithms. However it IS a wonderful book for beginners or as is mentioned on the cover 'for curious people'.

The chapter on dynamic programming alone makes this book highly worth reading.

Pros -

  • Very easy to understand and grasp the underlying intuition
  • Everyday relatable examples of the algorithm usage
  • The high quality illustrations
  • Written in a fun and engaging manner so easy to dive in and keep reading
  • Chapters are independent, so can pick without needing to read in sequence


Cons -

  • Minimal algorithms covered and in less depth
  • Not a substitute for the more formal books in this area
  • Will not help you master algorithms. This book is to start the journey into algorithms


Book Review — Things to make and do in the fourth dimension

 Math is stranger than fiction and this book is filled with the many curiosities of the math world. It contains a glimpse into its intriguing lanes in an entertaining manner along with optional hands-on activities to enjoy.

Each chapter is not so much in depth that it is akin to a text book but just enough to get you started to play with the math, if the topic interests you. Dive in — you’ll be amazed at the sights (with a little math humor thrown in).

I won’t claim to have understood it all.

For e.g. The multidimensional world which was just too bizarre.

(A helpful tip by Geoffrey Hinton — “To deal with hyper-planes in a 14-dimensional space, visualize a 3-D space and say “fourteen” to yourself very loudly. Everyone does it.”)

But there is something in it for everybody.

Some delightful snippets -

  • Different-sized infinities
  • The strange cut outs from Mobius loops
  • Prime numbers ( considered pointless math till 1940 !! Now basis of digital communication )
  • A sphere that increases in size even when bounded by other packing spheres (26th dimension onwards) !! Weird is an understatement !
  • Ramanujan summation where sum of all the positive whole numbers = -1/12 ! Used in string theory ( I am still trying to wrap my head around this )
  • Knot theory — Trying to find one method to know if a tangled string is a knot and if so how to undo it with minimal effort. Why bother ? Biologists may be able to devise new wave of medical treatments based on this
  • Uncomputable numbers !!! ( No amount of exclamations will do this justice ! )
  • Description of Gödel’s incompleteness theorem. Short, succinct and intuitive
  • Riemann Hypothesis, e, π, Φ, infinite hotel do get a mention ( almost de rigueur I think )

An engaging book about math; The language the universe speaks to us in. Fall into the fascination and there’s no going back.


Step-by-Step guide to restore old photos

 A few months back, Microsoft shared code for old photo restoration. The implementation was in pytorch.

I tried to use the code to restore some old damaged snaps. I found that not all old photos can be enhanced. Reasonably well defined blemishes and lines are handled well but diffused areas of damage don’t fare that as good.

Nevertheless it is a very impressive photo restoration using AI.

This is a step-by-step guide to using the code to restore your old photos using Google colab.

You need —

a. Gmail ID to run the colab notebook

b. Old photo (≤500 x 500 pixels only)

1. Copy the colab notebook

Save the colab notebook at this link to your own gdrive so that you can use this notebook in your google colab environment.

Save copy of the colab notebook to your gdrive
Image for post

2. Change the run time environment

Change the runtime type to Python3 and the hardware accelerator to GPU as mentioned at the top of the notebook.

Image for post
Image for post

3. Run the notebook cells

Run all the cells till the section ‘Try it on your own photos’. So all steps under ‘Git Clone’, ‘Set up the environment’, ‘Run the code’ need to be completed.

Image for post

4. Upload the files to be restored

When you run the cell after the heading ‘Try it on your own photos!’ you will see a button to ‘Choose files’. You can choose multiple files or a single file.

Image for post

5. With scratch or Without scratch flag

After the files are uploaded in the next cell — choose the restoration type. If the photos have scratches then simple add the flag --with-scratch at the end of the code. Otherwise no change to be made.

Image for post

6. Results display

After this cell completes its run, the result is displayed side by side with the original input picture.

Image for post

7. Download the results

Run the next cell which copies the output to a zip file and downloads this zip file. This downloaded file will contain the resultant restored image(s).

Image for post

8. Issues

Scaling images

If you upload a file that is more than 500x500 pixels — the large image is skipped and not processed.

Image for post

You can scale images in GIMP or use any image editor tool to ensure it is within the limit prescribed.

Incognito Mode

If you run the colab notebook in Incognito mode you may come across this error message.

Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable.

To overcome this — you can either run the notebook in regular chrome window or use whitelist cookies from google like this -

https://[*.]googleusercontent.com:443

For more details — check out this stackoverflow link.

References:

User Interface design and User Experience

Recently the story of the student who lost his seat in IIT due to inadvertently clicking the wrong link made headlines.

The story is sad and hopefully the Supreme Court will allow him to get a seat on humanitarian grounds. One of the assertions by IIT was that; withdrawal is a conscious two-step process. The student has to enter a reason for withdrawal. While I don't know the UI(User Interface) for IIT - I wonder could the experience have been made better so such an error could not have easily happened ?

If you approach the UI design thinking that ~90% of the students who get into IIT will not reject the seat, then perhaps the design could have been different.

Consider, instead of just asking for 'reason for withdrawal' - could additional UI elements have made the student realize what he was doing ?

  • Red exclamation point ❗️/ stop sign 🚫
  • Clearer message - 'You will lose your seat' !!! ( Certainly more meaningful that using the word 'freeze' as the articles suggest. )
  • Simplification of language and double check - 'Are you sure ?' 🔴
  • A waiting period before accepting the withdrawal ( this could pose issues to other candidates of course )
  • A separate mail / call confirming the withdrawal

UI design and UX (User Experience) design are vast fields with the attendant deep knowledge and experience required for best results. This is not restricted to software alone either. Add in making design decisions which will help people with special needs, health issues, color blindness, deafness etc., it is a field that cannot be under-rated. And it begins with one question -


Who is the audience and what do we want to help them accomplish ?


There is never a perfect UI design that can ensure no errors but gentle nudges (not always gentle as the dark patterns in UI show) towards a desired outcome is  part of the design and UX. 

And what can be more desired than a seat in IIT to a JEE Aspirant ?

References : 

  1. Nudge 
  2. Dark Patterns in UI
  3. Dark Patterns in ecommerce sites
  4. Interfaces designed to trick you

 

Recommended Daily Interview Problem Newsletter

TLDR; Subscribe to the daily interview problem newsletter at Quastor Daily. It is a wonderful newsletter to help prepare for technical interviews.

This is not a paid recommendation !!! All opinions are my own.

I don’t know where I came across this newsletter first but I have not regretted signing up for it. In fact I have now removed most other algorithm subscriptions in favor of this one.

What’s in the newsletter ?

One gets an interview problem in the mail along with the solution to the previous day’s problem (In Python3). Curated Tech News is also a part of the mail.

So why do I like it ? Let me list the reasons -

1. No sign-in required to view the solutions.

Yes, yes this is not a deal breaker if the content is really good but I like that even this small (grain in the shoe type of friction?) hindrance is removed. All solutions are found at a public repl.it link. No logging in required!!

2. Explanation of the logic

A through explanation of the logic followed in the code solution is part of the mail. Some oft repeating tips are very helpful in understanding how to approach particular type of problems. Basic test cases are also part of the solution.

3. Not restricted to only coding questions

Map Reduce, Rate Limiting, ACID, Leader Election etc. — the questions are not restricted solely to coding.

4. Clean Design

I like that the design is clean and not cluttered. After the recent change in the order of items it is even better.

5. Tech Dives

Newly added — this really helps round one’s preparation as well as understand concepts in greater depth.

6. Almost a one-stop solution

Because the questions are not limited to coding, it is almost like a one-stop solution to prepare for a programming interview. I say almost because language specific idiosyncrasies are not covered ! I think it should remain as is in this aspect.

7. Misc

- I was not able to get my head around a dynamic programming solution (work in progress) but the author responded with relevant links towards understanding this. Other queries were also met with helpful suggestions.

- I really like the Tech News section. Did not know Cryptokitties were a thing !!

- There was a recent chance to have a mock interview with a google engineer.

- I feel the newsletter improves a little bit everyday. Hope it continues to do so !

It is said the power of your routine is built in your daily habits.

I am happy to have found this newsletter which has helped me make this a daily habit ! (almost! I do miss a few days).

Stuck somewhere ? Check out program visualization of code at this awesome website. Support for other languages is also present but I have not checked them out.

Have fun !

Book Review - Emperor Of All Maladies

I found myself reading this book compulsively; every moment I could. This biography of cancer reads like a thriller. Surprising when you consider we have not yet found a true cure for cancer. We are still on the journey. We have found therapies that work with long remissions but there are no guarantees. And yet - I could not put this book down.

History entwined with scientific theory tends to skew towards personalities / events and less science. Not so in this book. From the earliest known records (with 'no cure' as answer) to radical surgery, toxic chemotherapy that bring patients to the brink of death to retroviruses, genetic mutations to biochemical pathways - there is no lack of scientific details.

Political movements to urge politicians to fund the war on cancer, compassionate access to trial medicines, lobbying for display of warnings (lung cancer),  identifying prevention measures, role of statistics, palliative care - this tome brings other aspects outside of the lab to light too.

But the tale that holds the most attention is the disease itself. Every time you think the fiercely committed doctors/scientists/chemists/etc. have come up with a cure - the chimera of cancer outwits those who would cure it and show another deadly face. Ultimately cancer cells are our own mutated cells - twisted like an evil twin that does not know when to stop.

Chilling, suspenseful, heartbreaking (children !) and impressively researched it fosters immense respect towards the people involved in this field. And a sober empathy to all those lost within sealed 'isolation' sterile rooms; who don't have the energy to make their friends/well-wishers feel 'needed' when they come to visit - so lose them at a time when they possibly need them the most.

Book Review - Telescope in Ice - Inventing a New Astronomy at the South Pole by Mark Bowen

Telescope in Ice - Inventing a New Astronomy at the South Pole by Mark Bowen
I picked up this book because the title intrigued me. A telescope in ... ICE ?? 

It follows the building of the IceCube Neutrino instrument in Antarctica. It is buried about a mile deep in the diamond-clear ice there. It detects extraterrestrial neutrinos. 

The first part of the book is about the physics. Neutrinos are fascinating sub-atomic particles - neutral in charge and can pass through almost anything. Billions pass through universe, the earth and through your body harmlessly every second. From the book - 

'Your average neutrino will pass unscathed—and therefore undetected—through a slab of lead one light year, or six trillion miles, thick'. 


Occasionally they will react/collide with the ice and this is what the IceCube telescope is built to detect using the earth as a shield.

Why neutrinos ? Because it can pass through almost anything, it can reveal information about the interior of stars, supernovae, gamma ray bursts and other regions that are hidden behind inter-stellar dust and hence not accessible to normal telescopes.

The book brought to mind that science these days is like a huge group enterprise spanning multiple areas of expertise (the design of the drill bit was the one most important parts of the project) than a lone scientist working at something.

In turns compelling, human (rivalries !), mundane (project budgets and government agencies !) the journey through the span of years it takes to build the final instrument and the failures before is like taking a seat in Antarctica and watching the action and adventure first-hand.  

Book Review - Stuff Matters: Exploring the Marvelous Materials That Shape Our Man-Made World by Mark Miodownik

Stuff Matters - Exploring the Marvelous Materials That Shape Our Man-Made World by Mark Miodownik
Concrete cloth, Self-cleaning concrete, Chocolate Engineering :), Materials that change behavior completely with just addition of one more layer of atoms, Material that is 99.8% air (Blurs around edges when viewed. The author equates it to holding a piece of sky !).

This is a effervescent romp through common materials that surround the author as he sits on his deck drinking coffee.

Most chapters read like a story going through the history of the material, chemical composition, structure and its relevance to our everyday life. (No chemical equations if this makes a difference). 

It brings to home an appreciation of the fact that structure of the bonds inside a material matter just as much as composition.

Can't wait to read 'Liquid' by the same author. :)

My book list in Lean In Bangalore

 2020 Mid-Year Books Recommendations

I had shared a list of books on whats app along with my reviews and Lean In Bangalore posted the content at this link — 

https://medium.com/leaninbangalore/2020-mid-year-books-recommendations-5eebb26cb2fa

Other than the introduction and last line, all the reviews are mine ! :)

Github profile readme

Github profile readme is an excellent way to create a short (or over-engineered !) introduction about yourself. This will be displayed above your pinned items in your github profile.

There are a plethora of choices to personalize since the readme is a markdown file. Profiles are having spotify lists, games, gifs etc.

I wanted something clean, simple and self-updating.

I created a technical blog and ‘Today-I-learnt’ blog towards this endeavor. 

The exact code and how-to can be found at this link — 

https://vidyabhandary.github.io/blog/github/2020/07/27/Self-updating-profile-readme.html

And this is how Github profile looks now — https://github.com/vidyabhandary

Self-updating Github profile readme (completely within Github ecosystem)


Swap bits - Visual Explanation

Code that takes as input an integer (x) and swaps the bits at indices (i) and (j).

The code below is taken from EPI 4.2

def swap_bits(x, i, j):
    if (x >> i) & 1 != (x >> j) & 1:
        # ith and jth bits differ. We will swap them by flipping their values
        # Select the bits to flip with bit mask.
        # Since x^1 = 0 when x = 1 and 1 when x = 0 we can perform flip XOR
        bit_mask = (1 << i) | (1 << j)
        x ^= bit_mask
    return x

Visual Explanation

1. Most Significant bit and Least Significant bit of the integer (x)

In this problem x = 73. The bits to be swapped are at positions 6 and 1. So i = 6 and j = 1.



2.  Move the relevant bit at index i to the LSB position.

x >> i



3. Perform a bit AND operation to extract the bit value. In this case it gives 1.

(x >> i) & 1



4. Move the relevant bit at index j to the LSB position.

x >> j



5.  Perform a bit AND operation to extract the bit value. In this case it gives 0.

(x >> j) & 1


6.  At this point it is clear that the two bits to be swapped are different. Hence they need to be interchanged. If the bits were same we would simply return (x).

(x >> i) & 1 != (x >> j) & 1


7. Bit mask  - Use a bit mask to mark the position of the indices.

(i << i) | (i << j)


7a. Mark the first index position i with 1  

(i << i)





7b. Mark the second index position j with j 1

(i << j)


7c. Perform a bitwise OR to mark both the index positions in the bitmask

(i << i) | (i << j)


8.  Toggle the bits to perform the swap operation. Use the bitmask with the index positions marked and perform bitwise XOR. Return the result.

x ^= bit_mask ( XOR to toggle the bits )




Unsubscribe ... with a zeal ...

It had to happen ! Yesterday I was watching a TED talk on concentration and one of the items listed in the suggestion was a talk I had viewed before. But for the life of me I just could not remember anything about it. I know I had watched it solely because the title intrigued me (clickbait?!) and the talk did not disappoint - and yet here I was, hardly a couple of months since I had watched it (yes - I remembered that too) and could recall nothing of the talk itself.

So that made me curious - like any self-respecting software professional - I bookmark tons of articles, blog posts, books and videos to consume. This is continuous learning I am writing about. Not fiction.

Books 
I looked at the list of books I had read and there they were - couple of books that I had no recollection of at all !! Not a single point of those books stood out.

There could be couple of things here - One that I read so widely that nothing in those books stood out from the many blogs / TED Talks / Articles etc that I read. I already knew the material in bits and pieces from various resources.

I don't think this is entirely true. When I pick up a book - I try to do a basic synopsis (not as much in depth - as suggested in 'How to read a book') and at least as far as the books of last year are concerned I did not think I knew about those topics as much.

Two - They were just entirely forgettable simply due to a non-connect emotionally or due to no-usage day in and day out.  The forgetfulness curve set in and with nothing to make me remember (not yet added to my trusty Anki Spaced Repetition App) - like water through a sieve - it just drained out.

Subscriptions
Too many blogs these days do not have a RSS feed. Sometime last year I decided that if a website does not have RSS feed I would not bother with updates from that website. Yes, I may get less content but then it is not like I do not have plenty of good material to read. I am drowning in the To-Read pile.

Even with that I had a lot of mail subscriptions from authors that I thought I cared about. Looking through more than ~125 mail subscriptions I could not adequately recall enough to justify this kind of deluge and the time I spent on that deluge.

That UX design mail course - nothing remains in mind. I remember instead the UX designing trade offs that we had to make while developing our app.

That snippet of daily knowledge  - uh oh .. just cannot recall.

So ...... 

The end result -

1. I unsubscribed from almost all of the mail subscriptions - and they were quite a lot ! Phew !
2. Pared down my bookmarks to a minimum ( this took a while - I think there are some time-wasters lurking there but for now it will do)
3. Removed more than 100 RSS subscriptions
4. I always have a humongous list of next books to read - slashed it to 1/3rd !!
5. Videos and videos list - Completely revised the list and removed everything that went - 'I may get to this topic later' !! It never happens. Because then one makes a fresh search and list !!!

This clean up was definitely not my new year resolution but I am glad the way to have started this.

I have realized that I prefer my learning mostly from books / some MOOCs  and then projects. So I am sticking to what works for me.

'Deep Work' by Cal Newport made an impression on me and since then I have been following its tenets as much as possible. This year I hope to read 'Digital Minimalism' by him and make it even more easier to do deep work. Let's see.

And to ensure I stay on course if I do not consume what I mark for reading (articles/blogposts/videos) in a month - I will just delete it.

Books do not come in this list because some books are big and I take time to read them so the 1 month criteria does not work. What does work is keeping the book aside if it does not appeal. Life is too short to read boring books even if they are non-fiction. With some search - there will be other authors who will present the same material in a more engaging way.  Or even a youtube list !! LOL ... Back to the vicious circle !!!!


I have realized 'To-Be-Consumed-later' is a black-hole. Nothing that goes there seems to come out !!!

And so when I read this - I thought I am glad I am on the journey to consume more meaningfully.

500 unread mails, 2K unread articles, 5K unread posts – I am drowning

But I realized I had completely forgotten learning this lesson once before -

Infinity Redefined