This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ngx.timer.every(sync_interval, sync, self) | |
ngx.timer.every(sync_interval, sync, self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i ${source} \ | |
-vcodec libwebp -lossless 0 -q:v 75 -preset picture -loop 0 -an -vsync 0 -filter_complex "setpts=0.5*PTS,fps=12,scale=w=320:h=-2" -t 10 animated.webp | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- location /test { | |
-- content_by_lua_block { | |
local redis_client = redis_cluster:new(config) | |
--- simulating a dynamic code being stored at Redis --- | |
redis_client:set('authentication', "access_by_lua_block||local token = ngx.var.arg_token or ngx.var.cookie_superstition \n if token ~= 'token' then \n return ngx.exit(ngx.HTTP_FORBIDDEN) \n else \n ngx.header['Set-Cookie'] = {'superstition=token'} \n end") | |
redis_client:sadd('coding_units', 'authentication') | |
--- simulating a dynamic code being stored at Redis --- | |
--- fetch --- | |
local resp, err = redis_client:smembers("coding_units") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- fetch --- | |
local resp, err = redis_client:smembers("coding_units") | |
local raw_coding_units = {} | |
for _, coding_unit_key in ipairs(resp) do | |
local resp, err = redis_client:get(coding_unit_key) -- it'd be nice to keep the id for logging reasons | |
table.insert(raw_coding_units, resp) | |
end | |
--- fetch --- | |
--- parse --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Error during evaluation - syntactically invalid | |
code, err = loadstring(" a = 1 \n a a \n pring(a) \n") | |
print(code) | |
-- nil | |
print(err) | |
-- [string " a = 1 ..."]:2: '=' expected near 'a' | |
-- Error during runtime - syntactically valid | |
stringcode = " a = taketime.menu " | |
code, err = loadstring(stringcode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- running luajit in repl will be useful for exploration | |
-- docker run -it --rm akorn/luajit:2.1-alpine | |
-- just inspired at | |
-- https://stackoverflow.com/questions/1426954/split-string-in-lua | |
function mysplit (inputstr, sep) | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run this in one tab | |
docker run --rm -it --name some-redis redis | |
# run this in another tab | |
docker exec -it some-redis redis-cli | |
127.0.0.1:6379> set authentication "access_by_lua_block||if token ~= 'token' then \n return ngx.exit(ngx.HTTP_FORBIDDEN) \n else \n ngx.header['Set-Cookie'] = {'superstition=token'} \n end" | |
OK | |
127.0.0.1:6379> get authentication | |
"access_by_lua_block||if token ~= 'token' then \n return ngx.exit(ngx.HTTP_FORBIDDEN) \n else \n ngx.header['Set-Cookie'] = {'superstition=token'} \n end" | |
127.0.0.1:6379> sadd coding_units authentication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make sure you have docker | |
git clone https://github.com/leandromoreira/nott.git | |
cd nott | |
git checkout 1.0.2 | |
# in a tab | |
make run | |
# wait until the platform is up and running | |
# and in another tab run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- counting how many requests a given ip did | |
local redis_client = redis_cluster:new(config) | |
local resp, err = redis_client:incr(ngx.var.remote_addr) | |
ngx.header['X-Request-Counter'] = resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make sure you have docker | |
git clone https://github.com/leandromoreira/nott.git | |
cd nott | |
git checkout 0.0.3 | |
# in a tab | |
make run | |
# wait until the platform is up and running | |
# and in another tab run |