So, for now ... I say to keep the peace - take it on the chin. Good learning experience for you. You did not properly credit yourself and made the way for this to happen. Note that you must be balanced in life too and not toot your horn too loudly. Have balance, allow others to succeed and get credit too. Maybe you saw the sample code on stack-overflow and refactored it. We all learn from others anyway.
The real problem here is the pat on the back from the boss, not the code itself which you saw as trivial anyway. Be aware of how this company operates. However, don't stop contributing! That will cause you to die inside. Your contributions are great and will help you to grow. So, no matter who gets the credit, keep doing it so that you'll be better off when you leave this place.