Skip to content

Instantly share code, notes, and snippets.

View BABA983's full-sized avatar
:shipit:

BABA BABA983

:shipit:
View GitHub Profile
@BABA983
BABA983 / falsehoods-programming-time-list.md
Created May 15, 2024 08:49 — forked from timvisee/falsehoods-programming-time-list.md
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@BABA983
BABA983 / fix-git-commit.sh
Created March 6, 2024 09:43
fix-git-commit.sh
#!/bin/bash
git filter-branch -f --env-filter '
OLD_EMAIL=""
CORRECT_NAME=""
CORRECT_EMAIL=""
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@BABA983
BABA983 / keybinds.json
Created January 30, 2024 02:05
vscode-settings
{
// window move down
"key": "ctrl+j",
"command": "vim.remap",
"when": "vim.mode == 'Normal' && !suggestWidgetVisible && !inQuickOpen",
"args": {
"after": [
"<c-w>",
"j"
]

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.