Can we program or pre-define our last thoughts? I have heard the last thoughts of a person can define next life.

If so can we somehow define them through practice, so when the time comes they will be as we planned?

Or is there a practice that would cause them to be positive?
Autopositivity is indeed a great skill, virtue, accomplishment, and in its own way a paradise.  With constant watchfulness and training in the Four Immeasurables (the four Divine Abodes) ones natural and spontaneously occurring thoughts can be patterned and trained to be of a purely helpful and nonharmful nature. 

Essentially we are developing the skill of choosing positive conscious states and being patient with nonpositive states.  Anyway, as mentioned above, the four immeasurables are worthy of your immediate attention and application.