So I've come to realize - After a friend/coworker shares something that they're sad/angry about, my standard MO is:
1) Say something like "Wow, that must really feel terrible. I'm sorry to hear that!" (I always feel the need to add more to this statement, but it's better off said with a light touch and not heavy-handed.) Then,
2) "I feel like I was in a similar situation a few months ago when..." Important rule about this step - this statement is NOT to be a 1-upper. You're not saying this to proclaim that your situation from the past is more significant/worse than their situation. You're saying this because it helps your friend/colleague understand that they're not alone in how they're feeling, and their feelings are (generally-speaking) justified. Also - You don't talk about what you did to solve the issue. You talk about how you felt, etc. Be vulnerable, be open, and the person venting to you will respond similarly. Finally,
3) Ask "So what are you gonna do about it?" This kinda turns its head on the status-quo. Usually, this is the time you start explaining "Well here's what I did in my situation!" But that's not what you want here. Instead, you're asking the person if they've thought of a plan to tackle the issue. If you've established a "safe space" to discuss the topic, they feel more open about sharing their plan to resolve the problem, even if they don't have a plan and have to come up with it on the spot. Then, more likely than not, they'll ask "What do you think?"
At this point, you're free to let your problem-solving self run wild, assuming that you don't then consider your friend/colleague a "broken piece of code begging to be fixed."