Skip to content

Instantly share code, notes, and snippets.

View dotBits's full-sized avatar
🔥
burning fast

Cristian Ronzio dotBits

🔥
burning fast
View GitHub Profile
@lsimone
lsimone / egghead courses download
Created October 22, 2017 21:19
Download free egghead.io videos
#!/bin/bash
list=`lynx -source $1 | grep -o -e 'https[^"]*.m3u8' | xargs`
course="${1##*/}"
mkdir $course
echo ">>> $(echo $list | wc -w) video(s) found"
c=1
for video in $list

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.