Skip to content

Instantly share code, notes, and snippets.

(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))
(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)))
(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)
(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]))))
{}
(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])
;; 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))
(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)
(defhtml application [text body]
[:html
[:head
[:title text]]
[:body
[:h3 text]
body]])
(defhtml code-list [body]
[:ul body])
(def walton-web
(app
["examples" text]
{:get [(fn [req] (walton-doc* text))]}
[#".*"] {:get ["all routes!"]}))
@devn
devn / web.clj
Created April 1, 2010 14:47 — forked from swannodette/web.clj
(ns defn-test
(:use clj-html.core
[net.cgrand.moustache :only [app]]
[ring.adapter.jetty :only [run-jetty]]
[ring.util.response :only [response]]))
(defhtml application [text body]
[:html
[:head
[:title text]]