Skip to content

Instantly share code, notes, and snippets.

View mpeterv's full-sized avatar

Peter Melnichenko mpeterv

View GitHub Profile
@mpeterv
mpeterv / randtest.lua
Created September 29, 2018 10:31
binser random bad data deserialization testing
local binser = require "binser"
local unpack = table.unpack or unpack
local error_patterns = {
"Expected more bytes of input",
"Could not deserialize type byte",
"Expected more bytes of input",
"Got nil resource name",
"Expected table metatable",
"No resources found for name",
@mpeterv
mpeterv / discordia.lua
Created March 12, 2018 09:22
Discordia client serialized with vinspect
<1>{
[1] = {},
[2] = {
autoReconnect = true,
bitrate = 64000,
cacheAllMembers = false,
compress = true,
dateTime = "%F %T",
firstShard = 0,
largeThreshold = 100,
@mpeterv
mpeterv / luacheck-build.sh
Last active April 29, 2018 16:25
Cross-compile luacheck.exe
#!/usr/bin/env bash
# TODO: write a program called `rock2bin` that does this all in
# one call (`rock2bin luacheck -l 5.3 -t windows`).
mkdir build
curl https://www.lua.org/ftp/lua-5.3.4.tar.gz | tar xz
luarocks unpack luafilesystem 1.6.3-2
luarocks unpack lanes 3.10.1-1
@mpeterv
mpeterv / gist:52df984bdee4d6dcb1169d384be28d1b
Created October 29, 2016 19:47
Missing dependency reporting includes indirect deps
Missing dependency for cgilua 5.1.4-2: luafilesystem >= 1.5.0
Missing dependency for busted 2.0.rc12-1: luafilesystem >= 1.5.0
Missing dependency for busted 2.0.rc12-1: luafilesystem
Missing dependency for penlight 1.4.1-1: luafilesystem
Missing dependency for xavante 2.4.0-1: luafilesystem >= 1.6.0
Missing dependency for wsapi 1.6.1-1: luafilesystem >= 1.6.2
Missing dependency for sailor 0.5-4: luafilesystem >= 1.5.0
Missing dependency for sailor 0.5-4: luafilesystem
Missing dependency for sailor 0.5-4: luafilesystem >= 1.6.2
Missing dependency for sailor 0.5-4: luafilesystem >= 1.6.0
local lua = "lua"
local i = 0
while arg[i] do
lua = arg[i]
i = i - 1
end
local is_windows = package.config:sub(1, 1) == "\\"
@mpeterv
mpeterv / test-normpath.lua
Created July 17, 2016 11:36
Script to compare Python's os.path.normpath and Penlight's pl.path.normpath on random inputs
-- Usage: lua test-normpath.lua [count | path]
local path = require "pl.path"
local socket = require "socket"
math.randomseed(math.floor(socket.gettime() * 1000))
local chars = "./A"
local function gen_random_path()
local length = math.random(0, 5) + math.random(0, 5)
@mpeterv
mpeterv / new.txt
Last active May 14, 2016 16:10
`luarocks install sailor` output
Installing https://luarocks.org/sailor-0.5-4.src.rock
Missing dependencies for sailor 0.5-4:
datafile >= 0.1 (not installed)
luafilesystem >= 1.6.2 (not installed)
valua >= 0.2.2 (not installed)
lbase64 >= 20120807 (not installed)
cgilua >= 5.1.4 (not installed)
xavante >= 2.3 (not installed)
wsapi-xavante >= 1.6.1 (not installed)
busted >= 2.0.rc9 (not installed)
-- Problem: there is a directed graph and a subset of some A
-- associated with each node. Some nodes are marked as reset nodes.
-- An element of A traverses the graph
-- along the edges from start node S to finish node F, only
-- passing through nodes with sets containing the element.
-- At reset nodes it can change to any element of A.
-- Calculate set of possible visiting elements for each node.
-- Solution: resulting set for a node N is intersection of two sets:
-- set of elements that can visit N from S and set of starting elements that
-- Problem: there is a directed graph and a subset of some A
-- associated with each node. An element of A traverses the graph
-- along the edges from start node S to finish node F, only
-- passing through nodes with sets containing the element.
-- Calculate set of possible visiting elements for each node.
-- Solution: resulting set for a node N is intersection of two sets:
-- set of elements that can reach N from S and set of elements that
-- can reach F from N. They can be calculated for each node separately
-- using forward and backward flow analysis correspondingly, where
#!/usr/bin/env lua
local function visit(node, visited_set, exited_nodes)
visited_set[node] = true
for _, successor in ipairs(node.next) do
if not visited_set[successor] then
visit(successor, visited_set, exited_nodes)
end
end