Skip to content

Instantly share code, notes, and snippets.

View dongyuwei's full-sized avatar
💭
天天听儿歌

dongyuwei dongyuwei

💭
天天听儿歌
View GitHub Profile
@dongyuwei
dongyuwei / nginx-default-conf
Last active July 17, 2017 05:43
letsencrypt certbot-auto
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;
server_name erlang.us;
@dongyuwei
dongyuwei / test-cssom.js
Created July 10, 2017 02:42
test cssom, demonstrate a minimum css module implementation
const css = require('css');
const crypto = require('crypto');
const assert = require('assert');
var style = `.foo {
color: green;
}
.bar {
color: red;
}
@dongyuwei
dongyuwei / Shadow-DOM.html
Created July 7, 2017 03:43
Shadow DOM demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shadow DOM</title>
<style>
span {
color: green;
}
</style>
@dongyuwei
dongyuwei / kvs.erl
Created June 29, 2017 03:10
a simple key-value server implemented by Erlang gen_server
-module(kvs).
-behaviour(gen_server).
%% API
-export([start_link/0, store/2, lookup/1]).
%% gen_server callbacks
-export([init/1,
handle_call/3,
handle_cast/2,
@dongyuwei
dongyuwei / method_missing.erl
Last active July 10, 2017 02:46
Erlang's method_missing : '$handle_undefined_function'
-module(method_missing).
-export(['$handle_undefined_function'/2]).
'$handle_undefined_function'(Func, Args) ->
io:format("Called undefined function '~p' with args ~p.~n", [Func, Args]).
- 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
-module (translation).
-export ([get_translation/1]).
get_translation(Word) ->
io:format("~p ~n", [Word]),
inets:start(),
{ok, RequestId} = httpc:request(get, {"http://fanyi.dict.cn/search.php?q=" ++ Word, []}, [], [{sync, false}]),
receive
{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.

@dongyuwei
dongyuwei / erl_crash.dump
Created April 3, 2017 03:31
latest make-proxy ./start_server.sh crashed
=erl_crash_dump:0.3
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:1
Scheduler Sleep Info Flags: SLEEPING | TSE_SLEEPING | WAITING

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style