This file contains 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
(defn extract-fns | |
([ignores data] | |
(if (seq? data) | |
(lazy-seq | |
(let [data (macroexpand data)] | |
(let [f (first data) | |
data (rest data)] | |
(cond | |
(= f 'fn*) (let [data (first data) | |
locals (first data) |
This file contains 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
user=> (def sc (create-sandbox 'namespace (new-sandbox-tester (whitelist (function-tester '+))))) | |
;=> #'user/sc | |
user=> (sc "(* 1 1)") | |
;=> java.lang.SecurityException: Code did not pass sandbox guidelines (NO_SOURCE_FILE:0) | |
user=> (sc "(- 1 1)") | |
;=> java.lang.SecurityException: Code did not pass sandbox guidelines (NO_SOURCE_FILE:0) | |
user=> (sc "(+ 1 1)") | |
;=> 2 | |
user=> (sc "(+ 1 1 1 (+ 1 2))") | |
;=> 6 |
This file contains 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
(defn find-units | |
[game pred] | |
(let [units (vals (:units game)) | |
_ (utils/trace "find-units on" (count units)) | |
units (filter (fn [u] | |
(println "bla!!!!!!!!!!!!!!") | |
(utils/trace "find-units" "testing unit:" (:id @u)) | |
(if (and utils/*trace* (pred @u)) | |
(utils/trace "find-units" "testing unit:" (:id @u) "positive!") | |
(utils/trace "find-units" "testing unit:" (:id @u) "negativ!")) |
This file contains 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
(use 'net.licenser.sandbox) | |
(enable-security-manager) | |
(def sc (create-sandbox-compiler)) | |
(def my-really-secure-add (sc "(+ a b)" a b)) | |
(my-really-secure-add {} 23 19) ;=> 42 |
This file contains 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
(use 'net.licenser.sandbox) | |
(enable-security-manager) | |
(def sc (create-sandbox-compiler 'sandbox (new-sandbox-tester (whitelist (function-tester 'println))))) | |
(def sandboxed-print (sc "(println t)" 't)) | |
(def my-out (java.io.StringWriter.)) | |
(sandboxed-print {'*out* my-out} 42) | |
my-out ;=> #<StringWriter 42> |
This file contains 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
(let [d 2 | |
hostiles (foes-in-range 100) | |
target (first hostiles)] | |
(if target | |
(do | |
(intercept target 2) | |
(fire-all target)))) |
This file contains 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
(ns irc-parser | |
(:use clojure.contrib.duck-streams | |
clojure.contrib.str-utils | |
clojure.contrib.seq-utils)) | |
(def dates (file-seq (java.io.File. "./clojure"))) | |
(defn parse-irc-log | |
[logfile] | |
(line-seq (reader logfile))) |
This file contains 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
(ns irc-parser.core | |
(:use clojure.contrib.duck-streams | |
clojure.contrib.str-utils | |
clojure.contrib.seq-utils)) | |
(def dates (file-seq (java.io.File. "./clojure"))) | |
(defn parse-irc-log | |
[logfile] | |
(line-seq (reader logfile))) |
This file contains 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
(defn lazy-open-file-seq [rdr] | |
(let [seq-fn (fn seq-fn [rdr list] | |
(lazy-seq | |
(try | |
(if list | |
(cons (first list) (seq-fn rdr (rest list))) | |
(do | |
(.close rdr) | |
nil) ) | |
(catch Exception e (.close rdr)) |
This file contains 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
(defn extract-expressions [string] | |
(second | |
(reduce (fn [[exp exps state cnt] c] | |
(cond | |
(= state :escape) | |
[(.append exp c) exps :string cnt] | |
(= state :string) (cond | |
(= c \") | |
[(.append exp c) exps :code cnt] | |
(= c \\) |