Skip to content

Instantly share code, notes, and snippets.

View b0mbie's full-sized avatar
🌌

[aka]bomb b0mbie

🌌
  • 05:45 (UTC +02:00)
View GitHub Profile
@b0mbie
b0mbie / tty.lua
Created July 4, 2023 19:49
Terminal control library in pure Lua.
--
-- tty.lua
--
-- Written by [aka]bomb, 2023
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
@b0mbie
b0mbie / parenmult.lua
Last active May 11, 2023 10:44
Lua one-liner that adds a __call metamethod to numbers which multiplies given parameters with self and returns them.
local s,u=select,table.unpack or unpack debug.setmetatable(3,{__call=function(x,...)local n,t=s('#',...),{}for i=1,n do t[i]=x*s(i,...) end return u(t,1,n)end})
@b0mbie
b0mbie / dutchify.lua
Created September 7, 2022 19:48
dutchify.js implementation in Lua.
local oohsub = { o = 'e', O = 'E' }
local function oo(m)
return m:sub(1, -2) .. m:sub(-1):gsub("[Oo]", oohsub)
end
local function isupper(s) return s:upper() == s end
local function dj(m)
local wordc = m:sub(2)
@b0mbie
b0mbie / tserial-function.lua
Last active July 7, 2022 22:31
Table binary serialization library for Lua.
--
-- tserial.function.lua
--
-- Written by [aka]bomb, 2022
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
@b0mbie
b0mbie / printf.lua
Created June 28, 2022 17:23
A printfln and printpfln library for Lua.
--
-- printf.lua
--
-- Written by [aka]bomb, 2022
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
@b0mbie
b0mbie / hook.lua
Last active June 27, 2022 22:55
Very simple (non-debug) hook library for Lua.
--
-- hook.lua
--
-- Written by [aka]bomb, 2022
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
@b0mbie
b0mbie / imean.lua
Created May 14, 2022 14:25
Iterative mean function for Lua
return function imean(m, v, i)
return ((m * i) + v) / (i + 1)
end
@b0mbie
b0mbie / circdiff.lua
Created May 8, 2022 15:25
Circular difference function for Lua
local abs = math.abs
return function (a, b, m)
local diff = b - a
local hm = m * 0.5
if diff > hm then
return diff - m
elseif diff < -hm then
return m + diff
end
return diff
@b0mbie
b0mbie / linf.lua
Last active June 27, 2022 22:56
Small linear function library. linf stands for linear function
--
-- linf.lua
--
-- Written by [aka]bomb, 2022
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
@b0mbie
b0mbie / print_debug.lua
Last active April 17, 2022 19:04
Library for creating printfln and debugfln functions
local printDebug = {
debug = false
}
--- Similar to printfln of C, but uses Lua's print (which usually appends a newline).
function printDebug.printfln(fmt, ...) print(string.format(fmt, ...)) end
--- Create a printfln and debugfln function for a named context.
--- printfln message prefix: "[<ctx>] "
--- debugfln message prefix: "[<ctx>-debug] "