Created
April 29, 2010 11:51
-
-
Save jayfresh/383485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
system.use("com.joyent.Sammy"); | |
POST('/eval', function() { | |
/* get q like this because request.body doesn't correctly collect parameters with '+' characters - they get converted to ' ' */ | |
var q = decodeURIComponent(this.request.content.split('=')[1].replace(/\+/g," ")); | |
var func; | |
eval('func = function() { '+q+'};'); | |
var res = func(); | |
if(!res) { | |
res = "no return value"; | |
} | |
return res; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<link rel="stylesheet" href="css/reset.css" /> | |
<link rel="stylesheet" href="css/styles.css" /> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<h1>Messin' witcha live</h1> | |
<div class="grid2col left"> | |
<h2>Code</h2> | |
<form action="/eval" method="post"> | |
<textarea id="q" name="q" rows="20" cols="40"></textarea> | |
<input type="submit" value="run" /> | |
</form> | |
</div> | |
<div class="grid2col left"> | |
<h2>Results</h2> | |
<textarea id="results" rows="20" cols="40"></textarea> | |
</div> | |
</div> | |
<script type="text/javascript" src="js/jquery-1.4.1.js"></script> | |
<script type="text/javascript" src="js/eval.html.js"></script> | |
</body> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var updateResults = function(text) { | |
text = text.replace(/<br\/>|<br \/>|<br>/g,"\n"); | |
$('#results').text(text); | |
}; | |
$(document).ready(function() { | |
$('#q').closest('form').submit(function() { | |
var data = { | |
q: $('#q').val() | |
}; | |
$.ajax({ | |
url: "/eval", | |
type: "post", | |
data: data, | |
success: function(data,status,xhr) { | |
updateResults(data); | |
}, | |
error: function(xhr,status,exc) { | |
var text = "Error:\n\n" + (xhr.responseText || "no response; status: "+status); | |
updateResults(text); | |
} | |
}); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment