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
| (defn walton [#^String s] | |
| (let [count-result (rand-int (count (walton-doc s))) | |
| expr (nth (walton-doc s) count-result) | |
| code-text (first expr) | |
| result-text (second expr) | |
| expr-length (map count (map seq expr)) | |
| code-length (first expr-length) | |
| result-length (second expr-length) | |
| truncated-result []] | |
| (if (>= code-length 457) |
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
| ;; load paths | |
| (setq dotfiles-dir (file-name-directory | |
| (or (buffer-file-name) load-file-name))) | |
| (add-to-list 'load-path dotfiles-dir) | |
| (if (fboundp 'normal-top-level-add-subdirs-to-load-path) | |
| (let* ((my-lisp-dir "~/.emacs.d/elpa-to-submit") | |
| (default-directory my-lisp-dir)) | |
| (setq load-path (cons my-lisp-dir load-path)) |
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
| (defproject walton "0.5" | |
| :description "Walton will traverse caves filled with snakes to find you example clojure code containing the function you desire." | |
| :dependencies [[org.clojure/clojure "1.1.0"] | |
| [clj-sandbox/clj-sandbox "0.2.9-SNAPSHOT"] | |
| [org.clojure/clojure-contrib "1.1.0"] | |
| [clj-html "0.1.0"]] | |
| :dev-dependencies [[swank-clojure "1.2.0-SNAPSHOT"] | |
| [autodoc "0.7.0"]] | |
| :main walton.core | |
| :namespaces [walton.core, walton.integration]) |
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
| (defn categorize-sexps [] | |
| (reduce (fn [result, code] | |
| (try | |
| (let [r (*sandbox* code)] | |
| (update-in result [:good] | |
| conj [code (pr-str r)])) | |
| (catch Exception e | |
| (update-in result [:bad] | |
| conj [code nil])))) | |
| {} |
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
| (defn categorize-sexps [] | |
| (reduce (fn [code, result] | |
| (try | |
| (let [r (*sandbox* code)] | |
| (update-in result [:good code] | |
| [code (pr-str r)])) | |
| (catch Exception e | |
| (update-in result [:bad code] | |
| [code])))) | |
| (all-expressions logfiles) |
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
| (defn categorize-code [files] | |
| (reduce (fn [result code] | |
| (try | |
| (let [r (*sandbox* code)] | |
| (update-in result [:good] conj [code r]) | |
| [code (pr-str r)]) | |
| (catch Exception e | |
| (update-in result [:bad] conj code)))) | |
| {} | |
| (find-lines text files))) |
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
| (ns walton.core | |
| (:use clojure.contrib.duck-streams | |
| clojure.contrib.str-utils | |
| clojure.contrib.seq-utils | |
| clj-html.core | |
| net.licenser.sandbox | |
| walton.integration | |
| walton.find-user) | |
| (:gen-class)) |
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
| ;; this file is a walkthrough of Moustache features, a web framework for Clojure | |
| ;; http://github.com/cgrand/moustache/tree/master | |
| ;; Moustache allows to declare routes, apply middlewares and dispatch on http methods. | |
| ;; Moustache is compatible with all frameworks built on Ring, including Compojure | |
| (ns demo | |
| (:use net.cgrand.moustache) | |
| (:use [ring.adapter.jetty :only [run-jetty]])) ;; hmmm Ring without servlets | |
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
| (defn find-lines [#^String text logfile] | |
| (filter | |
| (fn [#^String line] | |
| (< 0 (.indexOf line text))) | |
| (line-seq (reader logfile)))) | |
| (defn of-IPs [coll] | |
| (flatten | |
| (remove empty? | |
| (pmap |
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
| (defn count-ips [logfile] | |
| (remove empty? | |
| (persistent! (reduce | |
| #(assoc! %1 %2 (inc (get %1 %2 0))) | |
| (transient {}) | |
| (of-IPs | |
| (find-lines "Deny tcp src outside" logfile)))))) |