Skip to content

Instantly share code, notes, and snippets.

View ajinkyakulkarni's full-sized avatar

Ajinkya Kulkarni ajinkyakulkarni

View GitHub Profile
@ajinkyakulkarni
ajinkyakulkarni / analysis.draft.md
Created November 6, 2021 18:24 — forked from MattPD/analysis.draft.md
Program Analysis Resources (WIP draft)
@ajinkyakulkarni
ajinkyakulkarni / LICENSE.txt
Created January 22, 2018 03:10 — forked from tlrobinson/LICENSE.txt
Extremely simple lexer, parser, compiler, and interpreter for a prefix notation calculator.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Tom Robinson <http://tlrobinson.net/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ajinkyakulkarni
ajinkyakulkarni / example.txt
Created December 13, 2017 22:40 — forked from Thorium/example.txt
File parsing, based on multiple lines, using recursive pattern matching with many :: (cons) operator
== MyItem 1 ==
...some content...
Total: 10
Success
== MyItem 2 ==
...some content...
Total: 2
Failed
@ajinkyakulkarni
ajinkyakulkarni / turbol.reb
Created September 12, 2017 18:10 — forked from mydoghasworms/turbol.reb
Little Rebol program that demonstrates using 'parse' to interpret some rudimentary Logo commands with a turtle and visual interface
REBOL [
title: "Rudimentary implementation of Logo Turtle"
date: 2015-02-16
author: "Martin Ceronio"
]
{ Load the turtle image; you can find the original at https://edu.kde.org/images/icons/kturtle_32.png Thanks, KTurtle! }
turtle-img: do to-string debase
{bWFrZSBpbWFnZSEgWzMyeDMyICN7CjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAKMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwCjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwNjdBMDcwNjdBMDcwNjdBMDcwNjdBMDcKMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwCjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMAowMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAxMDAwNjdBMDcwNjdBMDcKMDY3QTA3MDY3QTA3MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD
@ajinkyakulkarni
ajinkyakulkarni / 90-min-scc.scm
Created August 17, 2017 23:48 — forked from nyuichi/90-min-scc.scm
The 90 Minute Scheme to C Compiler
#!/usr/local/Gambit-C/bin/gsi
; Copyright (C) 2004 by Marc Feeley, All Rights Reserved.
; This is the "90 minute Scheme to C compiler" presented at the
; Montreal Scheme/Lisp User Group on October 20, 2004.
; Usage with Gambit-C 4.0:
;
; % ./90-min-scc.scm test.scm
Red [needs: view]
turtle: #()
win: layout [ panel [
tfield: base 500x500 white draw []
origin tfield/offset tlayer: base 500x500 255.255.255.255 draw [] ]
panel [
text "History" return history: text-list 200x350 data [] return
panel [ button "Save" [save request-file history/data]
Useful One-Line Scripts for Perl Dec 03 2013 | version 1.10
-------------------------------- ----------- ------------
Compiled by Peteris Krumins (peter@catonmat.net, @pkrumins on Twitter)
http://www.catonmat.net -- good coders code, great reuse
Latest version of this file is always at:
http://www.catonmat.net/download/perl1line.txt
@ajinkyakulkarni
ajinkyakulkarni / introrx.md
Created May 26, 2017 16:04 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@ajinkyakulkarni
ajinkyakulkarni / lis.pl
Created April 16, 2017 01:26 — forked from syohex/lis.pl
Simple Scheme interpreter in Perl(inspired by lis.py http://norvig.com/lispy.html)
#!perl
use strict;
use warnings;
package Lispl;
use Scalar::Util qw(blessed looks_like_number);
use List::Util qw(reduce);
my $global_env;

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.