If a man carried a bag of gunpowder with him!

(George Everard, "Heart-Work" 1871)

"Watch over your heart with all diligence, for from it flow the issues of life." Proverbs 4:23

Remember that the heart regulates the life. If the heart is right, then . . .
  the hands will do right — they will not steal or be idle, but do their work faithfully;
  the feet will move right, not going where they should not, standing in the way of sinners, or treading forbidden paths — but walking straight in the ways of godliness;
  the eyes will look right, not coveting forbidden fruit, or reading debasing literature — but spying out work that ought to be done, and looking kindly and pleasantly on those around;
the ears will hearken aright, not eagerly drinking in false reports, or the advice of those who have not yet learned to teach themselves — but ever willing to listen to a faithful reproof, or to a word of wise counsel;
  the lips will speak aright, not uttering words of slander, or falsehood, or folly — but words of truth and purity and love, words of earnest prayer and of grateful praise.

But HOW shall the heart be kept right?

1. First of all, remember that He  who made the heart, can alone fashion and dispose it to that which is good. Whatever is amiss, He knows how to remedy it:
  He gives it a new mainspring — He puts within it the love of Christ, instead of the love of the world;
  He sends His Holy Spirit to control and order its unruly passions and affections;
  He can cleanse it from all its defilements;
  When the chain is off the wheel, He can replace it — I mean, when something has turned our desires from their right object, He can restore them.

Then ask earnestly for grace, "Create in me a clean heart, O God! Incline my heart to Your testimonies! Let my heart be sound in Your statutes that I may honor You!"

But then, He bids us to be workers together with Him in this matter. There is that which He alone can do — but there is that which is our part by His grace to do also.

2. You must take care not to run into scenes of temptation. If a man carried a bag of gunpowder with him, he would be very careful not to go where sparks were flying about — he would feel that in a moment a spark might be his destruction.

Now your heart is very like that gunpowder — a little thing may set it all alight with evil passions! Words may be spoken that may arouse unholy thoughts or desires — therefore be careful. Never go near places where the devil is accustomed to come. Keep far away from the theater, the dancing-room, and never enter the bar of a tavern if you can avoid it.

3. You must watch against any evil thoughts lodging in your mind. You may not be able to prevent them arising, but endeavor to drive them away as soon as you can. A flock of birds may fly over your head — but you would not let them build a nest in your hair! Little flies or insects in summer are very troublesome sometimes — but you take pains to keep them from getting into your eyes, or irritating your face and hands. In the same way, watch against every bad thought.

Remember that among the thousands of thoughts that pass through your mind in a day, there is not one hidden from God! He understands your thoughts afar off, and in His sight the thought of foolishness is sin. Therefore be watchful — do not dwell on anything that may pollute the mind. Cast away murmuring thoughts, angry thoughts, impure thoughts — and pray that God would preserve you from them. "Let the words of my mouth, and the meditation of my heart be always acceptable in Your sight, O Lord!"

4. But to keep away thoughts that do harm — nourish thoughts that will do you good. "Finally, brothers . . .
  whatever is true,
  whatever is noble,
  whatever is right,
  whatever is pure,
  whatever is lovely,
  whatever is admirable,
  if anything is excellent or praiseworthy
 — think about such things." Philippians 4:8
There is a good old proverb, "Fill the sack with wheat — and there will be no room for chaff!" Fill your heart with kind thoughts, grateful thoughts, holy thoughts — and you will be safe. Let God's thoughts which are given to us in the Bible — leaven all your thoughts. Hide in your heart the promises and precepts of His Word.

5. But above all, live in a spirit of prayer. Believe that God is always ready to hear you — and often go to Him for help. Draw near to God — and He will draw near to you. Nothing will keep your heart in a holy, happy frame, so much as prayer.