Skip to content

Instantly share code, notes, and snippets.

@zew13
Created October 22, 2022 02:06
Show Gist options
  • Save zew13/cba77cb4c98597eed982d988ecca8cdb to your computer and use it in GitHub Desktop.
Save zew13/cba77cb4c98597eed982d988ecca8cdb to your computer and use it in GitHub Desktop.
> ~/R > R R_ID
@iuser/time > Second
@iuser/camel
CACHE = new Map
MINUTE = 61
< new Proxy(
{}
get:(_, name)=>
name = camel name.toLowerCase()
=>
cache = CACHE.get(name)
if cache
id = cache[0]
max = cache[1]
if id == max
[step,time] = cache[2..]
diff = Second() - time
step = (
step * Math.round(MINUTE/(diff+1))
) or 1
max = await R.hincrby(R_ID, name, step)
id = max - step
CACHE.set name, [id,max,step,time]
else
step = 1
max = await R.hincrby(R_ID, name, step)
id = max - step
cache = [id,max,step,Second()]
CACHE.set(name, cache)
return ++cache[0]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment