ideone 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE +21 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/examples/hello-world.rb +9 -0
- data/examples/with-stdin.rb +14 -0
- data/lib/ideone.rb +108 -0
- data/test/basic.rb +34 -0
- data/test/with-input.rb +16 -0
- metadata +71 -0
data/LICENCE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT Licence
|
2
|
+
|
3
|
+
Copyright (c) 2008-2009 Pistos
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT Licence
|
2
|
+
|
3
|
+
Copyright (c) 2008-2009 Pistos
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# ideone.com gem
|
2
|
+
|
3
|
+
A Ruby interface to the ideone.com API.
|
4
|
+
|
5
|
+
http://github.com/Pistos/ideone-gem
|
6
|
+
|
7
|
+
Base code taken from http://github.com/staii/tgoa . See References, below.
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
See examples/ dir of repository or gem.
|
12
|
+
|
13
|
+
## Contact
|
14
|
+
|
15
|
+
Pistos in #mathetes on irc.freenode.net
|
16
|
+
|
17
|
+
## Licence
|
18
|
+
|
19
|
+
MIT. See LICENCE file.
|
20
|
+
|
21
|
+
## References
|
22
|
+
|
23
|
+
* http://ideone.com/api
|
24
|
+
* http://ideone.com/api/1/service.wsdl
|
25
|
+
* http://ideone.com/files/ideone-api.pdf
|
26
|
+
* http://github.com/staii/tgoa/blob/7490b8564977f9a0b0dde4840e1c00f6a47cdcba/safe_code.rb
|
27
|
+
* http://ideone.com/faq (for language id numbers)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ideone'
|
2
|
+
|
3
|
+
code = %{
|
4
|
+
input = $stdin.read
|
5
|
+
puts "input was: \#{input}"
|
6
|
+
}
|
7
|
+
|
8
|
+
$stdout.print "Enter a little text: "
|
9
|
+
$stdout.flush
|
10
|
+
|
11
|
+
text = $stdin.gets.strip
|
12
|
+
|
13
|
+
paste_id = Ideone.submit( :ruby, code )
|
14
|
+
p Ideone.run( paste_id, text )
|
data/lib/ideone.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
|
6
|
+
module Ideone
|
7
|
+
|
8
|
+
class IdeoneError < StandardError; end
|
9
|
+
|
10
|
+
LANGUAGES = {
|
11
|
+
:bash => 28,
|
12
|
+
:c => 11,
|
13
|
+
'c#' => 27,
|
14
|
+
:csharp => 27,
|
15
|
+
'c++' => 1,
|
16
|
+
:cpp => 1,
|
17
|
+
:cplusplus => 1,
|
18
|
+
:clojure => 111,
|
19
|
+
:commonlisp => 32,
|
20
|
+
:clisp => 32,
|
21
|
+
:erlang => 36,
|
22
|
+
:go => 114,
|
23
|
+
:haskell => 21,
|
24
|
+
:java => 10,
|
25
|
+
:javascript => 112,
|
26
|
+
:js => 112,
|
27
|
+
:perl => 3,
|
28
|
+
:php => 29,
|
29
|
+
:python => 4,
|
30
|
+
:ruby => 17,
|
31
|
+
}
|
32
|
+
TIMEOUT = 4 # iterations
|
33
|
+
|
34
|
+
def self.submit( lang_, code )
|
35
|
+
lang = LANGUAGES[ lang_ ] || lang_
|
36
|
+
|
37
|
+
Net::HTTP.post_form(
|
38
|
+
URI.parse("http://ideone.com/ideone/Index/submit/"),
|
39
|
+
{
|
40
|
+
'lang' => lang,
|
41
|
+
'run' => 0,
|
42
|
+
'file' => code
|
43
|
+
}
|
44
|
+
).header['location'][1..-1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.run( id, input, timeout = TIMEOUT )
|
48
|
+
res = JSON.load(
|
49
|
+
Net::HTTP.post_form(
|
50
|
+
URI.parse( "http://ideone.com/submit/parent/#{id}" ),
|
51
|
+
{ 'input' => input }
|
52
|
+
).body
|
53
|
+
)
|
54
|
+
if res['status'] != 'ok'
|
55
|
+
raise IdeoneError, "Posting of input failed."
|
56
|
+
end
|
57
|
+
|
58
|
+
loc = res['link']
|
59
|
+
i = 0
|
60
|
+
|
61
|
+
begin
|
62
|
+
sleep 3 if i > 0
|
63
|
+
res = JSON.load(
|
64
|
+
Net::HTTP.post_form(
|
65
|
+
URI.parse("http://ideone.com/ideone/Index/view/id/#{loc}/ajax/1"),
|
66
|
+
{}
|
67
|
+
).body
|
68
|
+
)
|
69
|
+
i += 1
|
70
|
+
end while res['status'] != '0' && i < timeout
|
71
|
+
|
72
|
+
case res[ 'result' ]
|
73
|
+
when '0', '15'
|
74
|
+
# success
|
75
|
+
when '11'
|
76
|
+
raise IdeoneError, "Compilation error"
|
77
|
+
when '12'
|
78
|
+
raise IdeoneError, "Runtime error"
|
79
|
+
when '13'
|
80
|
+
raise IdeoneError, "Execution timed out"
|
81
|
+
when '17'
|
82
|
+
raise IdeoneError, "Memory limit exceeded"
|
83
|
+
when '19'
|
84
|
+
raise IdeoneError, "Illegal system call"
|
85
|
+
when '20'
|
86
|
+
raise IdeoneError, "Internal error occurred at ideone.com"
|
87
|
+
else
|
88
|
+
raise IdeoneError, "Unknown result: " + res[ 'result' ]
|
89
|
+
end
|
90
|
+
|
91
|
+
if i == timeout
|
92
|
+
raise IdeoneError, "Timed out while waiting for code result."
|
93
|
+
end
|
94
|
+
|
95
|
+
err = res['inouterr'].match(/<label>stderr:<\/label>.*?<pre.*?>(.*?)<\/pre>/m)
|
96
|
+
if err
|
97
|
+
err[1]
|
98
|
+
else
|
99
|
+
out = res['inouterr'].match(/<label>output:<\/label>.*?<pre.*?>(.*?)<\/pre>/m)
|
100
|
+
if out
|
101
|
+
out[1]
|
102
|
+
else
|
103
|
+
raise IdeoneError, "Error parsing output."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/test/basic.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'ideone'
|
2
|
+
require 'bacon'
|
3
|
+
|
4
|
+
describe 'an ideone gem user' do
|
5
|
+
it 'can submit Ruby code and receive stdout' do
|
6
|
+
paste_id = Ideone.submit( :ruby, %{puts "text on stdout"} )
|
7
|
+
results = Ideone.run( paste_id, nil )
|
8
|
+
results.should.equal %{text on stdout\n}
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can submit Perl code and receive stdout' do
|
12
|
+
paste_id = Ideone.submit( :perl, %{print "text on stdout\\n"} )
|
13
|
+
results = Ideone.run( paste_id, nil )
|
14
|
+
results.should.equal %{text on stdout\n}
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can submit Python code and receive stdout' do
|
18
|
+
paste_id = Ideone.submit( :python, %{print "text on stdout"} )
|
19
|
+
results = Ideone.run( paste_id, nil )
|
20
|
+
results.should.equal %{text on stdout\n}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'can submit PHP code and receive stdout' do
|
24
|
+
paste_id = Ideone.submit( :php, %{<?php echo "text on stdout\\n"; ?>} )
|
25
|
+
results = Ideone.run( paste_id, nil )
|
26
|
+
results.should.equal %{text on stdout\n}
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can submit Bash code and receive stdout' do
|
30
|
+
paste_id = Ideone.submit( :bash, %{echo "text on stdout"} )
|
31
|
+
results = Ideone.run( paste_id, nil )
|
32
|
+
results.should.equal %{text on stdout\n}
|
33
|
+
end
|
34
|
+
end
|
data/test/with-input.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ideone'
|
2
|
+
require 'bacon'
|
3
|
+
|
4
|
+
describe 'an ideone gem user' do
|
5
|
+
it 'can submit Ruby code with stdin and receive stdout' do
|
6
|
+
paste_id = Ideone.submit(
|
7
|
+
:ruby,
|
8
|
+
%{
|
9
|
+
input = $stdin.read
|
10
|
+
puts "input was: \#{input}"
|
11
|
+
}
|
12
|
+
)
|
13
|
+
results = Ideone.run( paste_id, 'some input' )
|
14
|
+
results.should.equal %{input was: some input\n}
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ideone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pistos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-08-02 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bacon
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: ideonegem dot pistos aet purepistos dot net
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/ideone.rb
|
35
|
+
- test/basic.rb
|
36
|
+
- test/with-input.rb
|
37
|
+
- examples/hello-world.rb
|
38
|
+
- examples/with-stdin.rb
|
39
|
+
- LICENCE
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/Pistos/ideone-gem
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A Ruby interface to the ideone.com API
|
70
|
+
test_files: []
|
71
|
+
|