Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Focusing

blastbeat blasti

:octocat:
Focusing
View GitHub Profile
@blasti
blasti / ringbuf.lua
Last active Mar 12, 2022
Simple ring buffer
View ringbuf.lua
ringbuf={}
ringbuf.eof=0
ringbuf.size=0
ringbuf.__index=ringbuf
function ringbuf:new(size)
size=tonumber(size)
if not size then
return nil, "arg must be an number"
elseif size<1 then
@blasti
blasti / tail.lua
Last active Mar 13, 2022
Simple tail implementation in lua
View tail.lua
#!/usr/bin/env lua
-- Example usage: ./tail.lua logfile -10
local fd=io.open(arg[1],"r")
local lines_to_read=math.abs(tonumber(arg[2]) or 0)
local eof=fd:seek("end",-1)
local pos=eof
local lines_read=0
local buf={}
local buf_len=0
while pos do