Skip to content

Instantly share code, notes, and snippets.

@ilmanzo
Last active December 10, 2015 00:48
Show Gist options
  • Save ilmanzo/4353368 to your computer and use it in GitHub Desktop.
Save ilmanzo/4353368 to your computer and use it in GitHub Desktop.
SECONDS_BETWEEN_REQUEST=5
enable :sessions
def ratelimit?
now=Time.new.to_i
session['lastrequest']||=0 #inizializza se non presente
result=(now-session['lastrequest'])<SECONDS_BETWEEN_REQUEST #passati dall'ultima richiesta ?
session['lastrequest']=now # aggiorna
return result
end
get '/' do
if ratelimit?
return "<h1>sorry, rate limit exceeded!</h1>"
end
"<h1>hello!</h1>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment