-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
69 lines (60 loc) · 1.68 KB
/
app.rb
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
require 'sinatra'
require 'sinatra/json'
require 'rake'
require 'github_api'
require 'open-uri'
set :port, 3010
set :json_content_type, :js
get '/version' do
version = `egison --version`.chop
ret = { version: version }
json ret
end
post '/eval/?' do
filename = "programs/" + Time.now.strftime("%Y-%m-%d-%H-%M-%S-%L");
File.write(filename, params[:program])
output = `timeout 5 nice egison --no-io -t #{filename} 2>&1`.chop
if $?.exitstatus == 124
output = "Timeout. We are limiting the resource for the online interprter."
end
ret = { output: output }
json ret
end
post '/eval2/?' do
filename = "tutorial/" + Time.now.strftime("%Y-%m-%d-%H-%M-%S-%L");
File.write(filename, params[:program])
output = `timeout 1 nice egison --no-io -t #{filename} 2>&1`.chop
if $?.exitstatus == 124
output = "Timeout. We are limiting the resource for the online interprter."
end
ret = { output: output }
json ret
end
post '/subscribe/?' do
filename = "mailing-list/" + Time.now.strftime("%Y-%m-%d-%H-%M-%S-%L");
File.write(filename, params[:email] + "\n")
ret = { output: "ok" }
json ret
end
get '/github' do
github = Github.new
response = github.repos.get("egisatoshi", "egison/contents/" + params[:path])
content = Base64.decode64(response.content)
ret = { content: content }
json ret
end
get '/source' do
content = open("http://www.egison.org/source/" + params[:path]).read
ret = { content: content }
json ret
end
get '/tutorial' do
output = `egison-tutorial -s #{params[:sn]} -c #{params[:ssn]} 2>&1`.chop
ret = { output: output }
json ret
end
get '/tutorial/table' do
output = `egison-tutorial -l 2>&1`.chop
ret = { output: output }
json ret
end