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
#!/usr/bin/awk -f | |
# | |
# call_graph.awk | |
# | |
# Usage: | |
# ./call_graph.awk my_program.lua | dot -Tsvg > call_graph.svg | |
# | |
# This is a script that generates a visual call graph for a Lua file. | |
# This script only shows calls made to functions defined within the | |
# input Lua file; that is, it excludes calls such as standard library |
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
#!/usr/bin/env lua | |
local pl_template = require "pl.template" | |
local tmpl_str = [[ | |
<ul> | |
# for i,val in ipairs(T) do | |
<li>$(i) = $(val:upper())</li> | |
# end | |
</ul> |
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
#!/usr/bin/env bash | |
jq 'walk( if (type == "object") and has("documentation") and (.documentation|contains("wJalrXUtnFEMI")) then del(.documentation) else . end )' sts-2011-06-15.normal.json >| output.json | |
# -or- | |
jq '(.. | select( (type == "object") and (.documentation != null) and (.documentation|contains("wJalrXUtnFEMI")) ) ) |= del(.documentation)' sts-2011-06-15.normal.json >| output.json |
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
-- table to monitor | |
ori_t = { a = "b" } | |
-- a proxy table - must be empty | |
proxy_t = {} | |
local mt | |
do | |
mt = { | |
__index = function (self, k) |
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
local sb = require "string.buffer" | |
local buff = sb.new() | |
buff:put("a", "", "c") | |
print("buff len after put: ", #buff) | |
local str = buff:get() | |
print("1st get: ", str) | |
print("buff len after 1st get: ", #buff) |
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
local pl_pretty = require("pl.pretty").write | |
-- create cosocket | |
local sock = ngx.socket.tcp() | |
sock:settimeouts(1000, 15000, 15000) | |
ngx.say("sock 1 = ", pl_pretty(sock)) | |
-- create kernel socket |
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
local func -- Forward declaration. `local func = nil` is the same. | |
local function func2() -- Suppose you can't move this function lower. | |
return func() -- reference to name, not to its value | |
end | |
-- error | |
print(func2()) | |
function func() -- defined here |
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
local socket = require("socket") | |
local host, port = "180.101.50.242", 80 | |
local sock = socket.connect(host, port) | |
sock:settimeout(1) | |
sock:send("GET / HTTP/1.1\r\n\r\n") | |
sock:close() |
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
-- memory test | |
local size = 1000000 | |
local t = {} -- create a table | |
local function report(title) | |
collectgarbage() | |
collectgarbage() | |
print(title, collectgarbage("count")) | |
end |
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
local function list_iter (t) | |
local i = 0 | |
local n = #t | |
return function () | |
i = i + 1 | |
if i <= n then return t[i] end | |
end | |
end | |
local t = { 10, 20, 30 } |
NewerOlder