This question repeatedly arises. How to maintain an undisturbed calmness of mind while functioning in the world? Here is Maharishi Patanjali’s formula:

One must cultivate:

Friendliness Towards the Happy
Most of the time, worldly people have a tendency, out of envy and jealousy, to look for the dark side, especially with respect to a successful person. By doing that, they create more bondage by polluting their mind as well as the world. On the other hand, by befriending happy and successful people, by rejoicing in their success, the mind is not polluted and one can even learn from them and benefit from the secret of their success.
Compassion Towards the Unhappy
When we see a beggar in the street, instead of walking the other way, which would be hardening our heart, we should try to help him. Behind the beggar is God, giving us an opportunity to eliminate greed and selfishness, and to develop compassion. If we adopt that view we should even be thankful. The person in need is there to helps us relieve ourselves from our load of selfishness and greed. 
Reverence for the Holy 
Saints or yogis do not need the reverence of others; but by cultivating reverence, the seeker frees himself from his gross ego and develops humility. Humility creates the right conditions for knowledge to be transmitted. If the “vessel” is not right, the transmission will not take place. So reverence for the holy is a sign of maturity and true discrimination.
Some people say; “I have reverence only for God, I don’t care about gurus and saints. ” But then who is God? Just a figment of their imagination! Someone who cannot feel reverence for a mother, father, or teacher will not have reverence for God either because parents, saints and yogis are nothing but reflections of the Divine.
Indifference to the Wicked
In this world of duality, there are good and bad people. Until you are fully established in the knowledge of the Self, it is better to avoid wicked people rather than associating with them with the idea of changing and converting them. Before you know it, you will become one of them. A sadhaka must protect the purity of his mind and guard his spirituality by turning away from evil company and seek right association.