Answered by Habib Umar bin Hafiz (may Allah protect him and benefit us by him)
What can people do to protect themselves in places where men and women mix freely?
You must lower your gaze as Allah has commanded us to do. It has been narrated in the hadith that to gaze at that which is unlawful is to allow the devil the opportunity to fire a poisoned arrow into your heart. However, the one who lowers his gaze will taste the sweetness of faith in his heart. You should read this Prophetic supplication nineteen times before entering the place where you work or study:
اللَّهُمَّ يا حَيُّ يَا قَيَّومُ برحمتِكَ أسْتَغِيْثُ ومِن عَذابِكَ أسْتَجِيرُ أَصْلِحْ لِي شَأنِي كُلَّهُ ولاَ تَكِلْنِي إلى نَفْسِي وَلا إِلى أحَدٍ مِن خَلقِكَ طَرفَةَ عَينٍ
Allāhumma Ya Ḥayyu ya Qayyum biraḥmatika astaghīthu wa min `adhābika astajīr. Aṣliḥ lī sh’anī kullahu wa lā takilnī ilā nafsī wa ilā aḥadin min khalqika ṭarfata `ayn
O Allāh, O Living! O Sustainer! I call upon Your Mercy for assistance, and from Your chastisement I seek refuge! Make good all my affairs and do not entrust me to myself or any of Your creation for the blink of an eye.