Skip to content

Instantly share code, notes, and snippets.

View adelarsq's full-sized avatar
🐢
I may be really slow to respond.

Adelar da Silva Queiróz adelarsq

🐢
I may be really slow to respond.
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.

@adelarsq
adelarsq / rfc3161.txt
Created August 8, 2018 18:22 — forked from Manouchehri/rfc3161.txt
List of free rfc3161 servers.
http://sha256timestamp.ws.symantec.com/sha256/timestamp
http://timestamp.globalsign.com/scripts/timstamp.dll
https://timestamp.geotrust.com/tsa
http://timestamp.verisign.com/scripts/timstamp.dll
http://timestamp.comodoca.com/rfc3161
http://timestamp.wosign.com
http://tsa.startssl.com/rfc3161
http://time.certum.pl
http://timestamp.digicert.com
https://freetsa.org
@adelarsq
adelarsq / dotfiles
Created May 23, 2019 13:35 — forked from jonathan-soifer/dotfiles
System and Shell setting for happiness and productivity
# Softwares that I currently use:
• Productivity Related Software (VPN, 1Password, CleanMyMac, Alfred, BetterSnapTool, DisableMonitor, Unarchiver)
• Design Related Software (Sketch, Zeplin, Skyfonts, Wacom, Adobe Photoshop, Adobe Illustrator)
• Terminal Software (iTerm2, Z-Shell, Oh My ZSH, Agnoster Fcamblor Theme, Z Script - Jump Around)
• Terminal Related Tools (xcode-tools, homebrew, git, nvm, rvm, ripgrep, ngrok, curl, eslint)
• Fonts (Source Code Pro for iTerm2 and Spacemacs, Fira Code Symbol for Spacemacs)
• Video Related Software (Adobe After Effects, Premiere, ScreenFlick, QuickTime)
• Browsers Extensions (1Password, Pocket, React DevTools, Redux DevTools)
• Communication Related Software (Zoom.us, What'sapp, Slack, Mac Mail)
@adelarsq
adelarsq / LetsDestroyC.md
Created January 30, 2020 13:58 — forked from shakna-israel/LetsDestroyC.md
Let's Destroy C

Let's Destroy C

I have a pet project I work on, every now and then. CNoEvil.

The concept is simple enough.

What if, for a moment, we forgot all the rules we know. That we ignore every good idea, and accept all the terrible ones. That nothing is off limits. Can we turn C into a new language? Can we do what Lisp and Forth let the over-eager programmer do, but in C?


local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
configs.omnisharp = {
default_config = {
cmd = {'omnisharp_lsp_run','-lsp'};
filetypes = {'cs','csx','cake','vb'};
root_dir = util.root_pattern("Makefile");
};
docs = {
Plug 'https://github.com/mattn/webapi-vim'
Plug 'https://github.com/vim-jp/vital.vim'
Plug 'https://github.com/xolox/vim-misc'
Plug 'https://github.com/LucHermitte/lh-vim-lib'
Plug 'https://github.com/Shougo/vimproc.vim'
Plug 'https://github.com/tpope/vim-dispatch'
Plug 'https://github.com/junegunn/vim-emoji.git'
Plug 'https://github.com/arecarn/vim-selection'
Plug 'https://github.com/roxma/nvim-yarp'
Plug 'https://github.com/roxma/vim-hug-neovim-rpc'
// This sample will guide you through elements of the F# language.
//
// *******************************************************************************************************
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter in Windows or
// Ctrl-Enter Mac, or right-click and select "Send Selection to F# Interactive".
// You can open the F# Interactive Window from the "View" menu.
// *******************************************************************************************************
//
// For more about F#, see:
// http://fsharp.org
@adelarsq
adelarsq / latency.txt
Created October 3, 2020 20:40 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@adelarsq
adelarsq / ProtobufSerializationTest.fs
Created May 25, 2021 02:29 — forked from object/ProtobufSerializationTest.fs
Protobuf serialization in F#
module ProtobufSerializationTests
open System
open System.IO
open ProtoBuf
open Xunit
module ProtoBufUtils =
[<ProtoContract>]
@adelarsq
adelarsq / fsharp-tutorial.fs
Created May 25, 2021 02:40 — forked from odytrice/fsharp-tutorial.fs
F# Code Samples
// This sample will guide you through elements of the F# language.
//
// *******************************************************************************************************
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter in Windows or
// Ctrl-Enter Mac, or right-click and select "Send Selection to F# Interactive".
// You can open the F# Interactive Window from the "View" menu.
// *******************************************************************************************************
// For more about F#, see: