Commit 5aca52e1 authored by Joel Martin's avatar Joel Martin

Cleanup. Move note files into docs/.

parent adfe6ac1
<!DOCTYPE HTML>
<html>
<head>
<title>Worker example: One-core computation</title>
</head>
<body>
<p>The highest prime number discovered so far is: <output id="result"></output></p>
<input type='button' value="Start" onclick="worker.postMessage('start');">
<input type='button' value="Stop" onclick="worker.postMessage('stop');">
<input type='button' value="Reset" onclick="worker.postMessage('reset');">
<br>
Log:<br>
<textarea id='debug' style="font-size: 9;" cols=80 rows=25></textarea>
<script src="include/mootools.js"></script>
<script>
function debug(str) {
cell = $('debug');
cell.innerHTML += str + "\n";
cell.scrollTop = cell.scrollHeight;
}
debug('Starting');
var worker = new Worker('prime.js');
worker.onmessage = function (event) {
var cmd = event.data.substr(0,4);
var data = event.data.substr(4);
switch (cmd) {
case 'log:':
debug(data);
break;
case 'num:':
$('result').innerHTML = data;
break;
}
};
</script>
</body>
</html>
var n = 1;
var cur = 1;
var timer = null;
function search() {
if (timer) clearTimeout(timer);
var sqrtn = Math.sqrt(n);
for (iters = 0; iters < 10000; iters += 1) {
cur += 1;
if ((cur <= sqrtn) && (n % cur != 0)) continue;
if (cur > sqrtn) {
postMessage("num:" + n);
}
n += 1;
cur = 1;
}
timer = setTimeout(search, 10);
}
onmessage = function (e) {
switch (e.data) {
case 'start':
postMessage("log:start");
if (timer) clearTimeout(timer);
timer = setTimeout(search, 100);
break;
case 'stop':
postMessage("log:stop");
if (timer) clearTimeout(timer);
started = false;
break;
case 'reset':
postMessage("log:reset");
n = 1;
postMessage('num:');
break;
}
}
#!/usr/bin/python
'''
A super simple HTTP/HTTPS webserver for python. Automatically detect
import sys
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
You can make a cert/key with openssl using:
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
as taken from http://docs.python.org/dev/library/ssl.html#certificates
'''
import traceback, sys
import socket
import ssl
#import http.server as server # python 3.X
import SimpleHTTPServer as server # python 2.X
def do_request(connstream, from_addr):
x = object()
server.SimpleHTTPRequestHandler(connstream, from_addr, x)
def serve():
bindsocket = socket.socket()
#bindsocket.bind(('localhost', PORT))
bindsocket.bind(('', PORT))
bindsocket.listen(5)
print("serving on port", PORT)
while True:
try:
newsocket, from_addr = bindsocket.accept()
peek = newsocket.recv(1024, socket.MSG_PEEK)
if peek.startswith("\x16"):
connstream = ssl.wrap_socket(
newsocket,
server_side=True,
certfile='self.pem',
ssl_version=ssl.PROTOCOL_TLSv1)
else:
connstream = newsocket
do_request(connstream, from_addr)
except Exception:
traceback.print_exc()
try:
port = int(sys.argv[1])
PORT = int(sys.argv[1])
except:
print "%s port" % sys.argv[0]
sys.exit(2)
server = HTTPServer(('',port), CGIHTTPRequestHandler)
server.serve_forever()
serve()
#!/usr/bin/python
'''
A super simple HTTP/HTTPS webserver for python. Automatically detect
You can make a cert/key with openssl using:
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem
as taken from http://docs.python.org/dev/library/ssl.html#certificates
'''
import traceback, sys
import socket
import ssl
#import http.server as server # python 3.X
import SimpleHTTPServer as server # python 2.X
def do_request(connstream, from_addr):
x = object()
server.SimpleHTTPRequestHandler(connstream, from_addr, x)
def serve():
bindsocket = socket.socket()
#bindsocket.bind(('localhost', PORT))
bindsocket.bind(('', PORT))
bindsocket.listen(5)
print("serving on port", PORT)
while True:
try:
newsocket, from_addr = bindsocket.accept()
peek = newsocket.recv(1024, socket.MSG_PEEK)
if peek.startswith("\x16"):
connstream = ssl.wrap_socket(
newsocket,
server_side=True,
certfile='self.pem',
ssl_version=ssl.PROTOCOL_TLSv1)
else:
connstream = newsocket
do_request(connstream, from_addr)
except Exception:
traceback.print_exc()
try:
PORT = int(sys.argv[1])
except:
print "%s port" % sys.argv[0]
sys.exit(2)
serve()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment