Comment your Rust Code

Introduction

This post explains how to properly comment you Rust code.

Add Documentation to your Public APIs

/// This is a documentation comment

Documentation comments can be used to generate public HTML documentation. So these are ideal to document your public Structs, Methods and Functions. Also Documentation support markdown formats. Explain Panics, Errors, Examples of your code and whether your code is Safe or Unsafe.

Cargo runs your Doc Examples

To ensure your code is up to date, Cargo test will run examples in your documentation. This is really awesome.

Use Regular Comments for Code Internals

// This is a regular comment

Use regular comments to describe your code’s internals. These would not be included in the generated HTML file.

Advertisement

Machine Learning – a 10 minutes overview

What is Machine Learning

Vast number of programming problems can be solved by writing a set of well defined rules. Some problems are very complex it’s either we can’t define a clear set of rules or there are huge number of rules that it is impossible to manually codify those rules. A very good example is Speech recognition.

Machine Learning provides us technology so we can teach computers these rules provided a set of labeled data (training set) and extend them to a general set of data that were not seen in the training set.

Categories of Machine Learning

Supervised Learning

Goal of Supervised Learning is to predict the output variable from a given input variable. So for supervised learning, we need a data set with labeled output variables to train our machine learning function. If output variable is a category, it is Classification Problems. The functions we learn to solve these problems are called Classifiers. If output is a real value, it is a Regression Problem. Function we learn is called Regression Function.

Unsupervised Learning

Main goal here is to find some structure in a input data set. This involves,

  • Find clusters of similar data
  • Outlier detection

Machine Learning Workflow

Machine learning workflow mainly consists of three components.

Representation

This involves representing your problem in such a way that a computer can deal with it. So you have to extract a set of features from your input objects. Extraction most relevant set of features from your input objects is called Feature Extraction or Feature Engineering. Next part of the problem is choosing an appropriate machine learning methodology for the problem.

Evaluation

You need to have a framework to evaluate the accuracy of your ML algorithm. We usually set aside a set of test data for this.

Optimization

After evaluation step, you may find some improvements you could do. Such as choosing a more appropriate algorithm or extracting more relevant features.

 

Usually you have to iterate through above described steps before you can find an optimal solution for you problem.

How to Pass Google Phone Screen

Introduction

A few years ago, I managed to successfully pass the Google online coding test. It was extremely challenging. In this blog, I explain how I prepared for it.

Purpose of the Coding Test

The purpose of the online coding test is to identify candidates who may do well on the onsite interview. It basically measures how good problem solver, coder you are.

Exam / Test

You can use most of the popular programming languages (like Java, C++, Python, Ruby…). You will be talking to an interviewer throughout the test. Test usually last for about an hour. Given the time spend for introductions, coding part lasts for about 45 minutes.

Through out the exam you will be talking to an interviewer. Usually he would start with an simple coding question then add more and more complexity to it as you progress. You will be using google docs for coding.

Preparation

Brush up your knowledge on data structures and algorithms. Cover all basics.

Data Structures

  • Stack
  • LinkedList
  • Queue
  • Arrays
  • Heap
  • Binary Search Trees
  • Hashing

Algorithms

  • Sorts – Merge Sort, Quick Sort, Heap Sort, Topological Sort
  • Search – Binary Search
  • Tree Traversals – DFS, BFS, Inorder, PreOrder and Post Order

Do not waste your time looking at too complex data structures/algorithms. It is very unlikely you will get a complex problem given the time limitations.

Learn to Calculate Time / Memory Complexity

You are usually asked to provide the time/memory complexity of your code.So brush up how to calculate this on a code. Also try to remember time complexity of above classic algorithms.

Recommended Readings

I highly recommend you to invest on Amazon best seller Cracking the Coding Interview: 189 Programming Questions and Solutions book.

This book covers all the algorithms, data structures that needed for your interview. It also covers Time and Memory complexity calculations. It briefly goes through the interview structure of the each big company like Google, Amazon and Facebook. This book also has lot of practice questions with solutions. Book is not cheap. But a very little investment considering that it will help to get in Google.

Practice Practice Practice

The practice is the key. Do as much as practice questions you can. If you buy above book, you try the practice questions of the book. There are several online web sites like Leetcode which provide practice algorithmic questions. Make the best use of them.

During the Test

Don’t Rush In

Don’t jump into solving problem too quickly. Questions are bit ambiguous; this is on purpose. So discuss the problem, ask questions to clear out any ambiguities you may have.

Think Out Loud

Also keep a good communication with the interviewer. Speak out your thought process. If you can think of several solutions to solve the problem, discuss them with the interviewer. Tell him which is the best solution and why you think it is. Also,  you can access the internet during the exam.

Write Good Code

This is the first time Google is going to see your code. So try to give the best first impression. Follow basics; use meaningful variable/method names, move the redundant code to functions. Try to create classes instead of using complex collections. Try to output the best industrial level software you can.

Do not Brute Force

You may be tempted to solve some problems by brute force. But this will not raise any eyebrows. Try to provide a code that can do better than the Brute Force.

Finally

Personally, I took about 3 weeks to prepare my self for the coding test. So start early.

//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=d1e624dd-ae12-4858-a5f9-324544f807a6

How to make a Blog Searchable in Google

How to make my WordPress blog searchable via Google? That was one of the first questions when I started my blog.  Here is a very easy way to get it done without meta tags.

Step 1 – Go to Google Search Console

Follow this link

Step 2 – Add Property – add the Link of your web page

Click “Add Property” and add the link to your web page.

Screen Shot 2018-08-19 at 8.34.42 AM

Step 3 – Verify the Ownership of your Webpage

Google asks you to verify the ownership of your page, this is where most of us run into problems.

Screen Shot 2018-08-19 at 8.38.43 AM

Step 4 – Get DNS Verification Record

Click “Alternative Method” then select “Domain Name Provider”. You should see the following page.

Screen Shot 2018-08-19 at 8.57.51 AM

You should add this record to your DNS.

Step 5 – Open WordPress Domains Page

Go to your WordPress Admin page. Go to Domain tab.

Screen Shot 2018-08-19 at 10.30.01 AM

Step 6 – Then Select “Name Servers and DNS”

Screen Shot 2018-08-19 at 10.30.33 AM

Step 7 – Then Click on “DNS Records”

Screen Shot 2018-08-19 at 10.31.39 AM

Step 8 – Add Google Site Verification Code as a Record

Screen Shot 2018-08-19 at 10.32.45 AM

Step 9 – Verify it on Google

DNS record instantly takes into effect. Go back to Google Search Console and click on Verify.

Screen Shot 2018-08-19 at 8.38.43 AM

We are very responsive. Feel free to ask question/leave suggestions.

 

IELTS Tips

ielts

IELTS is a quite easy exam to pass, provided that you have prepared your self well for it. In this blog I am explaining what I did to ace the IELTS exam with less effort.

Step 1 – Find an Institution

There are several well-known institutions. Choose one which is conveniently located for you. It’s really a personal choice.

Watch out!!!

When you reserve the test, do not mention your real purpose of taking the test. They typically to set higher standards for people who take it for immigration reasons. There is no reason for IELTS institution to know why you are taking the exam. Just specify that you are taking the exam for a personal reason. If they compel you to give a reason, it’s best to go with a different institute.

Step 2 – Schedule a Test

Seriously, book your test, at the very beginning. Here are the reasons why should you do it.

  • There will be a long wait list. Typically 3 – 6 weeks
  • It will give the motivation to get committed to studying. It’s harder than you think to find time to study when there is no deadline

Know Your Exam

Check whether to take an Academic or a General exam. If you are doing this for a PR application, you should take the General module. For university applications, take the Academic exam.

Know How Much You Have to Score

Know how many points you need. This will help with time management.

Step 2 – Study

Personally, I spent 3-4 weeks preparing for the exam. IELTS exam comprises of 4 parts.

Reading

The exam takes about 50 minutes. You have to read a few articles and has to answer some questions. Cambridge University has a book with IELTS pass papers. Get a copy and do practice past papers. One trick I learned is to read the question once before you start reading the paragraphs. This really helps to save time.

It is very easy to waste lots of time here trying to perfecting your score. If all you need is a 7, why study for a 9. Save your effort/time for other areas.

Listening

During the exam, you will listen to some dialogs and answer some questions. Similar to Reading taking some pass papers should suffice. Don’t waste time perfecting your score.

Writing

During the exam, you will be asked to write one letter/memo and an essay. Do a few Cambridge pass papers. Find “IELTS Training modules by Adam Smith” for writing. Follow this module do some of its exercises.

Speaking

You will have to talk with an interviewer during the exam for about 15 minutes. First, you will have to speak a few minutes on a given topic, following a few minutes of general conversation on the same topic. Again follow IELTS module of Adam Smith provide which some great tips to get a high score for this exam.

