For five months I walked past a homeless man on my way to work. He lived near the Hudson river in New York, his belongings piled up in a shopping trolley. He was in his late 20s, a little older than me, and every time I saw him I felt an uncomfortable mix of empathy tinged with shame about not helping him. Then, one day, I saw him exercising by lifting boat chains and it was such a poignant image that something inside me snapped.

The next day I approached him. I felt incredibly nervous, and worried he'd react badly, but I was determined. I had a gut feeling about him; he had a spark in his eyes that told me he was different.

There was no easy way to introduce myself, so I simply said, "I've passed you every day and I've got a weird feeling about you. You know how some days are not like others?" He looked puzzled but interested, so I continued. I offered him two options: I could either give him a laptop, and teach him how to write computer code, or give him $100 in cash.

He repeated my offer back to me, bewildered. He wasn't sure what coding was, so I explained that it's the language of computer programs; it shapes every game and app, and is the building block of all websites.

He told me his name was Leo, and accepted my offer. I agreed to teach him for an hour every day for two months. If he had chosen the cash, that would have been fine, but I was overjoyed that I could begin working with him.

I am a firm believer in the power of education. I was home-schooled by my mother, herself a software engineer, and she instilled in me the joy of learning. By the age of 12 I had set up my own business designing websites and had earned $3,000. Writing code is a valuable and much sought-after skill, so I was sure that if Leo learned how to do it, it could be a way for him to turn things around.

I bought a secondhand laptop and three books on Java, the programming language, and took them to Leo the next morning. We had to start from scratch. Leo had used computers a little at school but didn't have an email address and didn't know how to do very basic things such as copy and paste text. But he has an incredible memory and can recall information almost word for word. He also finds coding interesting, which is the most important hurdle.

Our goal is to launch an app. Leo came up with the idea: a car-sharing app that monitors the amount of CO2 emissions you've avoided; he is passionate about the environment.

For each 60-minute lesson, we find a nearby bench to sit on: he can't leave his belongings for too long and cafes don't welcome homeless people. It has become the best part of my day. I usually spend my working life staring at a computer screen, but here is a real human being, who is enthusiastic and focused. It is a pleasure to spend time with him.

He is truly dedicated and works at it for three hours a day: no mean feat, because the information is incredibly dense and it's hard to absorb a lot at one time.

My preconceptions about homelessness have been shattered. I always thought homeless people were isolated, but Leo is part of a very supportive community. He says the hardest thing is not the practical challenges but society's view of him. There is an assumption that homeless people are addicted to something or mentally ill, but Leo doesn't drink or smoke; he became homeless after he lost his job and then his accommodation in 2011.

At the start of this project, I wrote a blog about it and was inundated with responses. Some were moved and inspired; others were more negative, suggesting I should focus on buying Leo food or finding him somewhere to live instead. This idea is a tricky one. I consider Leo a friend. If he said he needed anything, I'd jump through hoops for him, but I don't ever want him to think we are anything but equals.

When our project is over, I hope Leo will be offered a job somewhere. I don't think that's unrealistic. As well as being brilliant at coding (he'll have surpassed me in two years), I think he could make a great teacher. I also hope that others will be inspired to repeat this scenario.

• As told to Emily Cunningham

Do you have an experience to share? Email experience@theguardian.com