Skip to content

Instantly share code, notes, and snippets.

View lancepantz's full-sized avatar

lance bradley lancepantz

  • bird
  • los angeles, ca
View GitHub Profile
(defn revert [id attrs opts]
(sql/with-connection rev-log
(let [id (Integer/parseInt (last (re-split #"-" id)))
result (sql/with-query-results result
["UPDATE revisions
SET reverted_by = nextval('revision_id_seq'::regclass)
WHERE id=?
AND reverted_by IS NULL
returning reverted_by AS revision;"
id]
(defn verify-table [table]
(sql/with-connection *db*
(sql/with-query-results results [(str "SELECT node_id, data FROM " table " WHERE data IS NOT NULL")]
(doseq [r results]
(try (json/parse-string (:data r))
(catch Exception e
(println e)
(println "table:" table)
(println "node_id:" (:node_id r))
(println "data:" (:data r))
(PUT "/:focus/:action"
{{type "focus" action "action"} :route-params
body :body
uri :uri
query-string :query-string
opts :query-params
:as request}
(let [nspace (symbol (str 'actions. type))
action (parse-action action)
opts (assoc opts :uri (str uri "?" query-string))]
(defmacro project-let [bindings & body]
`(binding [project {:name "project-stub", :version "0.0.0", :root "/home/project"}]
(let ~bindings
~@body)))
(deftest file-fn
(testing "single string"
(project-let [s "foo/bar/baz"]
(is (= (str (:root project) "/" s)
(.toString (file s))))))
lance:fulltext master$ cake test
----
Finished in 9.07E-4 seconds.
lance:fulltext master$ cake test
----
Finished in 7.4E-5 seconds.
lance:fulltext master$ mv test.bak test
(defn get-env []
(or (first (:env *opts*))
(get *config* "env")))
(defn create [port f & commands]
(let [commands (apply hash-map commands)]
(server-socket/create-server port
(fn [ins outs]
(binding [*in* (LineNumberingPushbackReader. (InputStreamReader. ins))
*out* (OutputStreamWriter. outs)
(defproject fulltext "0.0.1-SNAPSHOT"
:description "experimenting with fulltext search variants"
:dependencies [[clojure "1.2.0"]
[clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.0"]
[clojure-contrib "1.2.0"]
[postgresql/postgresql "8.4-701.jdbc4"]
[org.clojars.lancepantz/clojure-solr "0.2.0"]]
:environments {:development {:db {:classname "org.postgresql.Driver"
:subprotocol "postgresql"
#!/usr/bin/env cake
(println "hi")
(println "cake opts:" cake/*opts*)
(println "clojure opts:" *command-line-args*)
(deftask crawl
"learn to crawl"
{[me] :me} :when (= me "lance")
(println "opts:" *opts*)
(println "me:" me)
(println "learning to crawl"))
(deftask walk #{crawl}
"learning to walk"
(println "learning to walk"))
(defmacro defile
"Define a file task. Uses the same syntax as deftask, however the task name
is a string representing the name of the file to be generated by the body.
Source files may be specified in the dependencies set, in which case
the file task will only be ran if the source is newer than the destination.
(defile \"main.o\" #{\"main.c\"}
(sh \"cc\" \"-c\" \"-o\" \"main.o\" \"main.c\"))"
[name & forms]
(let [{:keys [deps body doc]} (parse-task-opts forms)
{:keys [destruct pred actions]} (parse-body body)