Kicking out Task One — HPDF

xXAlphaManXx
xXAlphaManXx
Published in
3 min readDec 8, 2017
A part of my code — Shows how clean the code is :D

The introduction — As usual

So long ago, not long ago Hasura and IIT collaborated to bring out an awesome course that pulls down even a I-don’t-know-what-a-computer-is person to I-am-a-computer-nerd person. They teach you to build Android App and connect it to a server which is backed by Nodejs. The course was called IMAD (Introduction To Modern Application And Development).

After the course, students can write an exam and the top 5% will be selected to work on an Internship conducted by Hasura which was called Hasura Product Development Fellowship. You can know more about it by clicking on that link. And, the most important part? I was selected in that. Yay!

What happens inside HPDF?

Well, here comes the interesting part. All eligible students are requested to join the Hasura’s slack channel (sorry — no link for that) so that each other can collaborate. We were provided with a task for the first week. I was allocated with the Nodejs-express which was what I wanted. Hurahh! Students can ask doubts, get help and yeah, they can help each other. Everyone was on fire when the first task was released. The slack was overwhelmed with responses and codes.

Now, the part you wanted — CODING!

Even though I am 15 years old (yeah, promise) I had 1 year experience in building things. I had a very good knowledge about PHP(laravel). Importantly — I felt I was more better at hacking things. I used to hate Nodejs just because it’s async feature always used to give me undefined error. But, it was this course that really pulled me on top of this. I am now confident over Nodejs too. And know what, Laravel (PHP) and Nodejs go well together.

The task at first seemed really easy for me. I did everything in just 5 minutes (yeah, I swear) except the 2nd sub-task. The 2nd sub-task used an API which had list of users and the another API that had a list of posts created by the users. The `userId` in the posts API corresponded to the id in users API. Now, we had to take data, process in such a way that list of users and the number of posts created by user must be shown — one line for each author.

This is how I made it — No styling 😂

I started wasting my time thinking really overcomplicated ways to get the data collected and processed. Yeah, I did finish this sub-task but this single feature had ~238 lines of code. I was like ewww. Then I drew a mind. Suddenly I started to laugh. The relationship was way easy. I got a new idea. I used a library called Lodash to pluck only the posts that corresponds each of the authors. And you know what I did that job and the code for this finished in just 5 lines. I’ve nearly eliminated 233 lines of code and the script response time went way low towards 98 milliseconds (excluding the time took to make API calls)

I was really happy with what I had done. The whole task was finished in just one hour. It just took that knack of time or else I would’ve done that in 10 minutes.

The conclusion — not that of bahubali

After a lot of testing, I found out that the average response time of my application under localhost was 92.76 milliseconds. When hosted in Heroku, the response time was 103 milliseconds (includes my network latency). Thus, I can proudly say that my application is fast and promised to do what is had to. The whole application was programmed in just a whooping 64 lines (seriously yes).

I hope someone finds this useful. I will reply to queries as soon as possible. You can find me at slack (xXAlphaManX) or at twitter @xXAlphaManXx.

And hey, some claps would really appreciate me in writing more blog. I would love that kind of motivation. So how much you would give? 10 or 20 or more? It’s your choice.

~ xXAlphaManXx

--

--

xXAlphaManXx
xXAlphaManXx

Developer, designer, system engineer. What more should I write?