reval 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/reval +108 -0
  2. metadata +80 -0
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'trollop'
6
+
7
+ def escape! h
8
+ h.keys.each do |k|
9
+ h[k] = h[k].to_s
10
+ end
11
+ h
12
+ end
13
+
14
+ FILETYPES = {
15
+ ".c" => "c",
16
+ ".h" => "c",
17
+ ".cpp"=> "cpp",
18
+ ".d" => "d",
19
+ ".hs" => "haskell",
20
+ ".lua" => "lua",
21
+ ".ml" => "ocaml",
22
+ ".mli" => "ocaml",
23
+ ".php" => "php",
24
+ ".pl" => "perl",
25
+ ".py" => "python",
26
+ ".rb" => "ruby",
27
+ ".scm" => "scheme",
28
+ ".ss" => "scheme",
29
+ ".tcl" => "tcl"
30
+ }
31
+
32
+ LANGS = {
33
+ 'c'=>'C',
34
+ 'cpp'=>'C++',
35
+ 'd'=>'D',
36
+ 'haskell'=>'Haskell',
37
+ 'lua'=>'Lua',
38
+ 'ocaml'=>'OCaml',
39
+ 'php'=>'PHP',
40
+ 'perl'=>'Perl',
41
+ 'python'=>'Python',
42
+ 'ruby'=>'Ruby',
43
+ 'scheme'=>'Scheme',
44
+ 'tcl'=>'Tcl'
45
+ }
46
+
47
+ def get(lang, code, priv=false)
48
+ url = 'http://codepad.org/'
49
+ data = {
50
+ 'code' => code,
51
+ 'lang' => LANGS[lang],
52
+ 'submit' => 'Submit',
53
+ 'run' => "True",
54
+ 'private' => priv.to_s.capitalize
55
+ }
56
+
57
+ res = Net::HTTP.post_form(URI.parse(url), escape!(data))
58
+ res.fetch("location")
59
+ end
60
+
61
+ opts = Trollop::options do
62
+ opt :lang, "Programming language (will try to guess from filename)", :type => :string
63
+ opt :list, "List available languages"
64
+ opt :eval, "Pass in code to be eval'd on the command line", :type => :string
65
+ opt :file, "The file containing code to be evaluated", :type => :string
66
+ opt :private, "Make this code private.", :default => false, :type => :bool
67
+ opt :verbose, "Log actions", :default => false
68
+ end
69
+
70
+ if opts[:list]
71
+ puts "AVAILABLE LANGUAGES:\n#{LANGS.keys.inspect}"
72
+ exit
73
+ end
74
+
75
+
76
+ file = opts[:file] || ARGV[0]
77
+
78
+ if file
79
+ begin
80
+ code = File.open(file).read
81
+ rescue Errno::ENOENT
82
+ puts "FILE DOES NOT EXIST."
83
+ exit
84
+ end
85
+ else
86
+ code = opts[:eval]
87
+ end
88
+
89
+ if code == nil || code == ""
90
+ puts "PLEASE GIVE ME SOMETHING TO EVALUATE."
91
+ exit
92
+ end
93
+
94
+
95
+ lang = opts[:lang] || (file && FILETYPES[File.extname(file)])
96
+
97
+ unless LANGS.keys.include?(lang)
98
+ puts "PLEASE SPECIFY A VALID LANGUAGE. CHOICES ARE: #{LANGS.keys.inspect}"
99
+ exit
100
+ end
101
+
102
+ if opts[:verbose]
103
+ puts "LANG: #{lang}"
104
+ puts "PRIVATE? #{opts[:private] ? "YES" : "NO"}"
105
+ print "RESULT: "
106
+ end
107
+
108
+ puts get(lang, code, opts[:private])
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reval
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Aditya Bhargava
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-02 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: trollop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Codepad is a remote code evaluation service. reval uses codepad to run code from various languages. Think of it as Ruby's eval from the command line.
36
+ email: batman@scribd.com
37
+ executables:
38
+ - reval
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - bin/reval
45
+ has_rdoc: true
46
+ homepage: https://github.com/egonSchiele/reval
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Use Codepad from the command line.
79
+ test_files: []
80
+