Step 3 – Know How to Spend your Efforts

Here is how I spent my efforts during my IELTS preparation.

Reading – 15%

Listening – 15%

Writing – 45%

Speaking – 25%

Step 4 – Go for the Exam

Be there on time, bring your ID – the usuals.

We are very responsive. Feel free to ask question/leave suggestions.

How to Pass Google Phone Interview

Introduction

A few years ago, I managed to successfully pass the Google online coding test. It was extremely challenging. In this blog, I explain how I prepared for it.

Purpose of the Coding Test

The purpose of the online coding test is to identify candidates who may do well on the onsite interview. It basically measures how good problem solver, coder you are.

Exam / Test

You can use most of the popular programming languages (like Java, C++, Python, Ruby…). You will be talking to an interviewer throughout the test. Test usually last for about an hour. Given the time spend for introductions, coding part lasts for about 45 minutes.

Through out the exam you will be talking to an interviewer. Usually he would start with an simple coding question then add more and more complexity to it as you progress. You will be using google docs for coding.

Preparation

Brush up your knowledge on data structures and algorithms. Cover all basics.

Data Structures

  • Stack
  • LinkedList
  • Queue
  • Arrays
  • Heap
  • Binary Search Trees
  • Hashing

Algorithms

  • Sorts – Merge Sort, Quick Sort, Heap Sort, Topological Sort
  • Search – Binary Search
  • Tree Traversals – DFS, BFS, Inorder, PreOrder and Post Order

Do not waste your time looking at too complex data structures/algorithms. It is very unlikely you will get a complex problem given the time limitations.

Learn to Calculate Time / Memory Complexity

You are usually asked to provide the time/memory complexity of your code.So brush up how to calculate this on a code. Also try to remember time complexity of above classic algorithms.

Recommended Readings

I highly recommend you to invest on Amazon best seller Cracking the Coding Interview: 189 Programming Questions and Solutions book.

This book covers all the algorithms, data structures that needed for your interview. It also covers Time and Memory complexity calculations. It briefly goes through the interview structure of the each big company like Google, Amazon and Facebook. This book also has lot of practice questions with solutions. Book is not cheap. But a very little investment considering that it will help to get in Google.

Practice Practice Practice

The practice is the key. Do as much as practice questions you can. If you buy above book, you try the practice questions of the book. There are several online web sites like Leetcode which provide practice algorithmic questions. Make the best use of them.

During the Test

Don’t Rush In

Don’t jump into solving problem too quickly. Questions are bit ambiguous; this is on purpose. So discuss the problem, ask questions to clear out any ambiguities you may have.

Think Out Loud

Also keep a good communication with the interviewer. Speak out your thought process. If you can think of several solutions to solve the problem, discuss them with the interviewer. Tell him which is the best solution and why you think it is. Also,  you can access the internet during the exam.

Write Good Code

This is the first time Google is going to see your code. So try to give the best first impression. Follow basics; use meaningful variable/method names, move the redundant code to functions. Try to create classes instead of using complex collections. Try to output the best industrial level software you can.

Do not Brute Force

You may be tempted to solve some problems by brute force. But this will not raise any eyebrows. Try to provide a code that can do better than the Brute Force.

Finally

Personally, I took about 3 weeks to prepare my self for the coding test. So start early.

//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=d1e624dd-ae12-4858-a5f9-324544f807a6

How to Pass Amazon Onsite Interview

Introduction

Before you can sit for the onsite exam, you must pass the amazon coding interview. Please check this blog on how to pass the amazon coding test.

I was able to successfully pass the Amazon exam in my second attempt. It was a very challenging and refreshing experience. In this blog, I am sharing what I did to prepare for the exam.

Interview Structure

The on-site interview has four separate interview sessions, done by four individual interviewers. Each interview should take about 55 minutes.

Out of four interviews, three will be algorithmic questions. One will be a system design question.

Algorithmic Questions

For Algorithmic questions, you will have to write your code on a paper or on a whiteboard. You can use any programming language. You will have to provide the runtime and/or memory complexity of your program. You will have about 40 minutes to finish your question. If you complete it early, the interviewer may ask you a second question.

Design Question

Same goes for the design question. You have to draw the design diagram on the paper/whiteboard and explain your question to the interviewer. Similarly, you will have about 40 minutes to complete the question.

Leadership Questions

