Skip to content

Instantly share code, notes, and snippets.

View colinhoernig's full-sized avatar

Colin Hoernig colinhoernig

View GitHub Profile

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.

@diegoconcha
diegoconcha / redux_egghead_notes.md
Last active January 18, 2022 13:23
Redux Egghead.io Notes

###Redux Egghead Video Notes###

####Introduction:#### Managing state in an application is critical, and is often done haphazardly. Redux provides a state container for JavaScript applications that will help your applications behave consistently.

Redux is an evolution of the ideas presented by Facebook's Flux, avoiding the complexity found in Flux by looking to how applications are built with the Elm language.

####1st principle of Redux:#### Everything that changes in your application including the data and ui options is contained in a single object called the state tree

@bishboria
bishboria / springer-free-maths-books.md
Last active April 25, 2024 06:27
Springer made a bunch of books available for free, these were the direct links
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@jj1bdx
jj1bdx / config-example.sh
Last active October 4, 2016 05:38
OpenSSH config example for OS X Yosemite 10.10.x
brew tap homebrew/dupes
# For OpenSSH 6.9p1 or later
brew install openssh --with-ldns
# NOTE: editing LaunchAgent is no longer supported in HomeBrew
# See https://github.com/Homebrew/homebrew-dupes/pull/482#issuecomment-118994372
# edit LaunchDaemons (as administrator/root)
launchctl unload -w /System/Library/LaunchDaemons/ssh.plist
vi /System/Library/LaunchDaemons/ssh.plist
launchctl load -w /System/Library/LaunchDaemons/ssh.plist
# check sshd_config
@g-cassie
g-cassie / gist:ff54a3d29bc8358892be
Created September 29, 2014 21:08
Using pdf.js in an Ember View
/**
* @class pdfView
* @extends {Ember.View}
*/
var PDFView = Ember.View.extend({
tagName: 'canvas',
/**
* Url to pdf file.
* @property src
* @type {string}
@h4cc
h4cc / restart_graylog2_services.sh
Created May 1, 2014 10:48
Commands needed to stop and restart all services in a Graylog2 server.
# Stop all services in needed order.
service graylog2-web stop; service graylog2-server stop; service elasticsearch stop; service mongodb stop;
# Start all services in needed order.
# - sleep is needed, so ES and Mongo have time to startup.
service elasticsearch start; service mongodb start; sleep 5; service graylog2-server start; service graylog2-web start;
@knownasilya
knownasilya / ajax.js
Last active June 22, 2016 14:37
RSVP jquery ajax wrapper
function ajax(url, options) {
return new Ember.RSVP.Promise(function (resolve, reject) {
options = options || {};
options.url = url;
options.success = function (data) {
Ember.run(null, resolve, data);
};
options.error = function () {
@chrismccoy
chrismccoy / gitcheats.txt
Last active April 20, 2024 08:50
git cheats
# alias to edit commit messages without using rebase interactive
# example: git reword commithash message
reword = "!f() {\n GIT_SEQUENCE_EDITOR=\"sed -i 1s/^pick/reword/\" GIT_EDITOR=\"printf \\\"%s\\n\\\" \\\"$2\\\" >\" git rebase -i \"$1^\";\n git push -f;\n}; f"
# edit all commit messages
git rebase -i --root
# clone all your repos with gh cli tool
gh repo list --json name -q '.[].name' | xargs -n1 gh repo clone
@t-io
t-io / osx_install.sh
Last active October 22, 2023 13:04
Install most of my Apps with homebrew & cask
#!/bin/sh
echo Install all AppStore Apps at first!
# no solution to automate AppStore installs
read -p "Press any key to continue... " -n1 -s
echo '\n'
echo Install and Set San Francisco as System Font
ruby -e "$(curl -fsSL https://raw.github.com/wellsriley/YosemiteSanFranciscoFont/master/install)"
echo Install Homebrew, Postgres, wget and cask
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"