I hereby claim:
- I am hariharan-uno on github.
- I am hariharan_uno (https://keybase.io/hariharan_uno) on keybase.
- I have a public key ASBHuJkcaA5BOowpEdql7Hls2EYRINCk53pq-ERLP3q9tAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
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.
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.
package main | |
// @lizrice, mostly copied from @doctor_julz: https://gist.github.com/julz/c0017fa7a40de0543001 | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"syscall" | |
) |
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"syscall" | |
) | |
func main() { |
HOSTIP=`netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10` | |
/home/vagrant/recond -marksman=http://$HOSTIP:3000 -nats=tcp://$HOSTIP:4222 & | |
echo "recond started..." |
package main | |
import ( | |
"fmt" | |
"strconv" | |
"github.com/extemporalgenome/slug" | |
) | |
type person struct { |
package main | |
import ( | |
"github.com/gorilla/websocket" | |
"io" | |
"log" | |
"net/http" | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { |
//Copied from https://groups.google.com/forum/#!msg/golang-nuts/dEfqPOSccIc/hoq8jdPTBIcJ | |
package main | |
import( | |
"crypto/rand" | |
"crypto/tls" | |
"io/ioutil" | |
"log" | |
"net" |
#include <sys/wait.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
int pipefd[2]; | |
pid_t cpid; |