Adulting

Hello ! Since most of you know I recently started working as a full-time developer, I did write a blog about it too “Makings things count” if you want to read about it, I would link it here.  This is just a life update after five months into the job.

This won’t be a technical blog but moreover some life lessons that I took from people around me. People might think this blog is bit obvious and simple. Yes, these things are simply not but not easy and sometimes in the midst of daily rush we just tend to ignore the most obvious things.

So here are some things that I think everyone who just started out or is about to start his career should definitely think though. If you’re one of them happy adulting 🙂

Get used to being bored: When your free trial of life expires you do have to think about a lot of stuff before making any major life decisions. So most of the time you might find yourself doing mundane tasks just because the output of this task can help you move to the place you want to be in life later, this might your first job that you thought was cool but later turned out just boring or a lazy Saturday afternoon where you could easily binge some x show but instead you are doing errands. The point I am trying to make is that it’s okay if you feel bored. What’s not okay is that you’re not putting enough effort to get out of those boring situations where you have control over.

Improve Daily: People who get used to being bored for the situations they could have avoided or can avoid if they put in enough efforts don’t think of self-improvement much. Committing to even 1% of work daily can help you a lot in the long run than doing nothing daily and to do that you need to build a consistent system in the right environment. This could apply both where you live and where you work. Talking from personal experience the place where you live or spend your time after work matters a lot at least for me because it would be the only time you can spend on yourself to plan out what can be done, actually work on it even it’s 30 min a day to 2 hours a day. Some peacefull work done can do wonders if you do it consistently.

For example, the first place that I use to stay with I shared it with people that I did go along well with but did not share the same ideology was a total disaster for me. Most of the time at home it would be a hard time for me to work on myself with all the nonsense that I had to deal with. Trust me on weekends that would reach over the top, so I eventually decided to live alone it was costly but I did manage but lost all my savings in the process. It but that did not help either though, initial days were okay but it got depressing very soon. Later it became a pain dealing with mentally. Luckily I found a place decent enough with the like-minded people.

So from the past few weeks I have been able to give some time on improving myself, it’s not much half an hour to forty minutes before work and an hour and a half after work. But I bet it would add up to a lot in the long run. Plus hopefully I would continue writing regularly, I have started making notes just to keep up with writing part. Who knows, I might format them properly and with some personal touches put them up as blog posts. For now, they are just markdown file in Github.

Make compound interest your friend: A friend of mine recently told me that savings are like a hole and your income shovel that helps you dig it. I guess he did use that analogy because during some rough time your life it would be that hole that you use to hide and wait in for the rough time to pass. It would be up to you how big of a hole you want to dig so that you can comfortably sit and wait for the chaos to settle down on the surface. I am among the few lucky ones that got to know this at an early stage of my career so that I can start digging my hole however deep I want.

For all the people who are just starting out and reading this, I can’t insist enough more savings. Start saving early. Rest would be taken care of by the compound interest.

Stay Motivated: Small wins and small achievements make big wins learn to enjoy them so you don’t get demotivated or disappointed. Sometimes it’s not you it’s your system so you should always improvise on how you do things in a particular environment and try to build a system around the most productive environment. Your small efforts are not noticeable most of the time, it takes some time before you realize that you are actually doing something good, so just stay keep working 1% every day.

Love your job, not the company:  Recently I read some conversations on #dgplug which made me think, the reason I work is mainly to be better at my job, grow in the field of interest I want to be and to save so I can dig up the savings hole how I want to be because this savings money would not only help me in rough times but would also help me in fulfilling my long term goals that require some large amount of money. If I sucessfully do these three things I would be happy. I can improve my skills by working on them consistently but to move in the right direction I would obviously need an environment where I would showcase my skills hence relevant work and get paid so I can fulfill my dreams plus can constantly increase the size of the hole.

So if you’re shovel is not helping you and you’re getting a better environment somewhere else with a bigger shovel to dig the hole you should take it if it’s possible and you should not put emotions into it.

By this, I am not saying change your job every second month just be curious and clever, improve daily. Just appreciate what you do and do it with uttermost passion.

 

 

 

Making things count

By the end of last year, I graduated and as I like to call it my life’s free trial ended 😛 and starting this week(21Jan,2019). I had my first day of work. Simple things have been complex in the past few months but I guess I survived with a lot of help thanks to good people around me.

So it all started by the last semester by the starting of Feb 2018, I had done a couple of bad interviews and even if the interviews were good I wasn’t confident that I would fit in. Maybe it was imposter syndrome or something else I don’t know. Later by graduation, I ended choosing unemployment and giving some more time to just code random stuff. 😛 The main reason behind writing this blog is to give you the up’s and down’s so you can get a reality check of what’s actually like because I have been talking to some of my college juniors who are now I in the same phase where I was one year back.

Just a bit of background on me to get things very clear from the start, I started coding in Python seriously a bit late like by the start of my third year in college, by seriously I mean like coding daily or maybe looking up small patches in upstream open source projects. I had been active in the local meetup group PyDelhi, ILUG-D and had been introduced to #dplug recently so I wasn’t complete noob in the world of open source tech in general. To put it nicely I was LAZY, I am not proud of it but yeah <pip install regret >.

So the journey started after college by the start of the first of August, I had some family problems in July so getting used to it back home took some time. I had read a lot of blogs about people taking a break and learning to code but most of them were about someone who had not coded in their like and in coming six months taught themselves to code and got a job so could not relate to it. So starting the first two weeks I use to check out the syllabus of coding boot camps and roadmaps for becoming a backend engineer, so here is my first mistake that someone should really avoid while traveling on the same road because once a wise friend of mine said

Life is too small to make all the mistakes yourself sometimes it’s best to learn from others mistakes.

So coming back to the point,

Talk to people even if don’t want to:  I was kinda lucky to have got a college in Delhi because Delhi has some awesome tech communities but when college ended I went back home, Nainital and was missing the meetup culture. I would still talk to people #dgplug, thank god it’s an online community otherwise I would have been completely lost. Even though I use to talk to people I did not actually use to ask for help in figuring things out maybe it was just what these people would think or maybe it was that people would ask me not to do it and get whatever job I was offered ASAP. This changed when I read 6 Bags and a Carton   by very own @fhackdroid . 😛 It was that moment I thought I am lucky and this wasn’t a bad idea. Later when I was staying with him, Sayan, Chandan, Devesh, Rayan during the time of PyCon India 2018 I opened up on what should I do make the most of the time and he with Sayan helped me a lot to make things clear, what should I be focusing on , what projects can I do and also suggested to read resource centre blog of people who took a break and went to Recuruce Centre to work on their tech skills.

So the point I am trying to make is you should talk to some people around in community even before you start planning that would eventually help a lot in making a concrete roadmap for the next x months you take because you would fail a lot, will be diverted and trust me even sometimes question  that you took the right decision or not. During those times it’s best that you have some experienced people helping you out and what I think is if you have concrete roadmap these feeling will be shrunk to a size where you can just ignore and work.

Time is money: I initially planned for an entire year! God knows what I was thinking. This could be because of the first problem I mentioned of not talking to people, but Yes unless an until you have a job waiting for you or you want to focus on something a subpart of a particular topic trim down the time because it takes time to get stable after your gap. In my honest opinion, three months are more than enough unless an until you’re just switching to learn to code and have not written a single line of code or know nothing about it.

Blogging to success: At first, I use to think that what’s the point of blogging when I see all the awesome blogs out on the internet which would be far better than me. But later I realized it’s not about your blog being the best it’s mainly about consistency because what I think is blogging helps in two ways:

1. It helps you structure your thoughts that you can explain to ‘n’ number of people easily.

2. For all the research you do behind the blog you get to learn a lot and that learning sticks for a long time plus you get a backup of your notes to look back.

I would recommend to someone who is talking his off to code/learn/hack/ build silly stuff to at least write a blog once three days.

Document the shit out of it: I was heavily inspired by OBM so I started documenting my daily working habits, I did set goals and future week goals but the problem I faced was I over-engineered the shit out of it which at some point became tedious. I maintained a bullet journal with waka time installed in sublime text to track my coding timings and also was doing short sprints of 25 min each every time I use to sit to code or read. Things got to a downfall pretty quickly because it required a lot of effort to just maintain the whole workflow, I am not saying it’s bad but it wasn’t for me. I did a lot of iterations of the whole bullet journals and found the simplest one to be easy to maintain and easy to follow.

So I would say don’t get sad and totally give up the idea if you’re not able to follow up the whole idea of documentation, just keep evolving the process until it suits your needs because this will definitely help you realize how much effort have you put in the past and how much you have to put in. This trusts me helps in times when you feel like you’re not doing enough work or you made a wrong decision.

One last thing. All the very best, if you’re talking that road just remember to work hard and things will eventually plan out. If it did for someone like me who had no clue, 😛 you at least have a heads up on things.  🙂

Finally, things wouldn’t have been the same without the help from #dgplug and I definitely owe a lot to them.  The people in the community are always ready to help you in a correct manner not spoon feeding you but making you independent. I got a lot of inspirations from different people in the community to work hard , I hope I can follow the same footsteps 🙂

 

Memory Managment in Python – Part 2

In the last part, we checked out how variables are stored in Python and how Python handles memory management with reference counts and garbage collector. If you haven’t checked it out and want to here is the link.

In this part, we will dig deep a little on how reference counting works and how it can increase or decrease taking in account the different cases. So let’s start where we left off, every object in python has three things

  1. Type
  2. Reference Count
  3. Value

Reference Count is a value showing how much an object has been referred(pointed) too by other names(variables). Reference counting helps the garbage collector in freeing up space so the program can run efficiently. Though we can increase or decrease the value of the reference count and can check the value with the inbuilt function called getrefcount().

Let’s take a small code snippet:


import sys

a = []

# Two reference one from the variable and one from the getrefcount() function

print(sys.getrefcount())

2

Though the examples look great and everything seems to be working but I did kinda trick you, first thing is that not all reference count values start from 0 so if you do the same example with a different value of the output may be different. Reference count values are calculated on two factors number of times the object is used in the bytecode and the number of time it’s been referenced to this includes your previous programs too.

Let’s look into another example:


import sys

a = 100

print(sys.getrefcount(a))

4

b = 100

print(sys.getrefcount(b))

5

c = 100

print(sys.getrefcount(c))

6

When more variables reference to the same value the refrence count increase. But this is not the case when we take into example the case of container objects like lists and constants.


import sys

ex_list = [a,b,c,d]

print(sys.getrefcount(a))

8

print(sys.getrefcount(b))

9

print(sys.getrefcount(c))

10

print(sys.getrefcount(d))

11

del ex_list

print(sys.getrefcount(a))

7

print(sys.getrefcount(b))

8

print(sys.getrefcount(c))

9

print(sys.getrefcount(d))

10

# Same thing goes with constants

print(sys.getrefcount(10))

12

const = 10

print(sys.getrefcount(10))

13

const = const + 10

print(sys.getrefcount(10))

12

As we saw container objects here list refer to other objects referring to the value thus when we delete them the reference link is deleted thus objects inside the list decrease the reference count by one. The same happens with constants too, when the variable they get referenced to is incremented the reference count is decremented.

By now you must have realized that del does not actually delete the object on the contrary it removes that variable(name) as a reference to that object and decrease the reference count by one.

All the example we saw are kinda similar considering the fact that they are in the global namespace but what happens when there are function what happens to the reference count then, let’s find out through this code snippet


import sys

num = 100

print(sys.getrefcount(num))

4

def ytf(number):

print(sys.getrefcount(num))

ytf(num)

6

print(sys.getrefcount(num))

4

We saw that when ytf() got into scope the reference count increased while the reference count decreased when the function got out of scope. Keeping this in mind that we should be careful of using large or complex objects in the global namespace because an object in a global namespace don’t go out of scope unless we decrease the value of the reference count thus a large object would consume more memory making the program less efficient.

That’s all for this part, in the next part we would look closely into the garbage collector and how it functions inside a python program in freeing up memory.

 

 

Memory Managment in Python – Part 1

Stumbling upon a Python code snippet from a GitHub repo I did come to realize that in Python variables don’t actually store values they are assigned too, variables actually store the location to the value. Unlike in C++/C which actually creates a space of a fixed size and assigns it to a variable created which we usually call a bucket/room while explaining variables to a beginner “what variables are?” in programming.

Thought python variables are a bit different they work like keys which points to a particular room in the hotel(memory space) so whenever we make an assignment to available we are not creating rooms rather creating keys to that room which is freed/overwritten by the python’s garbage collector automatically. (More on the topic of garbage collector later). So the point is when ever we do something like


a= 10

b = 10

id(a)

94268504788576

id(b)

94268504788576

We are optimizing here and creating two same keys which points to the same room in the hotel (memory) thus they would have the same id but this kind of optimization works only with the range of integers from -5 to 256 if you exceed the range, variables would point to two different storages thus will have different id().

Just don’t get confused why we did not use “==” instead used id(), == checks whether the value pointed by the variables are same or not inside the object and id() checks if it uses the same object or not because every object has a unique identity which can be checked by the id() function.

Following the official docs id(), the value is the address of the object in the memory.

Coming back to the code snippet from the GitHub repo given below and applying the same knowledge of integers to strings.


a = "wtf"

b = "wtf"

id(a),id(b)

(139942771029080, 139942771029080)

a = "wtf!"

b = "wtf!"

id(a),id(b)

(139942771029192, 139942771029136)

a= "hello world this is a string"

b= "hello world this is a string"

