Skip to content

Instantly share code, notes, and snippets.

View Egor-Skriptunoff's full-sized avatar

Egor-Skriptunoff

View GitHub Profile
@Egor-Skriptunoff
Egor-Skriptunoff / utf8_filenames.lua
Last active May 31, 2025 15:56
UTF-8 filenames on Windows in pure Lua
------------------------------------------------------------------------------------------------------------------------------
-- Module: utf8_filenames
------------------------------------------------------------------------------------------------------------------------------
-- Filename: utf8_filenames.lua
-- Version: 2019-07-13
-- License: MIT (see at the end of this file)
-- This module modifies standard Lua functions so that they work with UTF-8 filenames on Windows:
-- io.open
-- io.popen
@Egor-Skriptunoff
Egor-Skriptunoff / GSM7_to_ASCII.lua
Created December 1, 2018 13:30
Convertor from GSM7 to ASCII
-- Convertor from GSM7 to ASCII
-- Usage:
-- print(GSM7_to_ASCII("F4F29C9E769F1B"))
function GSM7_to_ASCII(hex_string)
local GSM_Base = {
[0] = '@', '£', '$', '¥', 'è', 'é', 'ù', 'ì', 'ò', 'Ç', '\n',
#!/usr/bin/env lua
---------------------------------------------------------------------------------------------------------------------------------------
-- Display list of globals used by your Lua script
---------------------------------------------------------------------------------------------------------------------------------------
-- Version: 2019-03-28
-- License: MIT (see at the end of this file)
--
-- Reads your Lua script from STDIN
-- Writes list of globals to STDOUT (if the script is syntactically correct)
-- Writes parsing error to STDERR (if the script is not syntactically correct)
@Egor-Skriptunoff
Egor-Skriptunoff / sha256_for_LuaJIT.lua
Created September 8, 2018 17:01
SHA256 benchmark for LuaJIT
--~ How to run the benchmark:
--~ $ luajit sha256_for_LuaJIT.lua;luajit -O-narrow sha256_for_LuaJIT.lua
local table_concat, byte, char, string_rep, sub, floor, ceil, min, max =
table.concat, string.byte, string.char, string.rep, string.sub, math.floor, math.ceil, math.min, math.max
local b = require"bit"
local AND = b.band
local OR = b.bor
@Egor-Skriptunoff
Egor-Skriptunoff / make_globals_backslashed.lua
Created July 16, 2018 19:46
Prefix all global identifiers in your Lua script with backslash
#!/usr/bin/env lua
---------------------------------------------------------------------------------------------------------------------------------------
-- Converter from "source text" to "globals-backslashed source text"
---------------------------------------------------------------------------------------------------------------------------------------
-- Reads Lua program from STDIN
-- Writes converted program to STDOUT (if the program is syntactically correct)
-- Writes parsing error to STDERR (if the program is not syntactically correct)
-- Usage (both Windows and Linux):
@Egor-Skriptunoff
Egor-Skriptunoff / demo.lua
Created July 23, 2017 13:11
bugfix for lua.org demo page
local write,D,L,select,tostring,ipairs,concat,execute,sub,gsub=io.write,{},8192,select,tostring,ipairs,table.concat,os.execute,string.sub,string.gsub
local T,E,I
T=io.read"*a"
T=string.match(T,"=(.-)$") or ""
T=gsub(T,"+"," ")
T=gsub(T,"%%(%x%x)",function (x) return string.char(tonumber(x,16)) end)
T=gsub(T,"^%s*=%s*","return ")
write(sub(T,1,L))
write[[</TEXTAREA>
--------------------------------------------------------------------------------------------------------
-- This code snippet implements pseudo-random number generator
-- Output: 32-bit integers 0..4294967295
-- Internal state (seed): 53 bits, can be read or write at any time
-- Good statistical properties of PRN sequence:
-- uniformity,
-- long period of 255 * 2^45 (approximately 2^53),
-- unpredictability
local append, concat, floor, abs = table.insert, table.concat, math.floor, math.abs
local num = {'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'}
local tens = {'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'}
local bases = {{floor(1e18), ' quintillion'}, {floor(1e15), ' quadrillion'}, {floor(1e12), ' trillion'},
{floor(1e9), ' billion'}, {1000000, ' million'}, {1000, ' thousand'}, {100, ' hundred'}}
local insert_word_AND = false -- 101 = "one hundred and one" / "one hundred one"
local function IntegerNumberInWords(n)
-- long_unsigned_integers.lua
---------------------------------------------------------------------------------------------------------
-- LONG ARITHMETIC (non-negative integers of arbitrary length)
---------------------------------------------------------------------------------------------------------
-- Compatible with Lua 5.1, Lua 5.2, Lua 5.3, LuaJIT
-- THIS MODULE WAS NOT OPTIMIZED FOR VERY LONG NUMBERS (multiplication has quadratic time complexity)
-- Usage:
-- local L = require("long_unsigned_integers")
------------------------------------------------------------------------------------
-- Module: null.lua
------------------------------------------------------------------------------------
-- How to insert nils in an array?
-- Traditional approach is to appoint some Lua value as nil-replacement.
-- A function null(...) that swaps nils with itself may be a perfect candidate:
-- 1) It represents nil values inside an array