Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Execute code online and return output this script is part of my quest to create a facebook bot for executing code and respond with code output in another comment, this is similar to a reddit bot. the first step is to submit code and get the output or error from a service online, i found that Eval.in is simple and free and supports json formatted…
#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
require 'json'
require 'open-uri'
require 'uri'
require 'net/http'
CODE_LIMIT = 10
$url = "https://eval.in/"
$languages = {
'c' => 'c/gcc-4.7.2', 'c++' => 'c++/gcc-4.7.2',
'fortran' => 'fortran/f95-4.4.3', 'haskell' => 'haskell/hugs98-sep-2006',
'io' => 'io/io-20110912', 'javascript' => 'javascript/node-0.10.26',
'lua' => 'lua/lua-5.2.1', 'ocaml' => 'ocaml/ocaml-4.00.1',
'php' => 'php/php-5.5.1', 'perl' => 'perl/perl-5.16.1',
'python' => 'python/cpython-3.2.3', 'ruby' => 'ruby/mri-2.1.0',
'slash' => 'slash/slash-head', 'assembly' => 'assembly/nasm-2.07'
}
def evalin code, language
return nil unless $languages.keys.include? language
return nil if code.length < CODE_LIMIT
params = {
code: code, lang: $languages[language],
execute: 'on', input: ''
}
postData = Net::HTTP.post_form(URI.parse($url), params)
location = postData['location']
if location
evalin_data = JSON.parse open("#{location.gsub 'http://', 'https://'}.json").read
return "#{evalin_data['output']}\n#{evalin_data['status']}\n#{location}"
end
return nil
end
puts evalin('10.times{ puts "done."}', 'ruby')
@pynixwang

This comment has been minimized.

Copy link

commented Mar 31, 2014

you sure CODE_LIMIT is minimal length?

@emad-elsaid

This comment has been minimized.

Copy link
Owner Author

commented Apr 15, 2014

@pynixwang am i missing something ? i think in line 23 i did that right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.