ruboty-ideone-codeiq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1778ee6c2498d7bc5165a49bccfb81cdf5dddb2b
4
+ data.tar.gz: 3759d6c841b092b0a59167c07665d201da6a6dbd
5
+ SHA512:
6
+ metadata.gz: 7425cc070231424f008d2bc845e08d963f182a53054d41549db30c209fee71db0a0b65076aa5ead46b848c897c8084e0dfb82c6b5b43d4da93d1795a5f3e6cb0
7
+ data.tar.gz: 6667b280b7f9fb28f98bdcc09da138f3e63c194bfee169078c101979c64276abbc0763bb3c9d4f63039a6aeec0bb931b92a58e478ca2723f3f83e0bc0be3cd85
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-ideone-codeiq.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 cielavenir
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ruboty::Ideone::CodeIQ
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-ideone-codeiq'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-ideone-codeiq
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-ideone-codeiq/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,160 @@
1
+ #coding:utf-8
2
+ require 'open-uri'
3
+ require 'rubygems'
4
+ require 'cgi'
5
+
6
+ #クラス変数を使いたいので、Actionを切り出すことは不可能
7
+ module Ruboty
8
+ module Handlers
9
+ class Ideone_codeiq < Base
10
+ #基本的にruboty-ideoneの古いバージョンから拾ってくれば大丈夫。念のためソース開いて照合を。
11
+ LANGUAGES=[
12
+ {:key=>"7", :value=>"Ada (gnat-4.9.2)"},
13
+ {:key=>"45", :value=>"Assembler (gcc-4.9.2)"},
14
+ {:key=>"13", :value=>"Assembler (nasm-2.11.05)"},
15
+ {:key=>"104", :value=>"AWK (gawk) (gawk-4.1.1)"},
16
+ {:key=>"105", :value=>"AWK (mawk) (mawk-3.3)"},
17
+ {:key=>"28", :value=>"Bash (bash 4.3.30)"},
18
+ {:key=>"110", :value=>"bc (bc-1.06.95)"},
19
+ {:key=>"12", :value=>"Brainf**k (bff-1.0.5)"},
20
+ {:key=>"11", :value=>"C (gcc-4.9.2)"},
21
+ {:key=>"27", :value=>"C# (mono-3.10)"},
22
+ {:key=>"41", :value=>"C++ 4.3.2 (gcc-4.3.2)"},
23
+ {:key=>"1", :value=>"C++ 4.9.2 (gcc-4.9.2)"},
24
+ {:key=>"44", :value=>"C++14 (gcc-4.9.2)"},
25
+ {:key=>"34", :value=>"C99 strict (gcc-4.9.2)"},
26
+ {:key=>"14", :value=>"CLIPS (clips 6.24)"},
27
+ {:key=>"111", :value=>"Clojure (clojure 1.7)"},
28
+ {:key=>"118", :value=>"COBOL (open-cobol-1.1)"},
29
+ {:key=>"106", :value=>"COBOL 85 (tinycobol-0.65.9)"},
30
+ {:key=>"32", :value=>"Common Lisp (clisp) (clisp 2.49)"},
31
+ {:key=>"20", :value=>"D (gdc 4.9.2)"},
32
+ {:key=>"102", :value=>"D (dmd) (dmd-2.042)"},
33
+ {:key=>"36", :value=>"Erlang (erl-5.7.3)"},
34
+ {:key=>"124", :value=>"F# (fsharp-3.10)"},
35
+ {:key=>"123", :value=>"Factor (factor-0.93)"},
36
+ {:key=>"125", :value=>"Falcon (falcon-0.9.6.6)"},
37
+ {:key=>"107", :value=>"Forth (gforth-0.7.2)"},
38
+ {:key=>"5", :value=>"Fortran (gfortran-4.9.2)"},
39
+ {:key=>"114", :value=>"Go (1.4)"},
40
+ {:key=>"121", :value=>"Groovy (groovy-2.4)"},
41
+ {:key=>"21", :value=>"Haskell (ghc-7.6)"},
42
+ {:key=>"16", :value=>"Icon (iconc 9.4.3)"},
43
+ {:key=>"9", :value=>"Intercal (c-intercal 28.0-r1)"},
44
+ {:key=>"10", :value=>"Java (sun-jdk-8u25)"},
45
+ {:key=>"55", :value=>"Java7 (sun-jdk-1.7.0_10)"},
46
+ {:key=>"35", :value=>"JavaScript (rhino) (rhino-1.7R4)"},
47
+ {:key=>"112", :value=>"JavaScript (spidermonkey) (spidermonkey 24.2)"},
48
+ {:key=>"26", :value=>"Lua (luac 5.2)"},
49
+ {:key=>"30", :value=>"Nemerle (ncc 0.9.3)"},
50
+ {:key=>"25", :value=>"Nice (nicec 0.9.6)"},
51
+ {:key=>"122", :value=>"Nimrod (nimrod-0.8.8)"},
52
+ {:key=>"56", :value=>"Node.js (0.10.35)"},
53
+ {:key=>"43", :value=>"Objective-C (gcc-4.5.1)"},
54
+ {:key=>"8", :value=>"Ocaml (ocamlopt 4.01.0)"},
55
+ {:key=>"127", :value=>"Octave (3.6.2)"},
56
+ {:key=>"119", :value=>"Oz (mozart-1.4.0)"},
57
+ {:key=>"57", :value=>"PARI/GP (2.5.1)"},
58
+ {:key=>"22", :value=>"Pascal (fpc) (fpc 2.6.4)"},
59
+ {:key=>"2", :value=>"Pascal (gpc) (gpc 20070904)"},
60
+ {:key=>"3", :value=>"Perl (perl 5.20.1)"},
61
+ {:key=>"54", :value=>"Perl 6 (rakudo-2014.07)"},
62
+ {:key=>"29", :value=>"PHP (php 5.6.4)"},
63
+ {:key=>"19", :value=>"Pike (pike 7.8)"},
64
+ {:key=>"108", :value=>"Prolog (gnu) (gprolog-1.3.1)"},
65
+ {:key=>"15", :value=>"Prolog (swi) (swipl 5.6.64)"},
66
+ {:key=>"4", :value=>"Python (python 2.7.9)"},
67
+ {:key=>"99", :value=>"Python (Pypy) (Pypy)"},
68
+ {:key=>"116", :value=>"Python 3 (python-3.4)"},
69
+ {:key=>"117", :value=>"R (R-2.11.1)"},
70
+ {:key=>"17", :value=>"Ruby (ruby-1.9.3)"},
71
+ {:key=>"39", :value=>"Scala (scala-2.11.4)"},
72
+ {:key=>"128", :value=>"Scheme (chicken) (4.9)"},
73
+ {:key=>"33", :value=>"Scheme (guile) (guile 2.0.11)"},
74
+ {:key=>"23", :value=>"Smalltalk (gst 3.2.4)"},
75
+ {:key=>"40", :value=>"SQL (sqlite3-3.8.7)"},
76
+ {:key=>"38", :value=>"Tcl (tclsh 8.6)"},
77
+ {:key=>"62", :value=>"Text (text 6.10)"},
78
+ {:key=>"115", :value=>"Unlambda (unlambda-2.0.0)"},
79
+ {:key=>"101", :value=>"VB.NET (mono-3.10)"},
80
+ {:key=>"6", :value=>"Whitespace (wspace 0.3)"},
81
+ ]
82
+
83
+ def initialize(*__reserved__)
84
+ super
85
+ @input=nil
86
+ @languages=LANGUAGES
87
+ end
88
+ def read_uri(uri)
89
+ return nil if !uri||uri.empty?
90
+ Kernel.open(uri){|f|
91
+ return f.read
92
+ }
93
+ end
94
+
95
+ on /ideone-codeiq languages/, name: 'languages', description: 'show languages'
96
+ on /ideone-codeiq setinput ?(?<input_uri>\S*)/, name: 'setinput', description: 'set input'
97
+ on /ideone-codeiq submit (?<language>\S+) (?<source_uri>\S+) ?(?<input_uri>\S*)/, name: 'submit', description: 'send code via uri'
98
+ def languages(message)
99
+ message.reply @languages.map{|e|"#{'%4d:'%e[:key]} #{e[:value]}\n"}.join
100
+ end
101
+ def setinput(message)
102
+ #input_uri: 入力ファイル(空文字列ならクリア)
103
+ if !message[:input_uri]||message[:input_uri].empty?
104
+ @input=nil
105
+ message.reply 'Input cleared.'
106
+ else
107
+ @input=read_uri(message[:input_uri])
108
+ message.reply 'Input set.'
109
+ end
110
+ end
111
+ def submit(message)
112
+ #language: ID(数値)または言語名(文字列)。言語名の場合、記号類を除いて最大先頭一致のものを使用する。
113
+ #source_uri: ソースファイル
114
+ #input_uri: 入力ファイル(空文字列ならsetinputの内容を使用)
115
+ input=message[:input_uri]&&!message[:input_uri].empty? ? read_uri(message[:input_uri]) : @input
116
+ #guess lang
117
+ lang=message[:language]
118
+ if lang.to_i>0
119
+ lang=lang.to_i
120
+ else
121
+ lang=lang.downcase.gsub(/[\s\(\)\.]/,'')
122
+ lang=@languages.max_by{|e|
123
+ _e=e[:value].downcase.gsub(/[\s\(\)\.]/,'')
124
+ lang.size.downto(1).find{|i|_e.start_with?(lang[0,i])}||-1
125
+ }[:key].to_i
126
+ end
127
+ uri=URI.parse('https://codeiq.jp/tools/connect.php')
128
+ https=Net::HTTP.new(uri.host,uri.port)
129
+ https.use_ssl=true
130
+ https.start{
131
+ resp=https.post(uri.path,'lang='+lang.to_s+'&source='+CGI.escape(read_uri(message[:source_uri]))+'&input='+CGI.escape(input),{
132
+ 'Content-Type'=>'application/x-www-form-urlencoded; charset=UTF-8',
133
+ })
134
+ result=JSON.parse(resp.body)
135
+ if result['status'].to_i<0
136
+ message.reply '[Ruboty::Ideone::CodeIQ] waiting for compilation'
137
+ elsif result['status'].to_i==1
138
+ message.reply '[Ruboty::Ideone::CodeIQ] compiling'
139
+ elsif result['status'].to_i==3
140
+ message.reply '[Ruboty::Ideone::CodeIQ] running'
141
+ elsif result['error']!='OK'
142
+ message.reply '[Ruboty::Ideone::CodeIQ] something wrong happened in execution'
143
+ elsif result['result']=='15'
144
+ message.reply result['output']
145
+ else
146
+ message.reply('[Ruboty::Ideone::CodeIQ] '+{
147
+ 0=>'not running',
148
+ 11=>'compilation error',
149
+ 12=>'runtime error',
150
+ 13=>'time limit exceeded',
151
+ 17=>'memory limit exceeded',
152
+ 19=>'illegal system call',
153
+ 20=>'internal error',
154
+ }[result['result'].to_i])
155
+ end
156
+ }
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,10 @@
1
+ require "ruboty/ideone/codeiq/version"
2
+ require "ruboty/handlers/ideone-codeiq"
3
+
4
+ module Ruboty
5
+ module Ideone
6
+ module CodeIQ
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Ruboty
2
+ module Ideone
3
+ module CodeIQ
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/ideone/codeiq/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-ideone-codeiq"
8
+ spec.version = Ruboty::Ideone::CodeIQ::VERSION
9
+ spec.authors = ["cielavenir"]
10
+ spec.email = ["cielartisan@gmail.com"]
11
+ spec.summary = "Ruboty Ideone CodeIQ"
12
+ spec.description = "Ruboty Ideone CodeIQ"
13
+ spec.homepage = "https://github.com/"+spec.authors.first+"/"+spec.name
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "ruboty"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-ideone-codeiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cielavenir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Ruboty Ideone CodeIQ
56
+ email:
57
+ - cielartisan@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ruboty/handlers/ideone-codeiq.rb
68
+ - lib/ruboty/ideone/codeiq.rb
69
+ - lib/ruboty/ideone/codeiq/version.rb
70
+ - ruboty-ideone-codeiq.gemspec
71
+ homepage: https://github.com/cielavenir/ruboty-ideone-codeiq
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.14
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Ruboty Ideone CodeIQ
95
+ test_files: []