I heard the Messenger of Allah (May peace be upon him) say: A good vision comes from Allah and a dream (hulm) from the devil, so when one of you sees what he dislikes, he must spit on his left (three times), and seek refuge in Allah from its evil. It will then not harm him. (Using translation from Abū Dāʾūd 5021)
أَنَّهُ سَمِعَ رَسُولَ اللهِ ﷺ يَقُولُ الرُّؤْيَا مِنَ اللهِ وَالْحُلْمُ مِنَ الشَّيْطَانِ فَإِذَا رَأَى أَحَدُكُمْ شَيْئًا يَكْرَهُهُ فَلْيَبْصُقْ عَنْ شِمَالِهِ ثَلَاثَ مَرَّاتٍ وَلْيَسْتَعِذْ بِاللهِ مِنْ شَرِّهَا فَإِنَّهَا لَنْ تَضُرَّهُ