id(a),id(b)

(139942770977328, 139942770977408)

The same kind of optimization happens here too when the strings are small they refer to the same object in the memory rather creating a new one thus saving memory, this kind is called interning. But when the object becomes bigger or contains ASCII letters, digits or underscore they are not interned.

This shows abstraction at it’s best and python is very good at it, it does all the heavy lifting job for you of allocating/deallocating memory for you and lets you focus on the other parts of the program. Until you really want to know what’s happening and I assume you do that’s why you are reading this blog 😛

Though this explanation was already available on the repo. I wanted to know more about how memory management happens internally so I stumbled about a talk of “ Memory Managment in Python – The basics” by nnja. So yeah people with nicks like ninja are great with Python and Fortnite hahaha! (I could not resist myself from posting this joke and just to clear things out ninja is one of the top Fortnite players)

Thus if you see technically Python does not have variable but  ‘names’ which refers to other objects or names and Python likes to keep a count of all the references called as reference count of all the object’s references. So if the reference count of an object decreases to zero this means no reference is made to that object which as seen by the Garbage collector of python as free space thus the object is deleted and the space is free to use.

We as a programmer can increase or decrease the reference count of an object as a python object stores three things:

  • Type: int,string,float
  • Reference Count
  • Value

Seeing the first code snippet of the blog where two names a and b in which both names points to the same object with the value 10 with the reference count of 1 and type as int.

That’s all for this part, will cover the same topics in a bit detail in the next part. Still confused in some of the things so keeping this plain and simple for future me to look back when I am lost and can’t even notice the simple things 😛 and for someone who just wants to know this briefly.

REST APIs with DJANGO

I recently finished REST APIs with DJANGO by William S. Vincent it’s not lengthy book hardly 190 pages but does pack a lot of information if you are just starting out with building APIs with Django and REST API in particular.

It’s well written so it’s easy to understand and takes into notice that you have just started out with Django though this could be a bit frustrating to read if you have been making some apps in Django because it explains a lot of basics concepts that I assume most of the readers would know about. It uses Django 2.1 and uses Pipenv for virtual environment instead of venv so that was new 😛

tl;dr A lightweight and simple book that packs a lot if you are just starting out with REST APIs.

I picked up this book because I wanted to work on Django Rest Framework and while reading a blog from the same author I noticed his book at the end. I liked the blog and did a quick search to check out reviews on the book, the reviews were positive so I bought the book for my Kindel.

Screenshot from 2018-12-11 21-23-49

The book mainly revolves around three projects that are covered in the nine chapters of the book though eight I should say as the first chapter talks about the basics of World Wide Web, IPs, URL,API, endpoints,HTTP and ends with explaining what REST APIs are. Well, the take away was that REST is just an architecture approach of building APIs  and REST API at minimum follows these three principles:

1. It’s stateless

2. It supports GET,POST,PUT,DELETE(HTTP Verbs)

3.Returns data in either JSON or XML format

So where does Django REST framework comes into play you ask? It’s simple ! it creates API which contains all the HTTP Verbs that return JSON.

One more thing not to confuse you and all, just clearing things up 😛 Django creates websites containing web pages and Django REST framework creates web API both are two different separate frameworks.  Yes! both can be used simultaneously in a single web app.

Now that I have flaunted my newly acquired knowledge let’s move forward with this review. haha!

The book helps you build three different projects a very basic library website API this is the first project in the book so it’s just to get you all set with the process but does an important job of helping you distinguish between Django framework and Django Rest Framework.

The second one is a ToDo API with the React front end though I think it’s just put in the book to either get you to use to of making REST APIs which can be repetitive at times or just to get a beginner programmer to think that ” oh ! covers react too, nice !” (bait). If you skip the chapter nothing would happen.  For those of you wondering I did not skip the chapter, I had to write this fancy review #dedication, haha!

The project that you would get the most out of is the last one and it’s the most basic thing that every Django developer builds when he/she starts out learning about Django. You guessed it right, a blog website so this book helps you build Django API

The whole project is spread around 5 chapter and broadly covers user permissions, user authentication, viewsets, routers, and schemas. It gives you enough understanding that you can look up Django REST Framework documentation with an ease plus I think author took this Blog API project in particular because it would be a nice if a beginner who had started with the Django Girls tutorial can make those changes in that particular project so he would get even better understanding with something to work on by himself. Which I would highly recommend doing and would be doing now.

I would rate this book 3.9/5.

A must buy if you are beginner in Django or just starting out making REST APIs or even both . If you have a decent experience with Django and know your internet jargons well I would suggest going with the official documentation.

 

To start, just start !

It’s almost end of 2018 and most of the people start working on their new year’s goals, well I am doing that too a bit early I guess 😛

I usually plan to write A LOT but all the time what I have seen is that once I start a blog and work on it, I give up on it either mid-way or sometimes it doesn’t reach the half-way mark the reason being I want it to be just perfect. What I mean to say it that I write blogs with the uttermost detail like the last blog that I start and could not publish was of the PyCon India 2018. I wrote a lot in it and gave almost every good detail I remembered from the event but like most of the blog, it could only make it to the halfway mark.

I don’t know what it is either I think I have a massive audience that eagerly waits for my blog or I wanna be that kid that writes awesome blog everytime he sits on the computer to write one. Whatever it is! I wanna change that. I want to write blogs frequently. So while finding a solution to this problem I remembered some lines from a podcast  CodeNewbie, in which Julia Evans was the guest. (she writes awesome blogs, go check them out if you haven’t ) Julia mentions that while she was in Recurse Centre she picked up this technique of writing small bit of blogs every day but the problem was she had a lot going on during that time so she didn’t use to get much time to write but she managed to that by writing consistently without thinking about much of the size of the content or thinking of writing just the perfect blog.

The thing I took from the conversation was to write frequently without worrying much about the factor and it’s not like many people read my blog so they would just find me to insult about my poor blogs, haha!  Only a handful of good people from #dgplug read it 🙂  so I got nothing to lose.

Things I would follow from now it:

  1. Keep the blog short and crisp 400 words or less
  2. Blog every second day, I do read a lot these days mostly tech so I can put those notes up in the form of blogs that would help me in the future too.

So yeah hopefully you will be seeing a lot of my blog(mostly bad in the starting so I apologize in advance) from now 😛

Grokking Algorithms

There are some books that you suggest to every person who asks you ” How should I start with … ?” Well being a recent graduate of yet another engineering college I have been asked a few times, “How to start with programming? Can you recommend some books ?” to those people I generally recommend this book with Python for you and me followed by “Jokes on you mate, I am as clueless as you are about programming 😛 ”

To justify why I recommend this book to everyone who is starting with programming; here is my short review and if you want a one-liner I have added the TL;dr version too.

Grokking_algo

TL;dr When a comic book meets a programming book the result is grokking algorithms.

I have broken down the review into very basic pros and cons list that should give you the idea of the entire book. So starting with the pros:

1. Visualization is the key, one of the book’s strength lies in the neat sketches you get on every page with the unique way of storytelling. So while you’re busy figuring out the story and looking at the sketches, the author quietly passes those computer science fundamentals that would be taught in a boring lecture, which seems so fascinating and easy while reading the book.  For example, in the hash tables chapter, there is this one character  Maggie who work in the grocery store and knows all the product prices. So instead of searching the price catalog, the cashier can instantly check the price by asking her and we can say as in fancy computer science term, she can give the price in O(1) times for any item no matter what!

Maggie

One more example I could think of it the way it relates folding paper with binary search where the search space is divided into half just as we fold a paper in half every time we fold a paper.

B-search

The book is filled with such similar stories focusing on small but important concepts.

2. Short and crisp exercises, after every chapter there is a recap of major points and a small exercise of hardly 10 questions which are a blend of code and theory concepts and are enough to practice what you learned in the previous chapter. Plus the code is available on the GitHub repo and the answers to the theoretical concepts are printed at the end of the book. So it saves time and energy of searching for solutions online.

3. Great supplement books, although it is a good stand-alone book for a beginner programmer who is just starting out with python and is interested in algorithms but I believe this book will be best suited if you read it with some standard book because it majorly focuses on the concept and somewhat fails to go in much depth if you’re taking up a course of Algorithms in your college or you want to know more about a particular topic like hash tables, greedy algorithms etc.

As much as I love this book there are some cons to it too 😦

1. Expensive, the major drawback I found is that this book is a bit expensive, for a freshman it’s fine because he is yet to learn a lot and this book offers a good head start but for an intermediate user it’s still a big deal.

2. Too basic for intermediate programmers, I picked up this book in my last year of engineering when I had a basic understanding of the concepts explained in the book so I wasn’t that amazed what the book has to offer as it lacks the depth in the topics covered but I was amazed at how easily they were explained.

The above six points cover all the major section of the book and should give a brief idea about the book of what I thought it’s strength are and what it lacks.

Book Rating: 3.5/5

So if you are starting out as a freshman in college, starting an algorithms course or are just curious about algorithms with a decent saving left around that you usually spend on partying 😛 give this book a shot, you won’t be disappointed.