Here's what I did.
#1 I always sit in the front. I believe that front students do better than back students. Anyway, sitting in front means that your teacher will recognize your face.
#2: Know your shiitt
#3: Answer questions when the teacher asks them (see #2).
#4: If you don't understand a part of the lecture, raise your hand and ask. Asking means you're paying attention.
#5: Be friendly. Don't be friendly for an LOR. Be friendly because life is better that way.
#6: Be friendly with your teacher. Talk at their office, before/after lecture, during lab, etc. Most students don't bother, so you won't have to compete for attention. If this is difficult, start with a few questions, then chat about other stuff.
#7: Relax and don't censor your conversation. Perhaps this is somewhat risky, but you want the teacher to know you, not you minus everything you think you shouldn't say. If you have a negative attitude, change it now. Life WILL catch up to you.
#8: If you're having trouble with #6, then be sure to visit at their office at least a few times per semester.
If you've done the above, then the teacher will accept your request for an LOR.
I'm a nontraditional and got an LOR from a faculty member from 10 years ago. I visited him a few times recently. I brought my resume and we discussed what I'd been doing. Later on, I gave him a copy of my transcript so he could remember my A's. I gave him my AMCAS essay also, so he'd have info to work with. I asked him if there was anything else I could provide, and he said he had enough info. Most of all, I had visited and we had had friendly, casual conversations.
I hope this helps. I lost video game time to enter it.