Skip to content

Instantly share code, notes, and snippets.

View outsinre's full-sized avatar

Zachary Hu outsinre

View GitHub Profile
@outsinre
outsinre / tcp_rst.lua
Created September 21, 2023 07:21
The send buffer has data
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()
@outsinre
outsinre / table_shrinking.lua
Created September 21, 2023 07:19
table_shrinking.lua
-- memory test
local size = 1000000
local t = {} -- create a table
local function report(title)
collectgarbage()
collectgarbage()
print(title, collectgarbage("count"))
end
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 }
@outsinre
outsinre / deep_compare.lua
Last active February 15, 2023 13:26
Lua gist
-- deeply compare two objects like 'pl.tablex.deepcompare()'
local function deep_equals(t1, t2, ignore_mt)
-- different type
if t1Type ~= t2Type then return false end
-- compare simple values directly
if t1Type ~= 'table' then return t1 == t2 end
-- both table type; try metatable method
if not ignore_mt then
local mt1 = getmetatable(t1)
[cplayer] Reading config file /home/zachary/.config/mpv/mpv.conf
[cplayer] Setting option 'no-border' = '' (flags = 4)
[cplayer] Setting option 'ontop' = 'no' (flags = 4)
[cplayer] Setting option 'save-position-on-quit' = 'yes' (flags = 4)
[cplayer] Setting option 'autofit-larger' = '100%' (flags = 4)
[cplayer] Setting option 'profile' = 'pseudo-gui' (flags = 4)
[cplayer] Setting option 'terminal' = 'no' (flags = 4)
libva info: VA-API version 0.38.1
libva info: va_getDriverName() returns 0
a-a 12 34 12
a-a-a 56 56
a-ba-ao-ke-luo 78 90 90

Each line is a key values pattern. The key is a string delimited by hyphens. while values delimited by spaces.

I want to remove duplicate vlaues on each line:

I want to merge lines that share common prefix. Example:

a 1
a 2
bc-de 3
bc-de 4
bc-de 5

After merging:

I want to merge lines that share common prefix. Example:

a 1
a 2
bc-de 3 4
bc-de 5

After merging:

I want to merge lines that share common prefix. Example:

a 1
a 2
a-b 3
a-b 4
a-b 5

After merging:

I want to merge lines that share common prefix. Example:
```
a 1
a 2
a-b 3
a-b 4
a-b 5
```
After merging: