Skip to content

Instantly share code, notes, and snippets.

View blasti's full-sized avatar
:octocat:
Focusing

blastbeat blasti

:octocat:
Focusing
View GitHub Profile
@blasti
blasti / tail.lua
Last active March 13, 2022 00:31
Simple tail implementation in 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
@blasti
blasti / ringbuf.lua
Last active March 12, 2022 17:22
Simple ring buffer
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