Neil Masterson (33) was arrested after gardai found drugs in a routine traffic stop, then uncovered more cannabis in a follow-up raid of a flat.
A judge has told him he will be left without convictions for possessing and supplying drugs if he gives €1,000 to charity.
Masterson, of Monksfield Walk, Clondalkin, admitted possession of cocaine and cannabis herb with intent to sell or supply when he appeared in Blanchardstown District Court.
The charges related to seizures of the drugs from his car at Outer Ring Road, Lucan on October 7, 2011, and an apartment at Watermill Square, Market Square, Monasterevin, Co Kildare, on the same date.
Garda Enda Waters told the court he stopped the defendant on the date and got a smell of cannabis from the car.
On searching the car, he found cannabis and cocaine, as well as €970 in cash.
A follow-up search of the apartment was then carried out and more drugs were found. The total value was €3,800.
The defendant had one previous conviction for possession of drugs "a long time ago", his solicitor Mathew Kenny said.
Since the offences, Masterson had gone for treatment in Coolmine and was "not involved in the drug trade any longer".
Garda Waters confirmed that the accused had since been a "model citizen".
The defendant's partner was in court and they had one child, born in March this year.
Masterson had overcome his drug difficulties, was involved in family life and would not come to any adverse garda attention again, Mr Kenny said.
The court heard the defendant's mother was from the Philippines and convictions may cause problems for him returning there to visit family.
"He is simply asking me to canvas the possibility, albeit remote, that he could be left without a criminal record", Mr Kenny said.
Judge John Lindsay noted that the amount of drugs found was "considerable".
He adjourned the case to February 7 and said he would strike the charges out if Masterson made a €1,000 contribution to the Mulhuddart Blakestown Community Drugs Team.