Simplest way to calculate AME, MEM, MER?

What is the simplest way to calculate average marginal effect, marginal effect at the mean and marginal effect at representative values for a logit model?
I found this example, but the explanation is messy and frankly I don't understand it:
example