A father-of-two had 100 sleeping tablets on him when he was caught riding a stolen motorbike, a court has heard.
Wayne Devereux (23) had been weaning himself off a "bad cocaine habit".
He had bought the bike and was "reckless" as to whether it was stolen, Dublin District Court heard.
Devereux, of Little Strand Street, Dublin 7, pleaded guilty to unauthorised use of a vehicle and drugs charges.
Judge Ann Ryan said he could avoid a 10-month prison sentence if he carries out 200 hours of community service.
The court heard the incident happened at Railway Street in the north inner city on October 27 last year.
The accused was seen riding a motorbike that had been stolen earlier that day. It was worth €3,500.
When gardai searched him, they found 10 trays of zopiclone tablets worth €200.
The court heard he discarded 90 tablets in a separate incident when gardai chased him after he "took off" on a bike.
He had since turned his life around and was seeking work, his solicitor John Feaheny said.
His partner had told him to "shape up or ship out".