The mask layer for the first example would just be a bunch of circles, and the animated gradient would be the layer that is being masked.
For the second one the general approach would be to have a mask layer that is exactly like the writing, then make a key frame in the mask layer and delete some of the mask. Make another keyframe and delete more. Keep going until all of the mask layer is erased. Now select the frames in the mask layer, right-click, and choose Reverse Frames. You should then have the handwriting effect you see in the example.
Don't forget that you only see the effect of the mask when doing a Test Movie, or if you lock both layers.