A heroin addict had been taking drugs since the age of 11, but it was only when he lost a leg from infection at the age of 28 that the "penny dropped", a court was told.
Philip Joyce (29) got clean after he hit "rock bottom" with the amputation.
Dublin District Court was told his "sad story" as he admitted hurling abuse at gardai in two separate incidents while he was intoxicated.
Joyce, from Ross Road in the south inner city, pleaded guilty to threatening, abusive and insulting behaviour.
Judge John Hughes handed him a one-year probation supervision order.
The court heard Joyce was arrested on Dawson Street at 9.15pm on New Year's Eve, 2017, when he yelled abuse at gardai who challenged him for approaching passers-by in an intoxicated state, looking for spare change, cigarettes and alcohol.
Gardai were called to deal with an incident at Ross Road at 9.04pm last August 29 and Joyce began shouting obscenities at them.
He was highly intoxicated and a large number of people had gathered.
He resisted arrest and was violent and had to be restrained.
Joyce misinterpreted the purpose of the gardai being there, thought someone was being arrested and accepted he had acted inappropriately, his solicitor Aonghus McCarthy said.
It was a "sad story," he added.
Joyce's mother died when he was a child and his father spent a lot of time in prison, so the accused went to live with a relative.
He was introduced to drugs at 11 and became addicted, remaining so until seven months ago. This was the longest Joyce had ever been off them, Mr McCarthy said.
Joyce had to have a leg amputated from the knee down because of blood clots he developed where he injected himself.
That was rock bottom for him, the "penny dropped" and he knocked drugs on the head, Mr McCarthy said.
Judge Hughes said Joyce had been taken advantage of at a very young age, with his drug use culminating in a significant disability.