Skip to content

Instantly share code, notes, and snippets.

Florent CHAUVEAU florentchauveau

Block or report user

Report or block florentchauveau

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@florentchauveau
florentchauveau / .gitlab-ci.yml
Last active Sep 16, 2019
GitLab CI yaml file for building docker images
View .gitlab-ci.yml
# This is a GitLab CI configuration to build the project as a docker image
# The file is generic enough to be dropped in a project containing a working Dockerfile
# Author: Florent CHAUVEAU <florent.chauveau@gmail.com>
# Mentioned here: https://blog.callr.tech/building-docker-images-with-gitlab-ci-best-practices/
# do not use "latest" here, if you want this to work in the future
image: docker:18
stages:
- build
View epoch_to_time.go
// ConvertTS converts a UNIX timestamp string (with sub second precision) "epoch" into a time.Time
// (c) Florent CHAUVEAU <florent.chauveau@gmail.com>
func ConvertTS(ts string) time.Time {
value := strings.SplitN(ts, ".", 2)
var sec int64
var nsec int64
if len(value) == 0 {
@florentchauveau
florentchauveau / leaky_bucket.lua
Created Aug 28, 2018
Redis script (Lua) to implement a leaky bucket
View leaky_bucket.lua
-- 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 <florent.chauveau@gmail.com>
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
View bucket_get.lua
-- Redis script to get the size of a token bucket
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260
-- (c) Florent CHAUVEAU <florent.chauveau@gmail.com>
local ts = tonumber(ARGV[1])
local key = KEYS[1]
-- remove tokens < min (older than now() -1s)
local min = ts -1
@florentchauveau
florentchauveau / bucket_add.lua
Created Aug 28, 2018
Redis script (Lua) to add an event to a token bucket
View bucket_add.lua
-- Redis script to add an event to a token bucket
-- see https://medium.com/callr-techblog/rate-limiting-for-distributed-systems-with-redis-and-lua-eeea745cb260
-- (c) Florent CHAUVEAU <florent.chauveau@gmail.com>
local ts = tonumber(ARGV[1])
-- set the token bucket to 1 second (rolling)
local min = ts -1
-- iterate overs keys
You can’t perform that action at this time.