There are two key passages regarding the practice of righteousness before others, and they seem to contradict each other!
The first is Matthew 5:16,
In the same way, let your light shine before others, so that they may see your good works and give glory to your Father who is in heaven.
The second is Matthew 6:1-18, particularly verse 1,
Beware of practicing your righteousness before other people in order to be seen by them, for then you will have no reward from your Father who is in heaven..
Taken at face value, these statements of Jesus are in direct opposition to each other. Should we let others "see [our] good works" or does that displease God and forfeit our heavenly reward? To answer that question, let's look at the essential meanings of the two passages.
In Matthew 5:13-16, Jesus speaks of the disciples' role in the world as "salt" and "light." What is the meaning of these two metaphors? Salt is a preservative: disciples are to slow the corruption of the world. Light, on the other hand, represents God's exposition of sin and call to moral purity (1 John). Thus, when you let others see your light, or your works, it is to show them to moral purity of God ("give glory to your Father"). The Apostle Peter clarifies this purpose in 1 Peter 2:12,
Keep your conduct among the Gentiles honorable, so that when they speak against you as evildoers, they may see your good deeds and glorify God on the day of visitation.
In Matthew 6:1-18, on the other hand, Jesus explores three topics—giving to the needy, prayer, and fasting—that were apparently issues in His day. From His words we see that the "hypocrites" did these things in the sight of others and "received [their] reward" this way. The reward was the approval of other Jews who saw these hypocrites as super-holy.
Jesus here warns that our reward comes from God, who sees "in secret," that is, He sees not only our public front but our private lives as well. Jesus therefore calls us to pay less attention to the good we do in public and more that that which we do in private. What a sad life it would be to pray only in public and never enjoy personal times of prayer with God.
Taking the two key passages together, the issue is ultimately—like so much in Scripture—a matter of the heart. The attitude of the heart in the first passage is to show God's righteousness; that attitude in the second is to show your own. Therefore, whenever we think of doing a righteous act before others, we must examine ourselves to see whose glory we are seeking: ours or God's. What are some ways we can do this?
One test I hear in church a while ago regarded thanks. The pastor said that in true humility one should be willing to serve without a chance of being told, "thank you." This will show that you are seeking no reward from man.
Another similar test I can think of is who you are talking to. If you are about to tell someone of a righteous act you committed, what will his response be? If the response would be some congratulations to you, then your intentions are most likely selfish. If the resopnse would be more praise (or, in some cases, less enmity) towards God, then go for it! That is exactly what Jesus would want you to do.
Well, this post has been straightforward, but I hope it will be useful to you all. May God give you good discernment and pure intentions in your public righteousness! Praise God for our redemption.