What the heck is “!!” and “??” in Kotlin

One of the first things that I found as I am starting my process of converting to Kotlin is the single and double exclamation mark “!” and the single and double question mark “?”. The first thing I thought about was, “mmmm, i think i have seen this some where before and I am like aha! I saw this in Swift” Swift has something like that too, the question mark “?” and the exclamation mark “!”. Where you tell the system that null is expected or not expected. I have not used Swift for sometime but this was awesome to have so that you can avoid null pointer exceptions while running your app. The last thing you need to know that some one places a 1 star review on Google Play Store that your app is “crashing”! To be honest, I was feeling jealous that Swift developers had this kind of advantage over android developers. There are many things that I feel they have more advantages but let’s not go too deep now!

Of course Java does not have this ! However it can be done using @Nullable annotations. So you need to use this annotation anywhere you have to use it to declare a variable or object that it can be Null. You know what, I liked the fact that now in Android development you can use the !! or ?? marks which is cleaner and comes inline with the code.

The Null Pointer Exception has been one of Kotlin’s top priorities in order to overcome Java and to convince developers to convert to Java.

Two Number Sum (optimized from O(nlogn) to O(N))

One of the most famous interview questions that you can expect to get in your next interview: Two Number Sum, and that given a non-sorted array, find 2 numbers that make a given sum. So, for example given an array: [10, 3, 2 , 9, -1, 8, 13], sum: 7, should give an output of [-1, 8]

One way to solve this problem is to sort the array first and then have a Left and Right pointers and iterate the array in 1 run. The code for this approach is as below:

The above approach will cost us O(n log n) time and O(1) space. That is because of the initial sort that we have done and that is why we have O(n log n) time.

If we try to optimize it then there is a way that we have to give up O(N) space in worst case and that is by using a HashMap and track the numbers while we iterate through the array in one go. The HashMap will obviously be using O(1) time for each check.

The Fibonacci Problem

The Fibonacci problem is the first thing you will hear about in any Dynamic Programming lecture or chapter (maybe not!) You can solve this problem using recursive iteration but that would create a lot of stacking in the memory. A lot of these stacks (sub problems) are reputations. For example the Fib(6) = Fib(0) + Fib(1) + Fib(2) + Fib(3) + Fib(4) + Fib(5) + Fib(6). If we look at Fib(4) & Fib(5) then you will see that they both have one in common and that is Fib(3) and Fib(2). So in the following algorithm we basically skip the Fibs that already have been calculated by just memorizing them in some variables (a & b). So instead of O(2^N) time complexity we do it in O(N) time. and O(1) space.

Balanced Brackets “{()}()” algorithm

This is a very common interview question and I personally faced it before on a technical phone interview with one of the top 5 tech companies in the world! The concept is easy but tricky. You need to use a stack and a HasMap to solve it. The stack is simply an array but you need to know what to store in it and how to pop items from it. The HasMap will store all the brackets and their adjacent matching closing vs opening brackets. So the idea is just to add a closing bracket when you see an opening bracket and when you see a closing bracket then you need to pop out a closing bracket from the stack. If at the end you see the stack is not empty then your string has a wrong brackets string.

Install VSCode on Arch Linux

I will make it straight forward just these steps and you are done:

Letsencrypt SSL certificate on a Linode server with Nginx and NodeJS installed

Working on backend APIs using NodeJS is fun and really smooth as you can see yourself done a lot in less time than you could imagine. Being a frontend and mobile app developer its kinda weird when you work on backend APIs. Its a different concept for certain extent. While I was working on a project I decided let me do the backend myself. It was a learning curve but it was fun to learn Nodejs. So, developing an API is something that I have been doing for a while. Putting that API in production was not something that I have done before. Here comes the challenges!

I decided to install one of these APIs myself on a http://linode.com cloud server. I had many other options like digitalocean.com and AWS but I said let me support a philly startup since I am living 1.5 hours away from them.

While trying to install the server I came across the SSL certificate installation. You usually need one for any API so I had to either buy or just use an open source one. Of course I did not buy one since i could get it for free! Letsencrypt.org provides a free certificate that you can easily install by yourself on your linux server.

After going through their documentation and a couple online resources, the I have installed the ssl certificate successfully for the domain name. One of the things that I have faced and could not run it and when I turned the API Nodejs server on , all the other websites stopped. So the problem was that I was configuring both ports 443 and 8080 for the nodejs server and also for the other domains that were installed on the same sever. I spent a whole day trying to figure out what was wrong. Finally it was that when you run a nodejs api server then that by itself a web server and being accessed through the http protocol. My problem was solved after removing the node server’s configuration that has been done on nginx web server which hosted all the other domain names that I had. So, if you have a port 443 reserved for the nodejs SSL protocol then you can’t use the same port for any other nginx or Apache web servers.

Espresso Coffee Makers

I am  a coffee addict and I really am into two kinds of coffee and I think anything other than that is just not coffee (that’s my opinion).

Espresso is a type of coffee that really gives you the true flavour of the coffee since it is so pure and so dense by the way it is prepared. However, the kind of bean also plays a big role. Starbucks are one of the best but if you like something good and try to save some money then the Cafe Bustelo Ground Espresso Coffee can be found in Wallmart.com.

