Skip to content

Instantly share code, notes, and snippets.

View sachaarbonel's full-sized avatar
👨‍💻
Uncovering bugs

Sacha Arbonel sachaarbonel

👨‍💻
Uncovering bugs
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.

@sachaarbonel
sachaarbonel / flask_ajax.py
Created August 22, 2020 10:43 — forked from MalphasWats/flask_ajax.py
Making a basic AJAX request with Flask
# Answer to a question on Flask mailing list
# http://librelist.com/browser//flask/2012/6/30/using-ajax-with-flask/
# NOTE: *REALLY* don't do the thing with putting the HTML in a global
# variable like I have, I just wanted to keep everything in one
# file for the sake of completeness of answer.
# It's generally a very bad way to do things :)
#
from flask import (Flask, request, jsonify)
app = Flask(__name__)
@sachaarbonel
sachaarbonel / psuedo-catalogue.html
Created August 16, 2020 17:27
Stripe complete payment cycle
<h2> Purchasable APIs</h2>
<script>
window.onload = function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/public-apis/pub-catalogues",
beforeSend: function()
{
@sachaarbonel
sachaarbonel / change_notifier.dart
Created July 28, 2020 20:53 — forked from rrousselGit/change_notifier.dart
A benchmark that compares before and after performances for notifyListeners of ChangeNotifier
import 'observer_list.dart';
typedef VoidCallback = void Function();
class ChangeNotifier {
ObserverList<VoidCallback> _listeners = ObserverList<VoidCallback>();
bool get hasListeners {
return _listeners.isNotEmpty;
}
package com.example.app.myapplication;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
public class ColorFilterGenerator {
private static double DELTA_INDEX[] = {
0, 0.01, 0.02, 0.04, 0.05, 0.06, 0.07, 0.08, 0.1, 0.11,

Dart VM FFI Vision

Background

The aim of Dart FFI project (tracked as Issue #34452) is to provide a low boilerplate, low ceremony & low overhead way of interoperating with native C/C++ code.

The motivation behind this project is twofold:

@sachaarbonel
sachaarbonel / _.js
Created February 10, 2020 09:09 — forked from shamansir/_.js
Parse and convert any SVG path to the list of commands with JavaScript + Regular Expressions
// svgPathToCommands('M10,10 l 5,7 C-5,7.2,.3-16,24,10 z');
//
// produces:
//
// [ { marker: "M", values: [ 10, 10 ] },
// { marker: "l", values: [ 5, 7 ] },
// { marker: "C", values: [ -5, 7.2, 0.3, -16, 24, 10 ] },
// { marker: "z", values: [ ] } ]
//
// commandsToSvgPath(svgPathToCommands('M10,10 l 5,7 C-5,7.2,.3-16,24,10 z'))
@sachaarbonel
sachaarbonel / graph-vis.html
Created February 7, 2020 07:07 — forked from kevinfjbecker/graph-vis.html
HTML5 Canvas Graph View
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>graph-vis</title>
</head>
<body>
<canvas id="viewer" width="800" height="500"></canvas>
<script src="graph-vis.js"></script>
</body>
@sachaarbonel
sachaarbonel / price1.md
Created December 3, 2019 10:07 — forked from GerardLutterop/price1.md
Cost table additional work
Activity Amount of work
Research 2–3 days
Design url’s, security 5–10 days
Build a prototype 3–5 days
Minimum viable product 5 days
Monitoring and alerting 2–3 days
Documentation (somebody will use your API!) 1–2 days
Selecting hosting, deployment 3–5 days
Deployment
@sachaarbonel
sachaarbonel / price2.md
Created December 3, 2019 09:59 — forked from GerardLutterop/price2.md
Cost table API, total cost
Activity Amount of work
Research 3-6 days
Design url's, database, security 10-15 days
Build a prototype 5-8 days
Minimum viable product 5-10 days
Full product 10-20 days
Monitoring and alerting 3-5 days
Documentation (somebody will use your API!) 1-2 days
Selecting hosting, deployment 5-8 days