Showing off (riya) in worship
Question

Is there any chance of getting blessings from an act ruined by riyaa if one's intentions change to please Allah after the thought of riyaa has already come? For example, I finish reciting Qu'an, and the thought of riyaa enters my mind. If I immediately fight this thought with thinking about Allah, can I still get blessings for my recitation, or is it completely ruined forever because of riyaa, given that the act is over and the riyaa thought came after it was already over?.
Praise be to Allah.Shaykh Ibn ‘Uthaymeen said: 
Showing off may affect worship in three ways: 
1 – When the basic motive for worship is to be seen by others, such as one who stands and prays so that people will see him, and so that they will praise him for his prayers. This invalidates the act of worship. 
2 – When it is a factor that develops during the act of worship, i.e., if the worshipper is initially sincere in his intention towards Allah, then the idea of showing off develops whilst he is doing it. In this case one of the following two scenarios must apply: 
(i) There is no connection between the first part of his act of worship and the last part, so the first part is valid in all cases, and the last part is invalid.
For example: a man has one hundred riyals that he wants to give in charity, so he gives fifty of them in a sincere act of charity. Then the idea of showing off develops with regard to the remaining fifty. So the first was a sound and accepted act of charity, but the last fifty was an invalid act of charity because the sincerity was mixed with a desire to show off.
(ii) The first part of the act of worship is connected to the last part, in which case one of the following two scenarios must apply:
(a) He wards off the idea of showing off and does not give in to it, rather he turns away from it and hates it. This does not have any effect on him, because the Prophet (peace and blessings of Allah be upon him) said: “Allah has forgiven my ummah for what crosses their minds, so long as they do not act upon it or speak of it.”
(b) When he gives in to this idea of showing off and does not ward it off. In this case the entire act of worship becomes invalid, because the first part is connected to the last part. For example, he starts the prayer with a sincere intention towards Allah, then the idea of showing off develops in the second rak’ah, so the entire prayer becomes invalid because the first part is connected to the last part.
3 – The idea of showing off develop after the act of worship has ended. This does not affect it or invalidate it, because it has been completed soundly, so if showing off occurs after that it does not affect it. 
It is not showing off if a person feels happy that the people come to know about his worship, because this developed after he has finished the act of worship.  
It is not showing off if a person feels happy because he has done an act of worship, because that is a sign of his faith. The Prophet (peace and blessings of Allah be upon him) said: “Whoever feels happy because of his good deeds and sad because of his bad deeds, that is the believer.” 
The Prophet (peace and blessings of Allah be upon him) was asked about that and said: “That is the first glad tidings of the believer.” 
Majmoo’ Fatawa al-Shaykh Ibn ‘Uthaymeen, 2/29, 30.