Skip to content

Instantly share code, notes, and snippets.

View mpeterv's full-sized avatar

Peter Melnichenko mpeterv

View GitHub Profile
#!/usr/bin/env lua
local remote_prog = [[
local name = [=[%s]=]
local fh = assert(io.open(name))
local src = assert(fh:read("*a"))
fh:close()
local f = assert((loadstring or load)(src))
local activelines = assert(debug.getinfo(f, "L").activelines)
local lines = {}
for line in pairs(activelines) do table.insert(lines, line) end
#!/usr/bin/env python3
import fractions
import itertools
import random
sample_size = 200
random.seed(44944755)
new_possible_holes = []
possible_holes = [[(fractions.Fraction(1, 1), fractions.Fraction(1, 1))]]
#!/usr/bin/env lua
local LineScanner = require("luacov.reporter").LineScanner
local lfs = require "lfs"
local function annotate_file(path)
local lines = {}
local max_len = 0
for line in io.lines(path) do
table.insert(lines, line)
@mpeterv
mpeterv / testcase.lua
Created June 8, 2015 18:40
luajit 2.1.0 testcase
-- The following code should print "nil" several times,
-- but one of the nils gets replaced with a table somehow.
local function key(expr)
if type(expr) == 'table' then
-- Removing the zero removes spurious table
local res = {0}
for i=1, #expr do
res[i] = key(expr[i])
-- Uncommenting the following line removes spurious table
@mpeterv
mpeterv / command.sh
Created May 18, 2015 15:53
pflua #216
./env tools/pflua-compile -O0 'tcp and ((tcp[tcpflags] & tcp-syn) != 0) and ((tcp[20] == 3) or ((tcp[20] != 1) and ((tcp[20 + tcp[21]] == 3) or ((tcp[20 + tcp[21]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1]] == 3) or ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + 1]] != 1) and ((tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + 1] + tcp[20 + tcp[21] + tcp[20 + tcp[21] + 1] + tcp[20 +
@mpeterv
mpeterv / output.txt
Created February 15, 2015 14:18
Luarocks unused variables
src/luarocks/admin_remove.lua:33:24: unused variable 'login_url'
src/luarocks/admin_remove.lua:37:52: unused variable 'password'
src/luarocks/build.lua:123:20: unused variable 'err'
src/luarocks/build.lua:178:13: unused variable 'ok'
src/luarocks/build.lua:184:10: value assigned to variable 'ok' is unused
src/luarocks/build.lua:231:7: value assigned to variable 'ok' is unused
src/luarocks/build.lua:306:4: value assigned to variable 'ok' is unused
src/luarocks/build.lua:309:4: value assigned to variable 'ok' is unused
src/luarocks/build.lua:317:4: value assigned to variable 'ok' is unused
src/luarocks/build.lua:320:4: value assigned to variable 'ok' is unused
@mpeterv
mpeterv / .luacheckrc
Created November 23, 2014 11:09
A test of configurability of luacheck: config for snabbswitch
-- luacheck configuration file for snabbswitch, requires luacheck 0.7.0.
-- Run luacheck as `luacheck -q src` from the snabbswitch root folder.
-- Ignore local variables defined twice in the same scope.
redefined = false
-- Ignore unused arguments and loop variables.
unused_args = false
-- Ignore unused values coming from a call of a multi-value function together with used ones.
#!/usr/bin/env luajit
local optimize = require "pf.optimize".optimize
local pp = require "pf.utils".pp
local expanded_src = [[
{ "if",
{ "true" },
{ "if",
{ "!=",
@mpeterv
mpeterv / dead_code.lua
Created September 27, 2014 08:40
Unreachable code detector using luacheck
-- Requires luacheck scm-6
-- Reads a Lua program from stdin, prints warnings for unreachable code in top level closure.
-- Crashes on `break` or `goto` or labels.
local flow = require "luacheck.flow"
local parser = require "metalua.compiler".new()
local src = assert(io.stdin:read("*a"))
local ast = assert(parser:src_to_ast(src))
local intel = {closures = {{stmts = ast}}, gotos = {}}
flow(intel)
@mpeterv
mpeterv / pfg.lua
Created September 27, 2014 08:18
Program flow graph printer using luacheck.flow
-- Requires luacheck scm-6
-- Reads a Lua program from stdin, prints program flow graph for top level closure.
-- Format: node id: (ids of previous nodes) -> ast node tag:line:column -> (ids of next nodes)
-- Crashes on `break` or `goto` or labels.
local flow = require "luacheck.flow"
local parser = require "metalua.compiler".new()
local src = assert(io.stdin:read("*a"))
local ast = assert(parser:src_to_ast(src))
local intel = {closures = {{stmts = ast}}, gotos = {}}