from flask import Flask, send_from_directory
app = Flask(__name__)
def base_static(filename):
return send_from_directory(app.root_path + '/../static/', filename)
View nginx-default-conf
vim `/etc/nginx/sites-available/default`
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
View test-cssom.js
const css = require('css');
const crypto = require('crypto');
const assert = require('assert');
var style = `.foo {
color: green;
.bar {
color: red;
View Shadow-DOM.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Shadow DOM</title>
span {
color: green;
View kvs.erl
%% API
-export([start_link/0, store/2, lookup/1]).
%% gen_server callbacks
View method_missing.erl
'$handle_undefined_function'(Func, Args) ->
io:format("Called undefined function '~p' with args ~p.~n", [Func, Args]).
View stackexchange.txt
- Format: 7zipped
- Files:
- **badges**.xml
- UserId, e.g.: "420"
- Name, e.g.: "Teacher"
- Date, e.g.: "2008-09-15T08:55:03.923"
- **comments**.xml
- Id
- PostId
- Score
View translation.erl
-module (translation).
-export ([get_translation/1]).
get_translation(Word) ->
io:format("~p ~n", [Word]),
{ok, RequestId} = httpc:request(get, {"" ++ Word, []}, [], [{sync, false}]),
{http, {RequestId, Result}} ->
io:format("~p ~n", [Result])

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 erl_crash.dump
Mon Apr 3 11:19:47 2017
Slogan: init terminating in do_boot ()
System version: Erlang/OTP 19 [erts-8.3] [source-d5c06c6] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:true]
Compiled: Wed Mar 15 11:13:13 2017
Taints: erl_tracer
Atoms: 6622
Calling Thread: scheduler:6
Scheduler Sleep Info Flags: SLEEPING | TSE_SLEEPING | WAITING