An NYPD officer got in to the Christmas spirit in a particularly touching way: he bought a homeless man who rummaging through the garbage a pair of much-needed diabetic socks.

Joshua Lagan of Long Island City said in a now-viral Facebook post that he was waiting for a train at Grand Central Terminal when he saw an NYPD officer running toward a man digging through a garbage can. Lagan said that after initially reprimanding the man for opening the trash can they asked why he was collecting cans.

Lagan said that when one of the officers found out he was trying to collect enough money for some doctor-prescribed socks, the officer -- later identified as Frank Rendina -- found out, he told the man "I’ll buy you socks. It’s Christmas soon right? I’ll buy you socks for Christmas. Merry Christmas. Let’s go to the store.”

Rendina said that he had known the homeless man, Ron Brown, for a couple of years and had celebrated a birthday or two with him with some candy bars. So when he heard about the man's request -- he didn't hesitate.

"His doctor told him he needed diabetic socks," Rendina said. "I said, 'No problem. For Christmas, I will make sure you get the socks."

Brown, who Lagan said was taken aback by the gesture repeatedly asked "Are you serious?", said Tuesday he knew Rendina to be a good guy.

"What he did, he did from his heart and people shouldn't think negative of the police," Brown said. "They're good people."

More than 2,000 people have shared Lagan's post about the touching exchange. NYPD Commissioner James O'Neill got word of the act of kindness as well.

"We can all learn something. I'm so proud of #NYPD cops, and of all NYers," he said in a tweet.