Skip to content

Instantly share code, notes, and snippets.

@Raynes
Created March 21, 2010 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynes/339388 to your computer and use it in GitHub Desktop.
Save Raynes/339388 to your computer and use it in GitHub Desktop.
net.licenser.sandbox> (def sc (create-sandbox-compiler))
#'net.licenser.sandbox/sc
net.licenser.sandbox> (def cap 100)
(defn trim [s]
(.replaceAll (apply str (take cap s)) "\n" " "))
(defn execute-text [txt]
(let [writer (java.io.StringWriter.)]
(try
(trim (str writer ((sc txt) {'*out* writer})))
(catch SecurityException _ "DENIED!")
(catch Exception e (.getMessage (.getCause e))))))
#'net.licenser.sandbox/execute-text
net.licenser.sandbox> (execute-text "(loop [] (recur))")
; Evaluation aborted.
net.licenser.sandbox> (execute-text "(loop [] (recur))")
; Evaluation aborted.
net.licenser.sandbox> (execute-text "(loop [] (recur))")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment