How can I implement this rate-limiting in my code? Please provide an example code snippet, together with helpful and descriptive comments.