Skip to content

Instantly share code, notes, and snippets.

@ambethia
Created November 29, 2011 02:47
Show Gist options
  • Select an option

  • Save ambethia/1403137 to your computer and use it in GitHub Desktop.

Select an option

Save ambethia/1403137 to your computer and use it in GitHub Desktop.
$ ->
return if $("#console").length < 1
$("#console_input").keyup (event) ->
if event.which == 13
command = $(this).val()
$.ajax
url: '/console'
type: 'POST'
dataType: 'text'
data:
cmd: command
success: (data) ->
cmd = $("<div class='cmd'></div>").text(command)
out = $("<div class='out'></div>").text(data)
$("#console .output").append(cmd).append(out)
$("#console_input").val('')
#console
.output
.input
%input#console_input{type:"text", autofocus:true}
#console
background-color: #333
color: #fff
padding: 10px
.output
height: 20em
.cmd
color: #999
#console_input
padding: 5px
margin: 0
background-color: #666
color: #fff
border: none
height: 1em
width: 740px
class ConsoleController < ApplicationController
def index
if params[:cmd]
result = begin
$repl ||= REPL.new
result = $repl.instance_eval <<-EOF.trim_gutter
| result = (#{params['cmd']})
| @_#{current_employee.id} ||= {}
| @_#{current_employee.id}.update(local_variables.inject({}) do |h, v|
| h.update({v => eval(v.to_s)})
| end)
| result
EOF
result.inspect
rescue=>e
"Error: " + e.message
end
render :text => result
end
end
class REPL
def method_missing(method, *args, &block)
eval <<-EOF.trim_gutter
| @_#{current_employee.id} ||= {}
| @_#{current_employee.id}[method.to_sym] || super(method, *args, &block)
EOF
end
def reload!
$repl = REPL.new
'ok'
end
end
end
match 'console' => 'console#index'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment