5 Simple Steps for code review:

1. Correct:

Does the code do what it’s supposed to?

Does it handle edge cases?

Is it adequately tested to make sure that it stays correct even when other engineers modify it?

Is it performant enough for this use case?

2. Secure:

Does the code have vulnerabilities?

Is the data stored safely?

Is personal identification information (PI) handled correctly?

Could the code be used to induce a DOS?

Is input validation comprehensive enough?

3. Readable:

Is the code easy to read and comprehend?

Does it make clear what the business requirements are (code is written to be read by a human, not by a computer)?

Are tests concise enough?

Are variables, functions and classes named appropriately?

Do the domain models cleanly map the real world to reduce cognitive load?

Does it use consistent coding convention?

4. Elegant:

Does the code leverage well-known patterns?

Does it achieve what it needs to do without sacrificing simplicity and conciseness?

Would you be excited to work in this code?

Would you be proud of this code?

5. Altruist:

Does the code leave the codebase better than what it was?

Does it inspire other engineers to improve their code as well?

Is it cleaning up unused code, improving documentation, introducing better patterns through small-scale refactoring?

Amazing tiny tools I use {More to be Posted soon}

1). ngrok

This tool exposes your localhost to the outside world.

For Example: http://localhost:8080/webapps/amazeme/index.html is your application working locally. When you’d want to quickly demo it your PM/BA or someone else not over the firms/organizations VPN, then that’s where ngrok helps your application available to the outside world by tunneling thru your firewall.

Simply download ngrok script from ngrok.com specific to your OS. Using terminal/cmd promptI cd to the directory where it exists (I would recommend to move that script to the bin directory on MAC (if using Windows, set the environmental variables) to easily identify and work with ngrok) and then simply type in

ngrok http 8080

This now exposes (both secured and non secured urls) your localhost to the outside world using ngrok’s internal tunneling mechanism. You can learn more about it here.

So you can test your application  http://{alphaNumericTextFromTheTerminal}.ngrok.io/webapps/amazeme/index.html

2). tmi (too many images)

Discovers your images that needs improvement both on Mobile as well as Desktop.

npm install –global tmi

Installs tmi

tmi rakeshchouhan.com

Gives the Image Weight Summary both on Mobile and Desktop.

tmi rakeshchouhan.com –verbose

Gives detailed information of Images that needs to be Optimized. The list does not include the images which cannot be optimized further.

3). nslookup, ping (on Mac & windows), tracert, nbtstat (on Windows only).

nslookup rakeshchouhan.com

Gives the ip of the domain.

nslookup {ipFromAbove}

Gives information of the registered domain where rakeshchouhan.com was hosted.

4). tree

Get the dependency of each and every node_modules that has been installed (/usr/local/lib/node_modules).

Installing the tree:

There are several Package Managers available to install a package. The most used are below

brew install tree
sudo port install tree
fink install tree

Here you find the list of available package managers for each operating system

https://en.wikipedia.org/wiki/List_of_software_package_management_systems

To know where the node modules are installed in your system

npm config list      // Check for cwd attribute

Then,

cd /usr/local/lib/                    // Change directory to the parent of node_modules
tree -d node_modules        // Gives the dependency on each installed node_modules

tree

 

What is tinyurl all about ?

I was asked this interview question for SomeCompany in NY Bethpage.

Well, I said I do not know how it works, but I know what it does.

Why is this so important at all? Why do you want to know this?

This is important because it evaluates your core computer science Data Structures and Algorithm skills.

As you all know what it does, it takes the long URL (Uniform Resource Locator) and converts it to a short URL. I know there would be at-least couple of questions in your mind.

How does the browser know to navigate to the long URL when a short URL is browsed?

Ans: When a short URL is generated by the tinyurl website, with a unique identifier, the browser, hits the registered tinyurl domain and it then redirects the tinyurl to the long URL with a UNIQUE IDENTIFIER.

How does the tinyurl.com website generate the tinyurl for the give long URL? In other words, how is the Unique key being generated and how does the browser recognize the long url with its respective identifier?

Ans: The interviewer wasn’t really keen in the above Q & A, but instead he was more interested in this one.

There are 3 ways to do so.

Good Way..

Given a URL, a Alpha-Unique key can be generated by using some programatic function such as Math.random() and associate with the URL, and store it in the DB as key-value pairs. If the URL is already present in the DB, then do not call the Math.random(), instead just return the same URL as a key-value pair.

Problem:

The problem with this approach is there are 2 overhead operations. First is check if the Unique key that is programmatically generated, already exist’s in the DB, and the other is creating a Unique ID using Math.random() if it doesn’t exist. DB table lookup is a expensive operation. You have to search a key (for its existence) in the entire table. Nevertheless, you can increase the speed of the table search by indexing the column.

Better Way..

The other way to solve this problem is by not using any programatic functions to create a Unique Index. Let the DB do this job for you. The DB table will create a unique alpha numeric id for each entry of the requested tinyurl. You can then index the unique id column for faster retrieval.

Problem:

The problem with the above approach is you still have to call the DB, which is an expensive operation. Now the question that would have come to your mind. What is the possible way that you could generate a unique identifier. ?

Best Way..

Have you ever heard about encryption and decryption ? May be about MD5 or CRC ? Or about 2 way Hashing algorithm ? If so, then you are a rockstar. Well for those who are unaware of these concepts, it is important to know it. Given a key (long URL), the md5 hashing algorithm will encrypt/generate a unique value (short/tinyurl). When this unique value is decrypted, it will return you the original key (long URL). It always returns you a unique value (tinyurl) no matter what long URL you ask for.

Problem:

There is no major problem as such, which was discussed above. You can create your own encryption/decryption hashing algorithms. Ensure that there you properly garbage collect unreferenced objects in your code. Always keep in mind about performances.

I hope you’ve enjoyed my post.

More Learning:

https://stackoverflow.com/questions/1562367/how-do-short-urls-services-work
https://www.educative.io/collection/page/5668639101419520/5649050225344512/5668600916475904