Skip to content

Instantly share code, notes, and snippets.

View dchae's full-sized avatar
:shipit:

Daniel Chae dchae

:shipit:
View GitHub Profile
import numpy as np
import numpy.testing as npt
from itertools import product
b = np.array([
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],
[0, 1, 0, 0, 0, 0, 1, 0, 1, 0,],
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0,],
[0, 0, 0, 1, 0, 0, 0, 0, 1, 0,],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0,],

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.

@lopspower
lopspower / README.md
Last active November 12, 2025 15:05
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha:

@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #