22 December 2017

Process Management in Python - os.fork()

Inspired by https://pymotw.com/3/signal/index.html, I thought of exploring os package in Python. The next few posts would be on process management and how to do it in Python. I would be showing you the code that is tiny. The goal is to provide basic code and I leave the improvision to you.

There are four important system calls - fork, exec, wait and exit that are related to process management. Interestingly Python provides equivalent APIs as a part of os package so that you can do a lot of system programming (and use it in a cool way). In this post, let us see some code that uses "os.fork" to create a new process.

os.fork() - creates a new process (often called as parent-child processes). The following code has enough comments and some explanation embedded as comments. Suggest you read the code and run it in Linux box.

Refer the Code in GIT Hub

If you want to know more about fork, refer - https://en.wikipedia.org/wiki/Fork_(system_call)

Share, comment and contribute if you like this post :-)


21 December 2017

Alarm and Signal in Python

Continuation to my previous post in Signals in Python. Again the credits go to Python Module of the week. The following code shows how easier it is to work with Python. This simple script registers for an alarm using SIGALRM which is configured to fire after "n" seconds. After "n" seconds, the handler function gets called.

In this code, I set alarm once as a part of main control flow and register again in the alarm handler. This program does not exit unless one kills the process or stops the execution of the program. (Python code seems to be more beautiful)



20 December 2017

Signal Handling in Python

If you are system programmer, you would have heard about signals and probably would have done lots of coding using signal. It might also be a second nature to you. But when you started to get your hands dirty with signals especially in C, it might have been quite involved. Now moving to signal handling in Python

Recently (last week), there was a post from Python Module of the week on signals and I thought I would try it. Here is the code that does some signal handling. You might want to check the full post (BTW, it is very interesting one). I feel that it easy to write code (and beautiful too) and I was able to do C-equivalent code in less than 30 minutes (which means that Python makes us productive). Here is the script that I wrote. You can find in GIT Hub and feel free to play around.



17 December 2017

"Python Crash Course by Eric Matthes" - Final Post and Review

If you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.

This is going to be the final post on this book

Review Comments: I accidentally stumbled on this book when I was looking for the books on Python. As the name suggests, it met the purpose of offering the crash course in Python. I could see the chapters are shorter as that one can complete a chapter (or two) in a single sitting. and logically arranged. The code snippets (examples) and "try it yourself" offered a great insight into the programming language. If you are in a hurry to get yourself exposed to Python, grab a copy of this book and you should be making a lot of good progress in booting up in Python. I should also alarm you that this book does not cover the language and its features in great detail. If you are looking for a deeper coverage of each feature, there are other books.

I have solved all the exercises in GitHub. I do not intend to solve the projects now.

Ratings: I would rate this book a 4.5 Stars.

Recommendation: Apt for beginners of Python (If someone is new to programming, they might feel left behind in later chapters as the book covers quite a lot of ground in every chapter or might need to spend more time referring the materials online). If you are new to programming, maybe a MOOC course on Python would be an excellent start.

You can find all posts related to this book - here

Next Goal:
It is time to learn Python little deeper using "Learning Python" by Mark Lurtz

Want to challenge yourself?
Do you want to take part in the challenge of completing "Learning Python" in two months? Add comments below.

13 December 2017

"Python Crash Course by Eric Matthes" - Code Journal 2

If you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.

Today's update:
Today (13-Dec-17, coded from 6am to 7.45am), I committed the coding solutions for Chapter 8. While solving the exercises, I realized that how easy and lovely is Python. When people say that Python is highly expressive, I did not relate to it. Now, I can :-). The amount of features that you can build with the amount of code is no way related. You will end up writing lesser code (less code means less time to develop means high productivity. Less code means fewer bugs which leads to high quality). If you want to experience it, try reading Chapter 8 and try solving examples. Lists, dictionaries along with various ways of using functions, passing arguments, passing parameters dynamically, passing a variable number of arguments are cool features of Python. Functions in Python is very powerful and yet flexible (I urge you to experience it by yourself)

Do not underestimate Python and this book (because it is a crash course). Solving some of the exercises can be very involved and serves the purpose. I would give 5/5 for the exercises in this chapter. Great selection of exercises. Kudos to the author

Solutions to Chapter 8 can be found in GIT Hub Repository. View it and Share it

Want to contribute/collaborate?
If you want to contribute, you can clone the repository, create a branch and give me a pull request. If you want to know how to collaborate, email/call me. Together, we can make things better.

If you wish to join me in the journey of a lifelong student, add yourself to my blog list and I will not disappoint you :-). 

12 December 2017

"Python Crash Course by Eric Matthes" - Code Journal 1

If you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.


I am archiving all the code that I have written so far in GIT. Just in case if you want to see it live, check this out - https://github.com/grabyourfreedom/pythoncrashcourse. I have committed all the code that I have written till chapter 5. I will keep working on it - fix bugs, add comments, refactor and add solutions to more exercises. For next few days, I will work on the code until chapter 11 and start reading the other chapters from Saturday (for more posts and code). The code journal posts are likely to be short as I am planning to post only updates here and commit the code to GIT hub.

It is very exciting to ramp in a language - reading, coding, and sharing.

Want to contribute/collaborate?
If you want to contribute, you can clone the repository, create a branch and give me a pull request.

If you wish to join me in the journey of a lifelong student, add yourself to my blog list and I will not disappoint you :-). 

11 December 2017

"Python Crash Course by Eric Matthes" - Reading Journal 4

If you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.

This post gives an overview of what I learned in Chapters 10 and 11.

Chapter 10: Files and Exceptions
It looks to me that the last few chapters are really informative. This chapter didn't disappoint me. The first part talks about file operations - reading a file, writing to a file, appending to a file with few variations. The second part talks about handling/managing errors using exceptions (try, except and else). As a bonus, the chapter covers storing data using JSON module and at the end talks about code refactoring. Overall it is written well and does the job.

Chapter 11: Testing Your Code 
This chapter seems to be very easy and yet at the same time very informative. It is great to see a book that boots up someone in a language (programming) talks about "testing the code". I feel that it makes a lot of difference in developer's life (others too) when we test our own code using automated unit tests. This chapter talks about testing your functions and classes using Python's unittest module with cool examples. And the side effect, it kindles the interest to explore further on creating automated tests too. Great job by the author

The next set of posts from me would be code journal. I will try to write a couple of posts sharing the coding exercises. With this, I concluded the basics of Python and I am excited to start the projects :-)

If you wish to join me in the journey of a lifelong student, add yourself to my blog list and I will not disappoint you :-). 

10 December 2017

"Python Crash Course by Eric Matthes" - Reading Journal 3

If you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.

This post gives an overview of Chapters 7, 8 and 9

Chapter 7: User Inputs and while Loops
This chapter covers how to get input from the user, how to convert it to numerical values if you need it. It covers while loop, how to exit from the loop using flag, break, continue and how to avoid infinite loops. It gives a couple of examples of when and how to use while loops with lists and dictionaries. This chapter is extremely light for a developer and might be interesting to someone who is new to programming. You should complete this in less than 30 minutes including the exercises.

Chapter 8: Functions
The chapter covers quite a lot of ground with functions, modules and a bit on PEP8 styling guidelines with respect to functions. You will see how to define a function, without and with parameters, returning value, keyword argument, optional values, default values for parameters, passing a variable number of arguments, passing a variable number of arguments with keywords, importing a module, importing a function from a module, importing all the functions from a modules and aliases for module/functions with sufficient examples. The chapter closes with the styling guidelines from PEP8. An awesome chapter and I really liked this chapter. This chapter might take a little longer including exercises and reflection. It is best to pause here for some time to reflect to ensure you got everything. After completing this chapter, you will really feel that Python is powerful. Kudos to the author for giving us a wonderful chapter.

Chapter 9: Classes
Like the previous chapter, this chapter too covers very interesting paradigm of Object Orientation using classes and objects. If someone is new to programming, I recommend for a slow reading solving all the exercises and trying out all the examples. It is worth the effort. Ensure that you understand the essence of the chapter (classes, objects in OO paradigm) before moving further. If you already know another OO language like C++ or Java, it should be a cakewalk for you. This chapter talks about creating classes, __init__ method, self, creating objects, accessing attributes, calling methods of the objects, subclassing/inheritance, overriding, importing classes and styling of classes. Another wonderful chapter with real-world examples.

If you wish to join me in the journey of a lifelong student, add yourself to my blog list and I will not disappoint you :-). Together, let us transform ourselves.

09 December 2017

"Python Crash Course by Eric Matthes" - Reading Journal 2

Like me, if you are new to Python and want to quickly ramp-up to become no non-sense developer in Python, you might want to read this post, these posts that are related to this book and probably all of these posts to become Python Super Star.

This post gives an overview of what I learned in Chapters 4, 5 and 6

Chapter 4 - Working with Lists
In this chapter, you will work with Lists in a much better way and you will see how much easier is working with Lists. You will learn the operations such as iterating the list using for loop, working with numerical lists using range, slicing a list, copying the lists, difference between copying and assigning lists. You also get to know various errors (runtime and logical error) that are likely to happen when you do not indent properly. At the end, you have a very nice section on how to Style the code. Refer PEP8 from here. This chapter is engaging and you can complete this chapter in 30 to 45 minutes including solving exercises.

Chapter 5 - if Statements
This is another easy chapter that covers conditions/tests, condition evaluation to boolean, test equality, test inequality, comparisons, multiple conditions using "and" and "or", check for existence of a value in a list and non-existence of a value in list, test to check whether the list is empty, simple if, if..else and if...elif...else. Like the other chapters, this chapter is also engaging and one can complete this within an hour

Chapter 6 - Dictionaries
This chapter covers the basics of another important feature of Python - Dictionary. This chapter teaches what is dictionary (you will understand the difference between list and dictionary when you work through examples),  adding new key-value pairs, modifying key-value pairs, removing a key-value pair, various ways of looping (items, keys, values) and various types of nesting (dictionary inside dictionary, list inside dictionary and dictionary inside list).

If you wish to join me in the journey of a lifelong student, add yourself to my blog list and I will not disappoint you :-). Together, let us transform ourselves.

08 December 2017

Switch by Chip and Dan Heath - Notes

This page contains my notes, my reflections and various other references that would aid my readers. Finally my recommendation on the book.

Book: Switch - Switch - How to change things when change is hard
Authors: Chip and Dan Heath

Posts:
These posts are not a replacement for the book. The book is million times impressive and insightful. After reading these posts you might get an urge to buy the book but after reading the book you would like to change something. I would rate this book a five star (*****) and encourage all my readers to buy one. These posts should shed some light on your investment on this book and potential huge return on investment.

  1. Book Review after first reading
  2. Switch (Part 1) - Three Surprises
  3. Switch (Part 2) - Direct the Rider, Find the Bright Spots
  4. Switch (Part 3) - Direct the Rider
  5. Switch (Part 4) - Motivate The Elephant
  6. Switch (Part 5) - Shape The Path
  7. Switch (Part 6) - How to keep the Switch going?
  8. Found an excellent video review of the book in Youtube
  9. Other Resources to aid in learning

!!! Happy Switching !!!

07 December 2017

Interviewer Essentials

A great part of my weekend goes to interviewing and a considerable amount of my time during my weekdays is devoted to hiring and activities related to hiring - profile screening, talking to the candidates, interviewing - technical and softer aspects.

What I learned are (over a period of time)

To Interviewers and to their managers (the source of problem but who think that the fault is on everyone but them)
  1. In the part of the world that I live in especially - be ready to read more (do not get bored or scared of seeing the projects and skills that one acquired 10 years back that never eroded)
  2. Shortlist quickly and ask HR to schedule interview
  3. Be available on time. If you have some work and you would join late, send someone who can do interviews (not just filling the space/time)
  4. Interviews are a business transaction. The interviewer has to sell the company and the future employee is likely to undergo. Not a fancy future that would never materialize. Be pragmatic on what you say
  5. You cannot get super-man when you pay peanuts. Reset your expectations
  6. Expect that someone can become super-man after she joins. Look for track record
  7. People want career, money, satisfaction, appreciation, feedback and a great culture (only the order differs from people to people). Do not oversell anything (as people might feel they won't get other stuff)
  8. You may be leading machine critical things but do not expect the folks to burn might night oil. Do not boast either
  9. Interview for the position (do not interview like you are hiring a CEO when you are hiring a developer). It is big sin to hire a developer without coding. Satisfied with pseudo code or "I can tell the logic" is the biggest sin. If you are hiring for senior position, start with design and drill down to coding (or start with code and move to design - bottom-up or top-down either way is fine, but do it)
  10. Often neglected piece is asking them to write unit tests for their own code. They might even write just two test cases, but it is fine. The question is whether they "think". If someone is allergic to writing unit tests - never look back
  11. Giving clues is not a sin. When you give hints, you really know more about the candidate (whether he picks up quickly and able to connect the dots). When you give clues, ask them to enhance.
  12. Do not ask funny or fancy questions on DS and Algo (which you were not able to solve for three hours but once you solved you want others to solve in 10 minutes) when your daily work is something else
  13. The world is moving more towards OpenSource, please see whether the candidate has allergy towards the word - OpenSource (and self-learning/training/exploring on their own)
  14. Give them the runway - Not all will be able to crack everything first and not always. Warm them up
  15. Listen properly and be attentive. Ask questions and answer questions properly
  16. Most often you will learn things from others, interviewing is no exception
  17. Decide as soon as the interview is over. Overthinking is killer
  18. Help HR. Maybe they have so many candidates to take care. Pick your resume, invite the candidates and take care of interviews. Keep HR informed on outcomes
  19. If the candidate asks feedback, spend some time with them in giving feedback (especially if they are very junior to you and looking to improve themselves). You never know when you will work for a nerd
  20. No frustration (even if your day is tiring)
  21. After hiring, connect with the candidate. Try to see whether you can be of any use to them.
  22. Wait for them to join
  23. Most importantly - remember that you are hiring a human, not a machine. Behave appropriately
Of course, this is not the bible to do interviews and there are zillions other things to do.

Your comments?