Amazon is very serious about its leadership principles. At the end of each interview, you will be asked some questions about Amazon Leadership Principles. This will take about 10 – 15mins.

Preparation

Algorithms

Basically, follow the same set of preparations that I described here for the coding exam.

Since you won’t have IDE support during the interview, you will have to prepare for it as well. Trust me this is important. When you do practice questions do them on paper. Don’t worry about small mistakes on language syntax. But try to output the best industrial code you can.

Same principals as online coding interview applies. Use meaningful variable names, try to come up the with best code structure you can.

Design Question

Design question can be very challenging because of the ambiguous nature of it.

These questions can be of two flavors. Either it can be a very high-level question like “Design Netflix”. Or it can be quite a low-level question like “Give me a class diagram for a Table”. So either you are designing a complex system with high granular modules. Or you are designing a very simple system with very modules with low granularity.

To prepare for this exam again you have to practice a lot. Do sample amazon design questions available online. Try to glance through SOLID Design principles. Key to pass this interview is to be able to justify your design trade-offs to the interviewer. You don’t have to present your solution with AWS, or any cloud solutions for that matter. Use whatever technologies you are familiar with.

Leadership Principles

You can read about the leadership principles here. Read each one of them and try to absorb the essence of every principle. Then try to think about your past experiences where you had to apply these principles. I recommend you to prepare two examples for each of the leadership principles from past experiences.

Preparation Resources / Books

Like I have recommended in my other post, I highly recommend you to invest on Amazon best seller Cracking the Coding Interview: 189 Programming Questions and Solutions book.

This book covers all the algorithms, data structures that needed for your interview with complexities and it has 189 practice questions. Book is not cheap. But a sound investment considering that it will help to get to Amazon.

Looking for a free book??

If above book is too expensive, an alternative book is Coding Interview Questions. This is not as good the first book, but gets the job done. You can read this book for free for 30 days if you register for Amazon’s Kindle Unlimited Membership Plan’s free trial period.

During the Interview

Think Out Loud

Always maintain good communication with the interviewer. Ask questions regularly. Also, try to think out loud. Explain your thought process to the interviewer. For a particular question if you can think of two or three solutions, explain all the solutions to the interviewer. And tell him what you think the best solution and why.

Make Assumptions

Questions can be ambiguous – sometime on purpose. Clarify ambiguities with the interviewer. You may be able to make some assumptions to simplify the problem. If you are going to make any assumptions, clearly state them.

Use Language Provided APIs

You can use any language-provided library for the algorithmic questions. This is highly encouraging because it saves your valuable time. But if you are going to use any API / Data structure, you should be able to explain the inter-workings and complexity of them to the interviewer.

Leadership Questions

For leadership questions, you will be asked about one of your past experience. And you will be asked lots of questions from different angles of the situation. It will be very hard to maintain a lie; so be honest and truthful.

One Screw up Doesn’t Count

Also, all interviewers have a vote on you. So if you screw up one interview, don’t give up. Give your best shot to remaining interviews.

Other Recommended Readings

https://www.linkedin.com/pulse/20141120061048-6976444-ace-the-coding-interview-every-time/?trk=mp-reader-card

//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=d1e624dd-ae12-4858-a5f9-324544f807a6

How to Pass Amazon Online Coding Test

Introduction

Recently, I was able successfully to pass the Amazon Online Coding test. I was an amazing experience that pushed my mental strengths to the limit. In this blog, I am going to explain what did I do to successfully pass the test. Let’s start with the test structure.

Test Structure

The purpose of the online coding test is to identify candidates who may do well on the onsite interview. It measures the problem solving skills and coding skills of the applicant. Also it has some questions to measure you against Amazon Leadership Principals. You’d be taking the test on a online code pad tool. You can use most of the popular programming languages. You can go to the tool and get familiar with the features before attempting the exam.

Test has two coding questions. First question is easier than the second. You will have 90 mins to complete both questions. Once you’ve submitted the code, you will get some MCQ questions about Leadership Principals. These questions is not timed, you can take as much as time you like.

Preparations

Let’s see how to prepare for the tests. Brush up your knowledge on basic data structures like Stack, Linked List, Queue, Heap, Binary Search Trees, Hash Tables and Graphs. Sorting and searching are the most popular questions in test. So brush up your knowledge on Merge Sort, Quick Sort, Heap Sort, Binary Search.

Tree traversals are also important. Read up on DFS and BFS. Cover all three traversal models pre Order, in Order and Post order. Study Prim’s and Dijkstra’s algorithms for graph traversal. Also read about Divide and Conquer and Dynamic Programming.

