Skip to content

Instantly share code, notes, and snippets.

View jsvisa's full-sized avatar
🏠
Working from home

Delweng jsvisa

🏠
Working from home
View GitHub Profile

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.

@MrChrisJ
MrChrisJ / 20170127--Bitfinex_Hacked_Coins.csv
Last active May 15, 2025 04:28
20170127--Bitfinex_Hacked_Coins.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 8 columns, instead of 1 in line 6.
Transaction Hash,Block Height,Date,Receiving address,Peer Cluster,Peer Name,Peer Category,Sent
a6a1c3e02bfe6ba0d49205841a066b7655070cf15d88baf7ff626051cfe39ee4,449876,2017-01-25 03:04:35,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,,,4.04631276
af16fea36591e43651d0f90c689a191e71f39f139c8c6c76ca6a94de1defbad9,449876,2017-01-25 03:04:35,1nL6u6dyeF5cp2vTvsG2jjfMqxQm1Z3fb,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,,,4.0455642
443706320e569141074a7ba6d3b488b3142928e386f1d4ca3ad0cbc3ea58eeb6,449876,2017-01-25 03:04:35,1D1LKbyLcWSsayaQwZYpE81Wnguhfgx14i,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,,,3.99877463
025e804d46520b0350dc5673df47feb2ea6c2690bd21e9e3fccc28e81c4cbfac,449876,2017-01-25 03:04:35,15RDbnXTpUeHqdK8S4CCVeukQseYs6kEBK,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,,,3.9926336
162dd46b873da7348f9a482063e0a39923b1a43fda29d0f0a374fa0de5407279,449876,2017-01-25 03:04:35,172gmUnva3vF1XsPwjkzJmwD8iFkbiqZse,1D38A8TJHAQfEGdoirE1WpXPEh7NMNHT5L,,,4.07657504
a67bf29545ee84fe3a3ad986a1a8d5d0d6fce54b51eaff5ca58e052eb
@eliquious
eliquious / README.md
Created January 4, 2016 05:01
Golang OpenPGP examples

Building

go build -o goencrypt main.go

Generating Keys

@muink
muink / Clear-unwanted-URL-on-Chrome-address-bar.md
Created October 28, 2015 07:57
删除Chrome地址栏记录中不需要的网址

删除Chrome地址栏记录中不需要的网址(访问历史)

Chrome的地址栏自动补齐功能提供了非常方便的地址预测功能 浏览器可以通过用户当前输入的字符来与用户的访问历史与书签匹配 然后在下拉栏中为用提供准确的补齐方案排名, 提高用户访问效率

在大部分情况下, 这个功能是非常好用的 但是有时, 出于某些原因, 用户需要移除某个记录(网址无法访问,网址更换域名等) Chrome提供了组合键Shift+Delete来删除地址栏下拉记录中的某个网址

@janlay
janlay / README.md
Last active January 7, 2026 03:39
Yet another config for Surge.app

Install

  1. Modify index.txt with your output path and proxy info
  2. Use Text Builder to build configuration for Surge: $ text-builder -index /path/to/index.txt Or run $ sh build-all to build all your index files.
  3. Import configuration via AirDrop/iTunes/Dropbox/iCloud

本人不提供任何保证和技术支持,使用者自负风险。
There are no guarantees, no any support. Use it at your own risk.

@romainl
romainl / .ctags
Last active December 3, 2025 14:50
My ctags config
--langdef=less
--langmap=less:.less
--regex-less=/^[ \t&]*#([A-Za-z0-9_-]+)/\1/i,id,ids/
--regex-less=/^[ \t&]*\.([A-Za-z0-9_-]+)/\1/c,class,classes/
--regex-less=/^[ \t]*(([A-Za-z0-9_-]+[ \t\n,]+)+)\{/\1/t,tag,tags/
--regex-less=/^[ \t]*@media\s+([A-Za-z0-9_-]+)/\1/m,media,medias/
--regex-less=/^[ \t]*(@[A-Za-z0-9_-]+):/\1/v,variable,variables/
--regex-less=/\/\/[ \t]*(FIXME|TODO)[ \t]*\:*(.*)/\1/T,Tag,Tags/
--langdef=scss
@P7h
P7h / tmux__CentOS__build_from_source.sh
Last active October 11, 2025 01:02
tmux 2.0 and tmux 2.3 installation steps for Ubuntu. Or build from tmux source v2.5 for Ubuntu and CentOS.
# Steps to build and install tmux from source.
# Takes < 25 seconds on EC2 env [even on a low-end config instance].
VERSION=2.7
sudo yum -y remove tmux
sudo yum -y install wget tar libevent-devel ncurses-devel
wget https://github.com/tmux/tmux/releases/download/${VERSION}/tmux-${VERSION}.tar.gz
tar xzf tmux-${VERSION}.tar.gz
rm -f tmux-${VERSION}.tar.gz
cd tmux-${VERSION}
@pnc
pnc / observer.md
Last active April 1, 2025 21:38
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
#!/bin/sh
remove_dangling() {
echo "Removing dangling images ..."
docker rmi $(docker images -f dangling=true -q)
}
remove_stopped_containers() {
echo "Removing stopped containers ..."
docker rm $(docker ps -qa)
@allex
allex / gist:11203573
Last active June 3, 2024 13:32
Ubuntu 安装中文字体

环境 (Environment)

版本:Ubuntu 14.04 LTS 默认语言:English(United States)

安装 (Setup)

Debian 和 Ubuntu 下对中文支持比较好的字体有: fonts-droid、ttf-wqy-zenhei 和 ttf-wqy-microhei 等,除了文泉驿系列字体外,比较流行的免费中文字体还有文鼎提供的楷体和上海宋,包名分别是: fonts-arphic-ukai 和 fonts-arphic-uming。