Peter Ma looked around his San Francisco condo and realized he'd won everything in it. His flat-screen TV, home theater system, 3D printers, phones, tablets, computers and furniture were either hackathon prizes or purchased with hackathon earnings. Stashed under his leather couch — which he'd bought with an Amazon gift card — was a thick stack of 2- and 3-foot-long cardboard checks commemorating his most cherished wins. "The only non-schwag I have are shoes," he said.

With his gray hoodie and close-cropped goatee, 33-year-old Ma looks like any of the thousands of computer programmers roaming the city, but he's part of an elite corps. He and about a dozen friends travel the hackathon circuit. They build apps, connected devices and other products during all-night, fiercely competitive programming contests where sleep is scarce and caffeine is plentiful. The sessions are usually sponsored by corporations, and top prizes mean serious cash. (We explore hackathons for the younger set on this week's Decrypted podcast; subscribe here on iTunes.)

Some of the hackers have jobs. Some do contracting work. Some have corporate sponsors. Almost all of them are working on a pet startup idea. For Ma and a few others, hackathons are a job. Ma knows he would make more money if he had a more traditional career. He just doesn't want one.

"I have my time to myself and the freedom to work on whatever it is I want," said Ma during a long lunch on a sunny Tuesday in March. Ma said he has considered offers from Google, Facebook and Uber over the years, but passed every time because he likes calling his own shots. Intel sponsors his work by sending him technology for company-related projects, and he also has an occasional gig consulting for large companies. He likes the setup because it allows him to travel and work on his own schedule.