You usually asked to provide the time/memory complexity of your code. So study how to calculate it. Also try to remember time complexity of classical algorithms.

Recommended Readings

You could study by your self. But I highly recommend you to invest on Amazon best seller Cracking the Coding Interview: 189 Programming Questions and Solutions book.

This book covers algorithms, data structures needed for the test. It explains how to compute time and memory complexities. Very importantly it has 189 practice questions. Book is not cheap. But a sound investment considering that it will help to get to Amazon.

Looking for a free book??

If above book is too expensive, an alternative book is Coding Interview Questions. You can read this book for free for 30 days if you register for Amazon’s Kindle Unlimited Membership Plan’s free trial period. You don’t even have to have a Kindle. Just log in to read.amazon.com and start reading.

Practice Practice Practice

Practice is the key. Do as much as practice questions you can. Try the practice questions of the book if you have it. Also there are several online web sites (like Leetcode) which provide hundreds of practice algorithmic questions. Make the best use of them.

During the Exam

You can access the internet during the exam. You are allowed to use your own IDE. But the risk is if you couldn’t copy paste your code on time, you will loose everything.

Time is Precious

50% of the exam is about time management. Two questions are hard enough to make it difficult to finish both within 90 minutes. If the first question is the easier one, don’t waste too much time on it.

If you are running out of time, prioritize the important bits of the algorithm. For example, if you are going to implement a sort, you should prioritize the Comparator since it’s going to be to the core logic of the program. To have any chance to pass the interview, you should at least have something to show for, for both questions.

Write Good Code

This is the first time Amazon is going to see your code. So give the best first impression. Follow basics; use meaningful variable/method names, move the redundant code to functions. Try to create classes instead of using complex collections. Write comments where needed. Try to output the best industrial software you can.

Do not Brute Force

You may be tempted to solve problems by brute force. But this is highly dicoraged. Try to provide a optimal solution than the Brute Force. Having 60% completed code of the optimal solution is better than a 100% working code of the  brute force solution.

Leadership Questions

After coding questions, you will have to answer a questionnaire which evaluates whether you are a good cultural fit for Amazon. Try to be your self and answer honestly. If you and company are not going to be a good match, it’s going to be a bad move for both the parties.

Finally

Don’t trust the tool too much save your work continuously as you progress. I took about 3 weeks to prepare my self for the coding test. Try to start early as possible.

Finally Good luck!!!
 

//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=d1e624dd-ae12-4858-a5f9-324544f807a6

What are SOLID Principles?

Follow SOLID Principals

SOLID principles are widely accepted set of rules that let you design/implement reusable and flexible Classes and methods. They consist of the following five principles.

Single Responsibility Principal – Promotes Encapsulation

A class/method should have a single, well-defined functionality. They should only contain code responsible to a single actor (of a use case).

Classes and Methods change because the requirements of the actors change. If a class / a method only contain code that is responsible for a single actor, they only have only one reason to change. This is important because different actors have different requirements, which evolves in different phases and for different reasons.

Open Closed Principal – Promotes Abstraction + Polymorphism

Classes (even Systems) you develop should be open for extension and closed for modification. New functionalities should introduce new codes to a system, not changes to the existing code. The modules you design should never change. When requirement changes you should extend and add more modules to change the behavior of the system.

This principle promotes Abstraction and Polymorphism. Your module should be designed on top of immutable abstractions so it never changes. However, anyone can implement different derivations of these abstractions to introduce new behaviors to the system.

Things that change for different reasons and in different rates, should exist in different places in the code. It is impossible to make a system 100% agnostic for all changes. The designer should find the most probable changes and should make the system to be resilient against them.

Find this very interesting paper on the topic – link.

Liskov Substitution Principal – Abstraction and Hierarchy

Any subtype should be directly substituted in place of a supertype reference. This means that a reference of the supertype should be replaceable with a subtype object without breaking the program. For this principle to work, it is essential that subtype does not change the behavior of supertype. The subtype should provide all the features of the supertype, then some extra

Find the research paper here.

Interface Segregation Principle

A client should not be forced to depend on the method that it does not need. This principle enforces splitting large interfaces to several small interfaces.

Dependency Inversion Principle

Abstract modules should contain high-level business logic. Concrete implementations should contain implementation details. When a high-level module needs to call a low-level module, define an interface on the side of the high-level module to invert the dependency.