Skip to content

Instantly share code, notes, and snippets.

View sposterkil's full-sized avatar

Sam Osterkil sposterkil

  • Stateless
  • Boulder, CO
View GitHub Profile
@sposterkil
sposterkil / Recursion?
Created August 31, 2014 18:21
I think this even works
def recurse(input_file):
"""Takes a file and recursively evaluates lines to get an answer."""
children, value = split_line(input_file.read())
# All operations we implement are binary, we should either have zero
# children or two. Anything else is an error.
if children == 0:
return float(value)
elif children == 2:
return operate(value,
recurse(input_file.read()),
@sposterkil
sposterkil / pr01.py
Created September 3, 2014 02:23
new evaluation()
def evaluation(tree):
print tree.label
if len(tree.children) == 0:
return tree
else:
return apply_op(tree.label, evaluation(tree.children[0]), evaluation(tree.children[1]))
@sposterkil
sposterkil / pr01.py
Created September 3, 2014 02:58
pr01 "binary"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from collections import deque
from pr01 import prefixParser
USAGE_MESSAGE = "pr01 [file]"
EXTENDED_MESSAGE = '''
Takes a file as an argument or on stdin, parses it as an expression tree, and
@sposterkil
sposterkil / lexer.py
Created September 16, 2014 05:18
Instruction generator
def get_instructions(pattern_list):
"""Takes a list of regex patterns and compiles them to a list of VM
instructions via the lexc tool, and then returns that list."""
# The lexing compiler should be in the same folder as us
lexexec = os.path.abspath(os.path.join(sys.path[0], "lexc"))
# (Yes, this giant chain of os.path things checks that)
if not os.path.isfile(os.path.abspath(os.path.join(sys.path[0], "lexc"))):
print lexexec
raise IOError("Lexc executable not in same folder as program.")
command = [lexexec] + ["--pattern=%s" % str(pattern)
Found the Vertex shader, loading it.
Found the Control shader, loading it.
ERROR: 0:4: Invalid use of layout 'vertices'
ERROR: 0:15: Use of undeclared identifier 'gl_InvocationID'
ERROR: 0:15: Use of undeclared identifier 'gl_InvocationID'
ERROR: 0:17: Use of undeclared identifier 'gl_InvocationID'
ERROR: 0:18: Use of undeclared identifier 'gl_TessLevelInner'
ERROR: 0:19: Use of undeclared identifier 'gl_TessLevelInner'
ERROR: 0:20: Use of undeclared identifier 'gl_TessLevelOuter'
ERROR: 0:21: Use of undeclared identifier 'gl_TessLevelOuter'
@sposterkil
sposterkil / arrowc.py
Created December 12, 2014 21:18
Binary compilation
with NamedTemporaryFile(suffix=".s", mode='rw+b') as asm_temp:
asm_temp.write(get_asm(source_file))
asm_temp.write(get_lib())
log("> Compiling with gcc...")
subprocess.call(["gcc",
"-m32",
"-o", output_file.name,
asm_temp.name
])
@sposterkil
sposterkil / arrowc.py
Created December 12, 2014 21:49
This works fine...
with open("a.s", "w") as asm_temp:
asm_temp.write(get_asm(source_file))
asm_temp.write(get_lib())
with open("a.s", "r") as asm_temp:
log("> Compiling with gcc...")
subprocess.call(["gcc",
"-m32",
"-o", output_file.name,
asm_temp.name
])
@sposterkil
sposterkil / fib.c
Created February 6, 2015 05:44
K&R Style Indentation
int fib(int n)
{
if (n <= 2)
{
return 1;
}
else
{
return fib(n - 1) + fib(n - 2);
@sposterkil
sposterkil / pwduid.c
Created February 6, 2015 22:08
C snippet to print working directory and effective/real user
char path[PATH_MAX];
// We use this getpwuid(geteuid()) construct instead of cuserid()
// for portability (Works on OS X and Linux)
printf("I ran in the directory %s, as effective user %s, real user %s.\n",
getcwd(path, PATH_MAX),
getpwuid(geteuid())->pw_name,
getpwuid(getuid())->pw_name);
@sposterkil
sposterkil / olb.h
Created March 21, 2015 19:15
SHM Access
int shm_id = shmget(SHM_KEY, 1024, 0777);
my_shared = (struct common *)shmat(shm_id, 0, 0);
if ((my_shared->bridge_dir == GOING_EAST ||
my_shared->bridge_dir == NONE) &&
(my_shared->xed_count < 4 &&
(my_shared->xed_count + my_shared->xing_count) < 5)) {