This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reverse(tbl) | |
for i=1, math.floor(#tbl / 2) do | |
local tmp = tbl[i] | |
tbl[i] = tbl[#tbl - i + 1] | |
tbl[#tbl - i + 1] = tmp | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- helper function common for all CGI | |
local t_insert = table.insert | |
local t_concat = table.concat | |
local t_remove = table.remove | |
local s_gfind = string.gfind or string.gmatch | |
local s_gsub = string.gsub | |
local s_char = string.char | |
local s_format = string.format | |
local i_write = io.write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Simple Lua XML generation library. | |
-- For example usage see test() function below. | |
-- Does not atempt to escape characters anywhere, so be carefull! | |
-- released under MIT License. | |
local insert = table.insert | |
local concat = table.concat | |
local function elem_t(name, parms, elems, parms_list) | |
local elem_t = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function num_to_str(num, bytes) | |
local num = bit.band(num, 2^(bytes*8) - 1) -- limit to selected bytes | |
local bits = {} | |
for i=bytes*8-1, 0, -1 do -- from highest bit to lowest | |
local bit = (bit.band(num, 2^i) == 0) and 0 or 1 -- check if the current bit is set | |
table.insert(bits, bit) -- append to bits table | |
end | |
return ("0x%.4X 0b%s 0d%d"):format(num, table.concat(bits), num) | |
end | |
return num_to_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Makes the module operator (%) between a string and a table behave like string.format | |
-- This works by setting the string metatable __mod function. | |
-- Example use: | |
-- str = "Hello %s, %d as hexadecimal is 0x%.2X" % {"world", 127, 127} | |
local mt = getmetatable("") | |
assert(mt, "string has no metatable") | |
mt.__mod = function(a,b) | |
if (type(a) == "string") and (type(b) == "table") then | |
return a:format(unpack(b)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <SDL2/SDL.h> | |
void main() { | |
SDL_Window *window; | |
SDL_Surface *screen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
This library converts pixels into a sequence of utf8 braile characters, | |
for displaying higher-resolution graphics on terminal emulators. | |
It features 3 functions to turn pixel data into braile characters. | |
All of them return a list of lines, and use the draw_pixel_callback | |
function internally. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return { | |
-- file extensions that are possibly a downloaded youtube video | |
file_extensions = {"mp3", "opus", "m4a", "ogg"}, | |
-- directorys to scan for youtube id's | |
local_dirs = { | |
"/media/your/music/library/folder/that/contains/youtube_dl/downloaded/videos/" | |
}, | |
-- where to store the downloaded files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
-- return stdout of command as a table containg lines | |
local function stdout_lines(cmd) | |
local proc = io.popen(cmd, "r") | |
local lines = {} | |
for line in proc:lines() do | |
lines[#lines+1] = line | |
end | |
proc:close() | |
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return function new_router(get_user) | |
-- This function returns a router table with some functions for dynamic routing. | |
local function pack(...) | |
return {...} | |
end | |
local get_user = get_user or function(request_uri, request_method, pattern_args, uri_args) | |
-- This function is called when a restricted route is accessed. | |
-- It should return something truethy when the user is authorized to access the resource. | |
-- The return value is passed to the handler of the route, so you could return a table representing the user. |
OlderNewer