Skip to content

Instantly share code, notes, and snippets.

View mpeterv's full-sized avatar

Peter Melnichenko mpeterv

View GitHub Profile
@mpeterv
mpeterv / template.py
Created December 16, 2013 20:02
Template for a robotgame bot
class Game:
def __init__(self, data, player_id):
self.player_id = player_id
self.update(data)
def update(self, data):
self.turn = data['turn']
self.robots = data['robots']
self.onNewTurn()
@mpeterv
mpeterv / game.py
Created December 19, 2013 19:20
Rewritten game.py
import copy
import imp
import random
import sys
import traceback
from collections import defaultdict
from rgkit import rg
from rgkit.settings import settings, AttrDict
@mpeterv
mpeterv / random_spec.lua
Created January 10, 2014 18:52
randomized test suit for serpent
local serpent = require "serpent"
local function random_var(is_key, deep)
local key = math.random(1000)
if key <= 100 then
if is_key then
return 0
else
return nil
@mpeterv
mpeterv / metalua-parser-0.7.3-3.rockspec
Created March 25, 2014 06:24
metalua-parser-0.7.3-3.rockspec
--*-lua-*--
package = "metalua-parser"
version = "0.7.3-3"
source = {
url = "http://git.eclipse.org/c/koneki/org.eclipse.koneki.metalua.git/snapshot/org.eclipse.koneki.metalua-v0.7.3.tar.gz"
}
description = {
summary = "Metalua's parser: converting Lua source strings and files into AST",
detailed = [[
This is a subset of the full Metalua compiler. It defines and generates an AST
@mpeterv
mpeterv / report
Created April 6, 2014 13:50
cd shine/src && luacheck *.lua */*.lua --no-unused-args --ignore setfenv getfenv newproxy
Checking main.lua Failure
main.lua:54:10: variable env was previously defined as an argument in the same scope
main.lua:111:10: variable args was previously defined as an argument in the same scope
Checking shnc.lua OK
Checking core/init.lua Failure
core/init.lua:23:7: unused variable xpcall
core/init.lua:51:4: setting non-standard global variable copy
@mpeterv
mpeterv / lchecks.lua
Created April 15, 2014 17:13
Pure Lua implementation of checks
--[[
Argument type checking API.
This library declares a `checks()` function and a `checkers` table, which
allow to check the parameters passed to a Lua function in a fast and
unobtrusive way.
`checks (type_1, ..., type_n)`, when called directly inside function
`f`, checks that `f`'s 1st argument conforms to `type_1`, that its 2nd
argument conforms to `type_2`, etc. until `type_n`. Type specifiers
@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 = {}}
@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)
#!/usr/bin/env luajit
local optimize = require "pf.optimize".optimize
local pp = require "pf.utils".pp
local expanded_src = [[
{ "if",
{ "true" },
{ "if",
{ "!=",
@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.