forked from rubenfonseca/map_crowd_reduce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.haml
74 lines (58 loc) · 2.4 KB
/
index.haml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%script{src: "examples.js"}
%h1= title
%p Welcome to #{title}
:if computations
%h2 Current computations
%ul
:each k in computations
%li
%a{href: '/compute/' + __key__}= __key__
:javascript
function load_example_1() {
var s1 = "function(input) {\n\treturn [ [0,1000], [1001,2000], [2001,3000], [3001,4000], [4001,5000], [5001,6000], [60001, 70000], [70001, 80000], [80001, 90000], [90001, 100000] ];\n}";
var m1 = "function(interval) {\n\tvar ret = [];\n\tvar isprime = function (num){\n\t\tvar prime = true;\n\t\tif (num == 1 || num == 2 || num == 3) { prime=true; } else { for (var i=2;i<=Math.ceil(num/2);i++) { if (num % i == 0) { prime=false; break; } } } return prime; }; for(var n=interval[0]; n<interval[1]; n++) { if(isprime(n)) ret.push(n); else ret.push(0); } return ret;\n}";
var r1 = "function(array) {\n\tvar res = 0; for(var i=0; i<array.length; i++) { for(var j=0; j<array[i].length; j++) { if(array[i][j] != 0) { res += 1; } } } return res;\n}";
s_editor.value = s1;
map_editor.value = m1;
reduce_editor.value = r1;
};
function load_example_2(){
load_example(example2[0], example2[1], example2[2]);
};
%h3 Prewritten examples
%button{onclick: "load_example_1()"}
Find the number of primes
%button{onclick: "load_example_2()"}
Find md5 collision
%form{action: '/new_job', method:'POST', enctype:'multipart/form-data'}
%p
%label{for: 's'}s function
%br
%textarea{name: 's', rows:20, cols:100, id:'s'}
%p
%label{for: 'map'}map function
%br
%textarea{name: 'map', rows:20, cols:100, id:'map'}
%p
%label{for: 'reduce'}reduce function
%br
%textarea{name: 'reduce', rows:20, cols:100, id:'reduce'}
%p
%label{for: 'file'}input file
%input{type:'file', name:'file'}
%p
%button{type:'submit'}Finish him
%link{id: "bespin_base", href:"/"}
%script{src:"/BespinEmbedded.js"}
:javascript
window.onBespinLoad = function() {
bespin.useBespin('s', { syntax:'js' }).then(function(env) {
window.s_editor = env.editor;
}, function(error) {});
bespin.useBespin('map', { syntax:'js' }).then(function(env) {
window.map_editor = env.editor;
}, function(error) {});
bespin.useBespin('reduce', { syntax:'js' }).then(function(env) {
window.reduce_editor = env.editor;
}, function(error) {});
}