Brian Clark, 27, supported himself on hackathon earnings for more than two years. (He and Ma don't know each other.) He's working on his fourth startup idea now, and says he carves out time for competitions because they help him hone skills and earn money quickly. "I'd much rather earn that money in two days so I don't have to take the programming job for two months," Clark said.

At one hackathon sponsored by Kmart and Sears, he built a mobile gifting app. None of his friends liked the idea, so he engineered it on his own and ended up winning $6,000 for fewer than four hours of work. Another time, when his bank account was down to zero and he was sleeping on a friend's couch in Oakland, he entered a hackathon out of desperation.

"It was win it or apply for a job," said Clark. He and some friends spent a little more than a day building a tool enabling developers to troubleshoot mobile apps by tracking user behavior. "Out of 800 teams, I won first for $40,000."

Over the past three years, Ma has traveled to more than 100 hackathons, and his strategy is down to a science. He knows how to maximize his time and prizes. He enters competitions based on the quality of the sponsors (read: big money), the location (unless airfare is covered, he's not inclined to leave the Bay Area) and which of his friends are planning to go.

The cooler and newer the technology being promoted, the more interesting the hackathon is. Ma and Clark both look for events that will help them continue their education by practicing new skills.

A few days before each hackathon, Ma checks that all his favorite programs and tools are up to date. Usually updates take 15 to 30 minutes, but sometimes there's a glitch, a program fails and an update can take a couple of hours. The times he hasn't done the prep work, like at a Smart Cities event at the Consumer Electronics Show in Las Vegas, have created chaos during the hackathon.

"We didn't know we needed an update and all the sample code stopped working," said Ma. The oversight cost his team several hours to correct. "You know how a soldier goes to battle with a sword? Our weapons are our laptops."

Ma brings his computer, his iPhone, two Androids, a microprocessor development board and sensors for temperature, humidity and touch. He doesn't pack a toothbrush. "I bring the basics," he said.

Clark packs his favorite blue fleece blanket and small pillow into his backpack along with his laptop and charging cables. (He also doesn't bring a toothbrush.) Once he knows who the sponsors are and what technology they're promoting, he writes a pitch describing the project he aims to build incorporating that tech and uses it as a script when he presents his project.

Hackathons can vary in length, focus, judging criteria and other factors, but they all follow a similar pattern. Hackers register online, usually in teams of three to five people. Corporations hold competitions in all kinds of places: Any large space with bathrooms, screaming fast Wi-Fi and lots of power outlets will do. After each team claims their work area and stashes their gear, they meet with corporate sponsors to evaluate the tech tools they might use to build projects and, of course, get T-shirts and other schwag. Hackathons usually have a specific technology like augmented reality or a theme like "connected homes." Hackers know about those categories in advance, but teams aren't allowed to begin working until the official start.

Most events last between 24 and 48 hours. During that time hackers work as a team to create something new, interesting and functional. Organizers provide all the food and drink — a menu that often includes pizza, burritos, energy drinks, chips and chocolate — so hackers can eat while they work. Many don't sleep. Others take short naps under tables while their teammates continue coding on their laptops a few feet away.

Calculating the salary of a professional hackathoner is not straightforward. Winners can earn tens of thousands of dollars every month, but much of that may come in the form of gift cards, service credits and gadgets. And since winnings are divided among team members, individual hauls vary depending on the size of the team. If these coders were working at Google as entry-level software engineers, they could each make about $127,000 a year, according to employer review site Glassdoor. That jumps to north of $200,000 for more senior positions.

Jay Zalowitz, who lives in San Francisco and is 28, said he used hackathon earnings to bootstrap his startup for several years. He pared back his weekend hacking — it usually takes a couple of days to recover from such a lengthy grind — when he got a full-time programming job.

"Once you start making real money, the amount you win is actually pretty marginal," he said.

Corporations have embraced hackathons in recent years. There were more than 1,000 in 2016, according to Devpost, a developer site that maintains a running list. Companies such as Microsoft and Amazon sponsor hackathons because the competitions allow them to show off their newest gadgets, like virtual-reality headsets and voice-control APIs. The more sponsors can entice developers to build with their products, the faster those products take off.

IBM holds hundreds of hackathons — online and in person — every year. Some are massive. To push Watson, its artificial intelligence platform, IBM is now running a true marathon event (with a more normal work schedule) of three years with a $5 million prize attached.

"We use it as a vehicle to push new technologies," said IBM Chief Developer Advocate Willie Tejada. "We know it feeds revenue somewhere down the line."

Devpost founder Brandon Kessler said he's recently noticed the rise of nontech companies and live events — like Fashion Week in New York — seeking to infuse technology into their main business by hosting and sponsoring hackathons. "They are becoming more of a daily tool for innovation," he said.

In March, Procter & Gamble hosted a hackathon in Redwood City, California, to promote Febreze plug-in scent dispensers and be inspired by new ideas for future products. Organizers invited Xerox's PARC, Nest, Google, Amazon Alexa, cloud platform startup Arrayent and other companies promoting connected homes to attend so they could showcase their own technologies enabling connected Febreze dispensers. In exchange for $10,000 and prizes — including a PARC internship — dozens of developer teams slept in shifts during the 48-hour event to build the best project.

Ma and his team, which brought a methane sensor to the event, built a fart app. When the sensor detected high levels of methane, it signaled the Febreze plug-in to emit a puff of fragrance. They didn't win.

"The technical integrations didn't matter. It was all about the idea," said Ma. He wished he'd had a woman on the team. "We had three guys building a fart app and 90 percent of the customers are women."

Procter & Gamble was happy with the results: One winning project connected the scent dispenser via Wi-Fi to a smartphone so users could control scent along with temperature and mood lighting.

"Hackathons allow us to have access to some of the sharpest minds," said Procter & Gamble spokeswoman Lauren Thaman, who said the company has done a couple such events and intends to do more. "It's a very creative, fast way to get answers from innovators and early adopters."

Corporate hackathons don't always go according to plan, though. blazed into the hackathon scene in 2013, offering a $1 million grand prize — an unprecedented amount that dazzled hackers, who registered in record numbers to compete. But when judges awarded the prize to a former Salesforce employee, who had written some code before the hackathon officially began, the backlash from developers was severe. Salesforce clarified the rules in 2014 and has since abandoned the splashy competition in favor of an online learning program for developers.

Ma says along with Salesforce's withdrawal he's noticed some companies have begun to offer smaller prizes. Founders sometimes game competitions, too, using hackathons as a place to launch their mostly baked startup ideas and presenting polished projects that have been a steady focus for months rather than a basic prototype created in a flash of inspiration. These forces have changed the competitive dynamic and made it harder to earn a living as a professional hackathoner.

Of course, some hackers also drop out after they get jobs, get married or their immune systems can no longer withstand the stress of poor diet and no sleep.

Ma says he plans to continue for as long as he can. He likes the freedom to build whatever he feels like and help larger social issues. He and friends recently competed in Code for the Kingdom, sponsored by Christian churches — a hackathon focused on solving homelessness, hunger and other social problems. They won $1,000.

"I can always get a corporate job," he said, slicing into seared branzino. "I don't need to. That's the backup plan."