Skip to content

Instantly share code, notes, and snippets.

View ezeql's full-sized avatar
✌️

Ezequiel Moreno ezeql

✌️
View GitHub Profile
@ezeql
ezeql / copilot1.go
Created July 10, 2022 20:53
copilot test 1
// read ten numbers from the standard input and print the smallest and largest number.
package main
import "fmt"
func main() {
var n int
var min, max int
for i := 0; i < 10; i++ {
print("Enter a number: ")
@ezeql
ezeql / keybase.md
Created August 11, 2021 16:12
keybase.md

Keybase proof

I hereby claim:

  • I am ezeql on github.
  • I am ezeql (https://keybase.io/ezeql) on keybase.
  • I have a public key ASA9hFkjMeBG8ex4daWtqQZcDDbnOb8AjDa20_8_cL017wo

To claim this, I am signing this object:

@ezeql
ezeql / keybase.md
Created October 5, 2018 06:46
keybase.md

Keybase proof

I hereby claim:

  • I am ezeql on github.
  • I am ezeql (https://keybase.io/ezeql) on keybase.
  • I have a public key whose fingerprint is 4FC9 358E EF09 CC61 189A 2383 32C1 B59A 25D1 ABAA

To claim this, I am signing this object:

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.

@ezeql
ezeql / keybase.md
Created August 12, 2016 01:49
keybase.md

Keybase proof

I hereby claim:

  • I am ezeql on github.
  • I am ezeql (https://keybase.io/ezeql) on keybase.
  • I have a public key whose fingerprint is B488 9B27 A9A0 07E3 15A3 D507 762D EE8C 57DD 62D5

To claim this, I am signing this object:

package main
import (
"fmt"
"sync"
"time"
)
func main() {
// Set up a done channel that's shared by the whole pipeline,
@ezeql
ezeql / redigo_logger_example.go
Last active November 23, 2015 16:09
redig (defaulg log like) logger
//package ...
import(
//...
"github.com/garyburd/redigo/redis"
"os"
)
//....
@ezeql
ezeql / builder.go
Created October 1, 2015 20:18
method builder example
func ProxyBuilder(repoFunction func(int) ([]interface{}, error)) func(c *gin.Context) {
return func(c *gin.Context) {
ID, _ := strconv.Atoi(c.Param("id"))
if results, err := repoFunction(ID); err == nil {
c.JSON(http.StatusOK, &results)
} else {
c.JSON(http.StatusBadRequest, err.Error())
}
}
@ezeql
ezeql / gist:2230420
Created March 28, 2012 20:52
test/LangMan.hx:10: characters 2-7 : Field hello needed by ILang is missing
var tint = TPath( { pack : [], name : "String", params : [], sub : null } );
var typeILang = { name:"ILang", pack:[], pos:pos, meta:[], params:[], isExtern:false, kind:TDClass(null, [], true), fields:[] };
typeILang.fields = [ { pos:pos, meta:[], name:"hello", doc:null, access:[APublic], kind:FVar(tint) } ];
Context.defineType(typeILang);
test/LangMan.hx:10: characters 2-7 : Field hello needed by ILang is missing