Skip to content

Instantly share code, notes, and snippets.

@mrwonko
mrwonko / gla_convert.py
Created July 12, 2012 22:53
Raven Software Ghoul 2 Animation retargetting script
#! /usr/bin/python
import struct
####
#### Matrix Math
####
# N-Dimensional vector with operators == and * (dot product)
class Vector:
@mrwonko
mrwonko / errorhandling.lua
Created July 31, 2012 13:07
some lua error catching examples
local success, message = pcall(error, "this is an error")
if not success then
print("Caught error:", message)
end
local success, message = xpcall(
error,
function(err)
return debug.traceback(err, 3)
end,
@mrwonko
mrwonko / luaCountHook.lua
Created July 31, 2012 13:23
a lua hook that's called every 1000 instructions
local function hook(event)
assert(event == "count")
local info = debug.getinfo(2, "Sl") -- get source file related info (S) and current line (l)
error("Code took to long (over 1000 instructions), aborted at file \"" .. info.short_src .. "\" line " .. info.currentline)
end
debug.sethook(hook, "", 1000) -- "" = when to call this hook, if any of "every line", "every function call" or "every function return", 1000 = call every 1000 instructions
local i = 0
while true do
print(i)
@mrwonko
mrwonko / Makefile
Created December 1, 2012 21:01
uni: ueb04test
# --------------------------------------------- #
# Fachhochschule Wedel, Wintersemester 2012 #
# C-Uebung 04 - ALU #
# Hanno Sternberg #
# #
# Makefile #
# --------------------------------------------- #
# Compiler
CC = gcc
-##- -##- -##- -##- -##- -##- -##- -##- -##-
-##- -##- -##- -##--##- -##--##-
-##- -##- -##- -##-
-##- -##--##- -##- -##- -##- -##-
-##- -##- -##--##- -##--##- -##- -##-
-##- -##- -##- -##- -##- -##-
-##- -##--##--##- -##- -##-
-##- -##--##--##- -##- -##--##- -##-
-##- -##- -##- -##- -##- -##-
-##- -##- -##-
#pragma once
#include <cstddef>
#include <cctype>
#include <algorithm>
#include <istream>
#include <streambuf>
#include <utility>
#include "gsl.h"
#pragma once
#include <array>
#include <utility>
#include <cassert>
#include <cstddef>
#include <algorithm>
#include "qcommon/q_platform.h"
/*
main = interact(decode tail(lines) ctree . head . lines)
-- the parens here are misleading, this is really just:
main = interact(decode tail lines ctree . head . lines)
-- which comes down to this due to operator precedence:
main = interact((decode tail lines ctree) . head . lines)
*/
int main()
{
@mrwonko
mrwonko / polish.hs
Last active November 23, 2015 18:04
module Main( main ) where
data PolishElement = PolishPlus | PolishNumber Integer deriving (Show)
polish :: [PolishElement] -> (Integer, [PolishElement])
polish (PolishNumber x : tail) = (x, tail)
polish (PolishPlus : tail) = (x + y, tail'')
where
(x, tail') = polish tail
(y, tail'') = polish tail'
@mrwonko
mrwonko / Main.hs
Last active November 30, 2015 19:15
module Main where
main :: IO ()
main = interact $ \ input ->
let (serializedTree:encodedMessages) = lines input
tree = deserialize serializedTree
messages = map (decode tree) encodedMessages in
unlines messages
data PrefixTree = Leaf Char | Node PrefixTree PrefixTree