Skip to content

Instantly share code, notes, and snippets.

View ryanlewis's full-sized avatar

Ryan Lewis ryanlewis

  • Leeds, United Kingdom
  • 03:31 (UTC +01:00)
View GitHub Profile
@ryanlewis
ryanlewis / leaky_bucket.lua
Created March 16, 2021 00:06 — forked from florentchauveau/leaky_bucket.lua
Redis script (Lua) to implement a leaky bucket
-- Redis script to implement a leaky bucket
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260
-- (c) Florent CHAUVEAU <[email protected]>
local ts = tonumber(ARGV[1])
local cps = tonumber(ARGV[2])
local key = KEYS[1]
-- remove tokens < min (older than now() -1s)
local min = ts -1
@ryanlewis
ryanlewis / sort-teams.js
Created December 15, 2021 16:20
Sort a series of players by a rank into a series of teams
const points = {
'immortal': 7,
'diamond': 6,
'platinum': 5,
'gold': 4,
'silver': 3,
'bronze': 2,
'iron': 1,
};