The mechanic
You own options and are delta hedged. The stock rises, so your delta rises - you are now net long. To restore neutrality you sell shares.
Then the stock falls back. Your delta falls, so you are net short. To rehedge you buy shares.
You sold high and bought low. Over the round trip the stock ended where it started, and you made money.
That is gamma scalping, and it is why being long gamma pays for movement in either direction.
What determines the profit
Your scalping profit over a period scales with the realised variance of the underlying. Your cost is the theta you paid, which was priced off the implied volatility when you bought.
So the trade is simply:
Profit if realised volatility exceeds implied volatility.
That is the cleanest possible statement of what an options market maker is actually betting on, and it is worth being able to say in one sentence.
The short side
Sell options and everything inverts. Your delta moves against you: you become short as the market rises, so you must buy to rehedge - buying high. You become long as it falls, so you sell - selling low.
Every rehedge loses a little. You are collecting theta and paying it out through hedge losses, and you profit only if the market moves less than the implied volatility you sold at.
This is why short-gamma positions are dangerous in fast markets: the hedging losses accelerate exactly when volatility spikes.
Frequency
More frequent rehedging captures the realised path more completely, but costs more in spread and impact. The optimal frequency balances the two, and in practice desks hedge on delta bands rather than on a clock.
The interview form
"The stock ended the day unchanged but was extremely volatile. You were long gamma and hedged. P&L?"
Positive. The path paid you, even though the endpoint did not move.
Practise in finance and derivatives.