For years I've been able to sit down and get intense on solving a problem. YMMV, and maybe you'll just cherry pick some of the points. Also, about none of this is original, they're all concepts I've picked up from various fields, thinkers and people over the last 8 or so years.
--
This is how I do it:
1. Get your location right.
I have a desk and computer for doing work on, and a completely separate one for playing/watching movies/just about anything else.
This location should have one purpose, and you should be cool with that. If you want to use the location for anything else, you'll mess with it.
It's for work. Nothing else.
Note, I say location because it doesn't have to be a desk. A laptop, comfy chair, and a nice room might work for you. Or maybe sitting outside is your thing.
2. Plan your time.
If you want to get serious work done 30 minutes wont cut it. You won't even be able to get ready to work in 30 minutes.
Set aside a few hours. I usually split my 8 hour day into a ~3 hour chunk, lunch, then another 3-4 hours. For me, the break is almost always useful. On one hand to eat, because eating is cool. (I've forgotten to eat enough times while coding, to not let that happen again.)
These blocks should not be rigid, if you're on a roll don't stop. Just remember to eat (good food, not crap. crap food does not help the brain).
3. Coffee.
Might not be for you, but a well timed coffee with food in your stomach can do wonders for your productivity. I'm sure it's psychosomatic but I swear I type faster with good coffee.
Actually thats another point. Get good coffee. Here in Melbourne, you practically trip over it, there's good real coffee everywhere. If you can't get a real coffee, try some good black tea.
They're both acquired tastes, so find a friend who loves them who can show you the ropes.
I'm not a fan of energy drinks, the release is too fast. A good tea or coffee in the morning will keep you going until 3pm, which is the perfect time for a second one.
I almost never go more than 2, you don't want too much of a tolerance to it.
4. Scope your work.
If we take the analogy of a good golf swing, you need to plan what you're about to do. But like a good golf swing, it should be more mentally thinking about the problem, as opposed to over thinking where the club must go to hit the ball.
For a good 8 hour chunk of time, taking 30-40 minutes to get into the right frame of mind to solve a problem is the way to go.
5. Music.
Now's a good time to start some music, incase you haven't already got something playing.
But kill the lyrics.
Any lyric heavy music, or anything that if mentally intensive to listen to - is sapping your brain power. Not cool, your brain is here to work. It's not time to enjoy music the way you would normally.
This music has a purpose. It's there solely to get you into, and keep you in a state of trance.
Surprisingly trance music is pretty good at that. But I'm more into electro, house, electro swing (Caravan Palace anyone?).
If I could reccomend anything here, get a nice comfortable pair of open cans. That is, circumaural headphones that cover your ears, and are open backed meaning the sound will leak out. It's very important that the sound can leak out, as it prevents a pressure on your ears. Closed headphones are generally amazing to listen to, but they can become incredibly fatiguing after a few hours.
Get a pair of headphones that barely even feel as if you're wearing them, that sound amazing. You may need to get a headphone amp as well, they're only $20-80. Do it. Trust me, I was once an audio engineer.
Also, spend a good bit of money on professional headphones. Not only do they sound amazing, are made to take a bit of a beating, they're almost always designed to be repaired.
I'm a fan of Sennheiser, AKG, Sony, et al.
Beats are for chumps.
I don't recommend spending less than $200.
You're going to wear these every single day for up to 8 hours. Get something that brings you joy to wear and hear. It will also help get you in the mood to work, knowing you get to listen to these awesome cans. If you can, use them exclusively for work.
6. Do your work.
Alright, you've got a sweet location.
You've got time to yourself.
(I often use a sign telling people to email me, instead of distracting me. A small question that throws you out of your trance can cost up to 20 minutes each, get a few of them and there goes your session.)
You've had your choice of stimulant. Please make it tea or coffee. They're so much better, just don't go overboard. Having 4 in a day scares me.
You have an idea of what your doing today.
DO IT.
Start slow. Ease your way into it.
Work on something easy. Enjoy your tea or coffee.
I often start by looking over what I have, or reading someone's post about something code related I saved to read.
If you've done this right, you should ease into doing work without actually realising it.
This my friend, is the much written about state called 'flow'.
You will forget there's even music playing (to the point where if it stops playing, it could be hours before you realise).
7. Let your mind wander.
It's time for a break though. You're mind has just be smashed with thinking. Thinking is hard. Fun, but damn it's hard. So do something else. Keep your headphones on, your music playing.
Time to let your mind wander.
It's very bad for your eyes to stare at a close distance for long periods of time. So kill two birds with one stone, stare of into the distance and give both your eyes and your brain a rest.
This shouldn't go for too long though. Maybe a couple of minutes.
Truth be told, you'll probably do this naturally.
8. Don't finish abruptly.
Like a good golf or tennis swing, the follow through is everything. Don't just jump up and go head first into something else.
You brain just spent 8 hours being intense. It needs a few minutes to de-brief.
This isn't time to waste though.
Keep your music in.
Take a moment to look back at what you have achieved today, and be damn proud of it. Didn't solve anything? Pfft, most people who succeed have more failures behind them than you'll ever know about. I have on more than one occasion spent weeks working on one problem, failing every single day to solve it. But each day, learning more about the problem at hand. I've never not solved a problem I've put time into. I'm sure I will one day, but that's when you ask for help.
Make deadlines, they'll encourage you to get stuff done. (Incidentally no GTD software or system, has ever worked well for me. Analogue lists with pen and paper, and backups [either typed or photos on an iphone] work better for me.)
The last thing you should to here, is plan out what you should do in your next session.
Issue trackers are cool, and invaluable in teams. But you need your own notes too.
"I’m not writing it down to remember it later, I'm writing it down to remember it now." - Field Notes
You should have a pen (a damn good pen) and a notebook (again, get a nice one). This is your analogue RAM. I'm a Moleskine person myself, but Field Notes also make some good notebooks. You don't put crappy RAM in you computer, so why should you use a crappy pen and paper. $30 will get you a pen like a Lamy (a nice solid aluminium pen), or maybe your lucky enough to have a Parker. It' doesn't matter what it is, but it should be special in some way. Like your headphones, and you notebook, you should look forward to getting to use them.
A good Moleskine or FN will cost around $20 and last maybe 2-3 months. You probably won't spend more than $300 a year on them. And if you do you're probably making enough money to spend more.
The point is, use gear you love. And love the gear you use.
Sure they're tools, but every good craftsman love's their tools.
9. It takes 28 days* to form a habit.
You will fail a lot.
Not just in life.
Not just in code.
If you can fail, you will :D
That's not a sadistic smile on the end of that sentence (which also purposely does not have a full stop in order to distress the OCD among us - okay that might be sadistic).
Failure is good.
I've always learnt more from what I got wrong, than what I got right. Usually because getting something right is often predicated on getting many things wrong beforehand.
That's life. If you don't like it, too bad. You're playing this game - you may as well learn the rules.
So however you decide to get into your state of trance or flow, stick to it. Choose one point to work on and get that to 'good enough', then move onto another point. When you finally have everything kind of going, refine it all.
Get your process working for you.
That last point is key to all of this. How I work best, likely differs from you.
*Is it 28 days? I honestly can't remember and it doesn't matter in this context. It's close enough to the right amount of time it should take you to get all this to be close enough to habit, that you don't even think about it.
EDIT:
Almost forgot this.
SLEEP.
Work out what you need each night, and don't take crap from anyone. You need to get the right amount of sleep to code. To solve problems. You need sleep. Good quality sleep.
All night coding binges are for chumps.