Generally speaking, we use some for positive forms and any for negative forms and questions. But there are some exceptions.
Study this example:
Would you like to have ____ coffee with your meal, Sir? asked the waiter. I think the correct word is some, because it is an offer by waiter. Am I wrong?
Michael Lewis [The English Verb, (1986), Hove: LTP] wrote:
“Both some and any are used with indefinite reference.
Some is used if the idea is restricted or limited in some way.
Any is used if the idea is unrestricted or unlimited.
Any applies to all or none; some applies to part.
The restriction may be a real one – There’s some cheese in the fridge – or a psychological one, existing only in the mind of the speaker – Would you like something to eat?
The real semantic distinction is as simple as that, and applies to all uses of some and any.”
Lewis could have added, "and to all words begining with some or any - ~one, ~body, ~thing, ..."
I reckon it summarizes all rules and exceptions to an easy memorizable rule. By the way has Michael Lewis written any English grammar book?
Its title is You got it
Every time I look into your lovely eyes,
I see a love that money just can't buy.
One look from you, I drift away.
I pray that you are here to stay.
Anything you want, you got it.
Anything you need, you got it.
Anything at all, you got it.
Here the meaning of anything is applied to all. It sounds as everything to my ears.
To continue, we can use any and no + comparatives. For example Bill is not any smarter than Jane.