You will need a good reliable coffee maker for a good espresso or late to make at home. Those machines for some reasons cost a lot if you try to get a professional or semi-professional one. However, I my self have a long time experience with the DeLonghi EC155 it does the job for 1 to 2 late per day with out any trouble. 

Lancaster PA’s Amish Dutch Country

If you ever wondered what and how the Amish people live then Lancaster PA is the right place to visit. The Pennsylvania Amish of Lancaster County are America’s oldest Amish settlement, where thousands still live a centuries-old “Plain” lifestyle. They are the most conservative and peaceful people you can ever meet. Arriving in PA Dutch Country allows you to step back in time to enjoy a slower, more peaceful pace – one where the horse & buggy remains a primary form of transportation, and where windmills dot the landscape, providing power harnessed from nature. The Amish people are hard workers. I guess they are the only people you can hardly see use the government food stamps or any kind of support. Always a vital part of Lancaster County culture, the PA Amish are involved in agriculture as well as an array of businesses and cottage industries. Also one thing you will never see an Amish uses a phone! neither a computer. They have their own schools, so no one studies computer science neither management. However, they are successful business people. If you ever visited Lancaster PA, make sure you pay good respect to their privacy! i know this sounds weird but, they don’t like to be in your photo gallery! neither on your instagram profile pictures.

Here is a link to where to go in Lancaster PA and to discover the Amish culture.

The main classes related to the use of sensors on the Android platform

1.Sensor: Provides methods to identify which capabilities are available for a specific sensor.
2.SensorManager: Provides methods for registering sensor event listeners and calibrating sensors.
4.SensorEvent: Provides raw sensor data, including information regarding accuracy.
5.SensorEventListener: Interface that defines callback methods that will receive sensor event notifications.

Hummus as a Healthy Snack for programmers!

This blog post is specially written for James Montemagno the guy behind Xamarin! This is the only way i could explain just like any other programmer! If you could really end up making a good Hummus then you are a programmer otherwise you can google for “Hummus Recipes”

Hummus is basically chick peas paste! Origins? you can debate on that part like any other food’s origins where people take it so religiously! For some people Hummus is just a side dish and for some it is like using using Mac or PC! I think like any other traditional meal I take it so personal and i can tell if a hummus is done by a professional or not. Lets stop talking Hummusolophies and dig into coding this bad boy:

I tried maintaining clean code but I think i need to read Uncle Bob’s clean code book again…

Try Hummus as a snack with pickles and pitta bread. enjoy…

Check if Tree is a Binary Search Tree

A Binary Search Tree is the tree that the key in each node must be greater than or equal to any key stored in the left sub-tree, and less than or equal to any key stored in the right sub-tree.

Binary Search Tree

Binary Search Tree

source: wikipedia




Detect a Cycle in a Linked List

This is one way of how to detect if a Linked List is a cyclic or not. The basic idea is to make 2 pointers to the head and then make one of them move slow (one hop at a time) and the other move faster (2 hops at a time). They will be in a loop until they collide which means there is a cycle!


Do we need to know Algorithms as programmers?

There are two different kinds of programmers. The ones who went to school and spent some years learning skills like science, maths , physics and algebra, and there are others who learned “coding” to do their day to day jobs. The second group are most likely like learning stuff by themselves, and did not have the opportunity to go to school. Algorithms are done at school most of the time and most of the classes used some kind of programming languages to teach algorithms.  That doesn’t mean that self taught programmers don’t know about them but these things can be learned from the books.

When it comes to hiring software engineers from a pool of many skilled and junior applicants, some these skills (algorithms) are counted in most places. That does not mean that you will be using algorithms in your daily front end JavaScript job. Some take it as a deep learning of computer science.

So, is it important to know it? yes it is but you can also get a job without them. However, the top 5 silicon valley companies for sure will ask about the algorithms. As a software engineer, i think you should know and have a good knowledge about them.

At the end , algorithms are there to make things better, and when it comes to technology, we talk speed/time and space. Whats the best way and more effecient way to solve a problem. So, yes whatever you do in the tech industry and wherever you are coming from, you need to know the basics of the Big O and other algorithms.

There are companies that made it to the market just because they had smart people to create great algorithms to transfer bits from point A to point B.

Do we really need that many Programming Languages?

I think from the day I started learning to code (age 10 i guess) and then studying Computer Science until this day there were so many programming languages came to live. We were so naive thinking that all what we need to learn is C++ or Java with some SQL and that’s it. Then we had to learn VB and then they said now its gonna be VB.NET and ASP.NET with a new thing called C# and the list just goes on.

Do we really need these many languages?

These days what even makes it worse that within the same languages there are different versions that you can’t even compile. Swift 2 and 4 are different within the iOS development. Its just like people just started to become proficient in a language and then they just need to learn some thing new because the guys in the Silicon Valley thought they needed to add new stuff or change the way things were programmed before. Java in my opinion added libraries which did not affect the language but were like been steroids injected in it making it more heavy weight !

Just came to know Google launched something called Flutter by Dart for cross platform mobile development! come on… give me a break!