Skip to content

Commit c0938ad

Browse files
committed
initial big v5-unity/ commit
1 parent d3e5740 commit c0938ad

267 files changed

Lines changed: 98158 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

v5-unity/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
./*.png
3+
bundle*

v5-unity/README.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,25 @@ Requires these global installations:
2020
npm install webpack -g
2121
npm install webpack-dev-server -g
2222

23-
If you run:
24-
webpack-dev-server --progress --colors
23+
If you run: webpack-dev-server --progress --colors
2524

2625
then your code will automatically recompile and be refreshed here:
27-
http://localhost:8080/webpack-dev-server/
26+
http://localhost:8080/webpack-dev-server/visualize.html
27+
(but this is kinda flaky, ugh)
28+
29+
Instead, use this to continually compile:
30+
webpack --watch
31+
32+
and run the server with Bottle:
33+
python bottle_server.py
34+
35+
36+
---
37+
38+
https://github.com/petehunt/webpack-howto
39+
40+
'webpack' for building once for development
41+
'webpack -p' for building once for production (minification)
42+
'webpack --watch' for continuous incremental build in development (fast!)
43+
'webpack -d' to include source maps
2844

v5-unity/bottle_server.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Lightweight OPT server that works on both Python 2 and 3
2+
3+
# to invoke, run 'python bottle_server.py'
4+
# and visit http://localhost:8080/index.html
5+
#
6+
# external dependencies: bottle
7+
#
8+
# easy_install pip
9+
# pip install bottle
10+
11+
# From an OPT user: A couple notes: to get bottle_server.py running,
12+
# I had to replace cStringIO with io and urllib2 with urllib, for
13+
# compatibility from 2.x to 3.x Ii was running from /v3/).
14+
15+
from bottle import route, get, request, run, template, static_file
16+
import StringIO # NB: don't use cStringIO since it doesn't support unicode!!!
17+
import json
18+
import pg_logger
19+
import urllib
20+
import urllib2
21+
22+
# dummy routes for testing only
23+
@route('/web_exec_<name:re:.+>.py')
24+
def web_exec(name):
25+
return 'OK'
26+
27+
@route('/LIVE_exec_<name:re:.+>.py')
28+
def live_exec(name):
29+
return 'OK'
30+
31+
32+
@route('/<filepath:path>')
33+
def index(filepath):
34+
# special-case for testing name_lookup.py ...
35+
if 'name_lookup.py' in filepath:
36+
return json.dumps(dict(name='TEST NAME', email='TEST EMAIL'))
37+
return static_file(filepath, root='.')
38+
39+
@get('/exec')
40+
def get_exec():
41+
out_s = StringIO.StringIO()
42+
43+
def json_finalizer(input_code, output_trace):
44+
ret = dict(code=input_code, trace=output_trace)
45+
json_output = json.dumps(ret, indent=None)
46+
out_s.write(json_output)
47+
48+
options = json.loads(request.query.options_json)
49+
50+
pg_logger.exec_script_str_local(request.query.user_script,
51+
request.query.raw_input_json,
52+
options['cumulative_mode'],
53+
options['heap_primitives'],
54+
json_finalizer)
55+
56+
return out_s.getvalue()
57+
58+
59+
@get('/load_matrix_problem.py')
60+
def load_matrix_problem():
61+
prob_name = request.query.problem_name
62+
assert type(prob_name) in (str, unicode)
63+
64+
# whitelist
65+
assert prob_name in ('python_comprehension-1',)
66+
67+
fn = 'matrix-demo/' + prob_name + '.py'
68+
f = open(fn)
69+
cod = f.read()
70+
f.close()
71+
72+
import doctest
73+
import sys
74+
p = doctest.DocTestParser()
75+
examples = p.get_examples(cod)
76+
if len(examples):
77+
first_ex = examples[0]
78+
#print >> sys.stderr, 'Source:', `first_ex.source`
79+
testCod = 'result = ' + first_ex.source
80+
81+
return json.dumps(dict(code=cod, test=testCod))
82+
83+
84+
@get('/submit_matrix_problem.py')
85+
def submit_matrix_problem():
86+
user_code = request.query.submitted_code
87+
prob_name = request.query.problem_name
88+
assert type(prob_name) in (str, unicode)
89+
90+
# whitelist
91+
assert prob_name in ('python_comprehension-1',)
92+
93+
test_fn = 'matrix-demo/' + prob_name + '.test.py'
94+
test_cod = open(test_fn).read()
95+
96+
# concatenate!
97+
script = test_cod + '\n' + user_code + \
98+
'''
99+
import doctest
100+
(n_fail, n_tests) = doctest.testmod(verbose=False)
101+
if n_fail == 0:
102+
print("All %d tests passed!" % n_tests)
103+
'''
104+
105+
url = 'http://ec2-107-20-94-197.compute-1.amazonaws.com/cgi-bin/run_code.py'
106+
values = {'user_script' : script}
107+
108+
data = urllib.urlencode(values)
109+
req = urllib2.Request(url, data)
110+
response = urllib2.urlopen(req)
111+
the_page = response.read()
112+
return the_page
113+
114+
115+
if __name__ == "__main__":
116+
#run(host='localhost', port=8080, reloader=True)
117+
run(host='0.0.0.0', port=8003, reloader=True) # make it externally visible - DANGER this is very insecure since there's no sandboxing!

v5-unity/css/basic.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SimpleModal Basic Modal Dialog
3+
* http://www.ericmmartin.com/projects/simplemodal/
4+
* http://code.google.com/p/simplemodal/
5+
*
6+
* Copyright (c) 2010 Eric Martin - http://ericmmartin.com
7+
*
8+
* Licensed under the MIT license:
9+
* http://www.opensource.org/licenses/mit-license.php
10+
*
11+
* Revision: $Id: basic.css 257 2010-07-27 23:06:56Z emartin24 $
12+
*/
13+
14+
.basic-modal-content {display:none;}
15+
16+
/* Overlay */
17+
#simplemodal-overlay {background-color:#000; cursor:wait;}
18+
19+
/* Container */
20+
.simplemodal-container {
21+
height:200px;
22+
width:300px;
23+
color:#bbb;
24+
background-color:#333;
25+
border:4px solid #444;
26+
padding:5px;
27+
}
28+
29+
.simplemodal-container .simplemodal-data {padding:8px;}
30+
31+
.simplemodal-container code {
32+
background:#141414;
33+
border-left:3px solid #65B43D;
34+
color:#bbb;
35+
display:block;
36+
font-size:12px;
37+
margin-bottom:12px;
38+
padding:4px 6px 6px;
39+
}
40+
41+
.simplemodal-container a {color:#ddd;}
42+
43+
.simplemodal-container a.modalCloseImg {
44+
background:url(x.png) no-repeat;
45+
width:25px;
46+
height:29px;
47+
display:inline;
48+
z-index:3200;
49+
position:absolute;
50+
top:-15px;
51+
right:-16px;
52+
cursor:pointer;}
53+
54+
.simplemodal-container h3 {
55+
color:#84b8d9;
56+
text-align: center;
57+
}
58+
59+
.feedbacktext {
60+
color:#84b8d9;
61+
}

0 commit comments

Comments
 (0)