'Before' and 'of' are prepositions. Other prepositions are, for example : by, with, without, in, at, on, after, for
If you have a verb following any of these words, it is ALWAYS in the 'ing' form ( gerund). A gerund is a verb functioning as a noun. For example:
by speaking, with reading, without looking etc.
The only exception to this rule is the preposition 'to', which is sometimes followed by the gerund, but it also is often part of the infinitive form (to speak). '
1. This should be: 'I think that after writing this entry I'm going to sleep, because it is very late in Colombia and I'm getting sleepy.'
i.e. the phrase should be 'after writing', not 'after of'.
2. The gerund use is fine here, but the sentence would be better as either 'I had the idea of studying abroad a long time ago' (past simple) or 'I've had the idea of studying abroad for a long time' (present perfect).
3 & 4. These are fine. They are examples of the gerund as the subject of a sentence : 'Writing English is very useful'.