Hadith.2406 - It is narrated from Ibn Abi Umair who said
I used to observe the stars and understand their movements and their rise, and from this, certain thoughts would enter my mind. I complained about this to Abu al-Hasan Imam Musa ibn Jafar Al-Kadhim, peace be upon them both.
Imam (as) said: "If something enters your mind, give charity to the first needy person you encounter, and then proceed, for Allah (swt), the Exalted and Glorious, will ward off harm from you."