Triac/Optocoupler Dimmer

The one I wanted to post is simpler but there is a good circuit in this app note: