Skip to content

Instantly share code, notes, and snippets.

redis-rate-limiter

This document specifies a concept for a multi-level rate limiting procedure that can be used to implement rate limiting of many kinds. It should be considered a work in progress!

This document describes the schema that should be utilized.

Limiting Keys

Each user shall be assigned a multi-level set of limiting that must pass for any request to continue.

const ms = delay => new Promise(resolve => setTimeout(resolve, delay));
async function* iterate() {
let i = 0;
try {
const done = false;
while (!done) {
try {
await ms(1000);
i += 1;
@bradennapier
bradennapier / notification.saga.js
Last active February 26, 2019 21:12
Saga Defer Example
import _ from 'lodash';
import {
take,
call,
put,
fork,
spawn,
delay,
cancel
} from 'redux-saga/effects';
@bradennapier
bradennapier / bot-bot.js
Last active March 28, 2019 17:55
Example of a Slack API flow using AWS, SQS, and a nice automated handling of commands
/* @flow */
import type { Bot$Interface } from 'types/bot';
import slack from 'lib/slack';
import * as utils from './utils';
function handleDeferredExecution(result) {
if (bot.state.isWorker) {
@bradennapier
bradennapier / aurad-amazon-linux-2.md
Last active April 3, 2019 22:45
AuraD on Amazon Linux 2

Install the Essentials

# Install Docker and start the daemon
sudo amazon-linux-extras install docker
sudo service docker start

# Allow running docker without sudo
sudo usermod -a -G docker ec2-user
@bradennapier
bradennapier / aurad-startup.md
Last active April 4, 2019 18:52
Aurad Startup Alias

Startup Alias Tip

When using infura, our aura start command requires a flag --rpc <url> each time we start it up. It can become tedious to do this on every startup, so here is a simple trick to simplify this!


  1. Login to your staking server

  2. Type vi ~/.bashrc into terminal then Enter to enter vim

@bradennapier
bradennapier / validateCognito.js
Last active August 27, 2019 08:43
Just a rough sketch for validating cognito tokens
/* @flow */
import axios from 'axios';
import jose from 'node-jose';
import day from 'dayjs';
const AWS_REGION = '<AWS_REGION>';
const AWS_POOL_ID = '<POOL_ID>';
const AWS_APP_CLIENT_ID = '<APP_CLIENT_ID>';
const AWS_TOKEN_PUBLIC_KEYS_URL =
`https://cognito-idp.${AWS_REGION}.amazonaws.com/${AWS_POOL_ID}/.well-known/jwks.json`;
@bradennapier
bradennapier / recursive-install.js
Last active December 7, 2023 15:44
Recursively find and install dependencies in subdirectories
const path = require('path');
const { promises: fs } = require('fs');
const cp = require('child_process');
/*
Recursively iterates and finds subdirectories which have a `package.json` file and does a dependency installation based
on the given configuration.
- can be setup to use yarn or npm
- can be setup to determine the command to use based on lock files so that if you set it to use yarn but a directory only
@bradennapier
bradennapier / ManjaroV20ParallelsGuide.md
Last active May 16, 2025 17:37
Manjaro v20 w/ Parallels Tools

So getting Parallels to work with Manjaro v20 (and probably v19 since parallels only says they support v18) was a pain in the butt and it took a lot of resources from a lot of places to figure it all out. I figured I would post some information here on things that I ran into and how to fix each of them.

This is from a completely fresh installation from the v20 isos but steps may be applicable in places for upgrades if you run into similar issues.

I got this all working finally:


Manjaro Version: 20.0 Desktop Environment: KDE

@bradennapier
bradennapier / globals.d.ts
Last active January 19, 2023 10:42
Typescript type resolution utility
/**
* Types declared in this file will be globally available throughout the project. These should
* be used sparsely and mainly for utility types (such as $Debug) that are likely unused outside
* of being helper utilities.
*
* @note
* If needing to `import` in this file, the global types must all be wrapped in
* `declare global` or they will no longer be seen as global.
*/