Skip to content

Instantly share code, notes, and snippets.

View amitmahbubani's full-sized avatar
🤓

Amit Mahbubani amitmahbubani

🤓
View GitHub Profile
@amitmahbubani
amitmahbubani / notify.yml
Created July 1, 2020 22:20 — forked from trung/notify.yml
Notify slack about Github Actions workflow and its jobs status. `notify` job must be the last job in the workflow and it must depend on all other jobs
notify:
if: always()
name: Notify
needs:
- job1
- job2
- job11
- job3
- job4
runs-on: ubuntu-latest
{
"level": "info",
"ts": 1589785322.1196852,
"caller": "logger/logger.go:36",
"msg": "logger initialized",
"context": {
"request": {
"id": "1234567",
"source": "sourcevalue",
"rpcservice": "servicev",
@amitmahbubani
amitmahbubani / build.sh
Created November 1, 2018 13:20 — forked from bobbytables/build.sh
Protocol Buffer build script for multiple folders
#!/usr/bin/env bash
# This script is meant to build and compile every protocolbuffer for each
# service declared in this repository (as defined by sub-directories).
# It compiles using docker containers based on Namely's protoc image
# seen here: https://github.com/namely/docker-protoc
set -e
REPOPATH=${REPOPATH-/opt/protolangs}
CURRENT_BRANCH=${CIRCLE_BRANCH-"branch-not-available"}

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.

@amitmahbubani
amitmahbubani / slim-redux.js
Created May 26, 2017 16:02 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {