├── main.go
└── templates
    ├── confirmation.html
    └── index.html
├── golang-response-snippets.go
├── images
│   └── had.jpg
├── templates
│   ├── index.html
│   ├── layout.html
│   └── render_string.html

Scaling your API with rate limiters

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.

Request rate limiter

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.

View frame-summary.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Coverage Report</title>
<link title="Style" type="text/css" rel="stylesheet" href="css/main.css"/>
<link title="Style" type="text/css" rel="stylesheet" href="css/sortabletable.css"/>
<script type="text/javascript" src="js/popup.js"></script>
<script type="text/javascript" src="js/sortabletable.js"></script>
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:


start new with session name:

tmux new -s myname
# 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
# coding=utf-8
:copyright: (c) 2016 by fangpeng(
:license: MIT, see LICENSE for more details.
import hmac
import hashlib
import base64
import redis
#!/usr/bin/env python
# -*- coding: utf-8 -*-
: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.
View 二叉树链式存储与遍历.c
// Created by 方朋 on 2017/1/4.
#include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0