View signal.go
package main
import (
"fmt"
"time"
"os"
"os/signal"
"syscall"
)
View access.lua
function password_encode(password)
local bcrypt = require 'bcrypt'
return bcrypt.digest(password, 12)
end
function check_password(password, encoded_password)
local bcrypt = require 'bcrypt'
return bcrypt.verify(password, encoded_password)
end
View Dockerfile
# Version 0.0.1
FROM ubuntu:14.04
MAINTAINER Beginman "xinxinyu2011@163.com"
ARG CHAINA_APT_SOURCE
RUN /bin/bash -c "if [[ ${CHAINA_APT_SOURCE} == ON ]];then sed -i 's#http://archive.ubuntu.com#http://mirrors.163.com#g' /etc/apt/sources.list; fi"
RUN apt-get update
RUN apt-get install -y lua5.1
RUN apt-get install -y liblua5.1-dev
RUN apt-get install -y git
RUN apt-get install -y nginx
View Main.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Main {
/**
* 步骤:
* 1. File 创建文件句柄
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Galenic">
<script src="js/jquery-1.9.1.js"></script>
<script src="js/knockout-2.1.0.js"></script>
<script src="js/Chart.js"></script>
<link rel="stylesheet" href="pure-min.css">
View READEME.md
.
├── main.go
└── templates
    ├── confirmation.html
    └── index.html
View READEME.md
├── golang-response-snippets.go
├── images
│   └── had.jpg
├── templates
│   ├── index.html
│   ├── layout.html
│   └── render_string.html
View READEME.md
View 0-rate-limiters.md

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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<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>