Skip to content

Instantly share code, notes, and snippets.

View uriid1's full-sized avatar
🏹
Focusing

uriid1

🏹
Focusing
View GitHub Profile
@uriid1
uriid1 / fstring.lua
Last active March 18, 2024 22:19
Lua Format String (fstring)
--- Lua format string
-- @param text text
-- @param args table
local function fstring(text, args)
local res, _ = string.gsub(text, '%${([%w_]+)}', args)
return res
end
-- Example
--[[
@uriid1
uriid1 / unicode_blocks.lua
Last active April 10, 2024 01:04
Format unicode blocks to lua table
--
-- Format table:
-- unicode.blocks = {
-- ['Domino-Tiles'] = "\u{1F030}-\u{1F09F}",
-- ['Supplemental-Arrows-C'] = "\u{1F800}-\\u{1F8FF}",
-- ...
-- }
--
-- Blocks.txt = https://www.unicode.org/Public/UNIDATA/Blocks.txt
@uriid1
uriid1 / switch.lua
Created November 5, 2023 15:15
Minimal switch-case statements in lua.
---
-- @function switch
-- @param value value
-- @param t table
-- @return nil or value
local function switch(value, t)
assert(type(t) == 'table', 'Argument[2] must be a table')
if t[value] then
assert(type(t[value]) == 'function', 'Case action must be a function')
@uriid1
uriid1 / hex.lua
Last active March 11, 2024 22:00
Hex encode/decode
--[[
####--------------------------------####
#--# Author: by uriid1 #--#
#--# License: GNU GPLv3 #--#
####--------------------------------####
--]]
local M = {}
function M.decToHex(decimal)