.
├── main.go
└── templates
├── confirmation.html
└── index.html
├── golang-response-snippets.go
├── images
│ └── had.jpg
├── templates
│ ├── index.html
│ ├── layout.html
│ └── render_string.html
link: http://www.alexandrejoseph.com/blog/2015-08-21-python-mock-example.html
Directory structure:
pyqueue
├── README.md
├── pyqueue
│ ├── __init__.py
│ ├── queue.py
The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.
In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.
This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import logging | |
from logging.handlers import RotatingFileHandler | |
from flask import Flask, request, jsonify | |
from flask_sqlalchemy import get_debug_queries | |
from ext import db | |
from users import User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
""" | |
desc.. | |
:copyright: (c) 2016 by fangpeng(@beginman.cn). | |
:license: MIT, see LICENSE for more details. | |
""" | |
import hmac | |
import hashlib | |
import base64 | |
import redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
:Author: beginman.cn | |
:Mail: pythonsuper@gmail.com | |
:Created Time: 2017-02-07 16:16:36 | |
:Last modified: 2017-02-07 16:16:36 | |
:Copyright: (c) 2016 by beginman. | |
:License: MIT, see LICENSE for more details. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by 方朋 on 2017/1/4. | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define OK 1 | |
#define ERROR 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by 方朋 on 2017/1/6. | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#define OK 1 | |
#define ERROR 0 | |
#define TRUE 1 |