Skip to content

Instantly share code, notes, and snippets.

View mwmitchell's full-sized avatar

Matt Mitchell mwmitchell

View GitHub Profile
Matt-Mitchells-MacBook-Pro:solrland mattmitchell$ lein swank
Exception in thread "main" java.lang.Exception: No such var: version/abbrev (project.clj:3)
at clojure.lang.Compiler.analyze(Compiler.java:5205)
at clojure.lang.Compiler.analyze(Compiler.java:5151)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3036)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
at clojure.lang.Compiler.analyze(Compiler.java:5190)
at clojure.lang.Compiler.analyze(Compiler.java:5151)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3057)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:5371)
{:docs [{:name "Boston" :lat 0 :lng 0}]
:facets {:property-types [{:name "xxx" :code "xxx" :num-hotels 0}]}
:stats {:stars {:min 0 ...}}
(defn ok? [x]
(expect x => (contains {:id number?})))
(fact
[{:id 0} {:id 3}] => (has every? ok?))
(defn string-or-nil? [x] (or (string? x) (nil? x)))
hotel => (contains {:lat number? :lng number? :name string?
:address (contains {:line1 string-or-nil?
:line2 string-or-nil?
:city string?
:region string?
:postal_code string?
:country_code string?
:country_name string?})
;; calling this:
(def-field [:data] (str "hello!"))
;; creates this:
{:fields [:data] :builder `(clojure.core/str "hello!")}
(def servers {})
(def default-core :production)
(defmacro with-server
"Execute body with the *server* binding set"
([body] (with-server default-core body))
([server-name & body]
`(binding [*server* (~server-name *servers*)]
~@body)))
@mwmitchell
mwmitchell / gist:1028011
Created June 15, 2011 20:21
weird slime error when querying solr
Debugger entered--Lisp error: (end-of-file)
byte-code("\302\300\"\210\303 \304\"\210\300\305\"\207" [error process debug slime-net-close t "net-read error: %S"] 3)
slime-net-read-or-lose(#<process SLIME Lisp>)
slime-process-available-input(#<process SLIME Lisp>)
slime-net-filter(#<process SLIME Lisp> " University of Virginia and Rotunda. Features. Courtyard by Marriott Charlottesville North has a...\\\", :h_lat 38.07323, :id \\\"hotel 0tOlou5mT04rGcJ002f129iS\\\", :h_location_tid \\\"1LTobQ5UP04rBth002f129iS\\\"}}, :facets ()}\") 12)")
@mwmitchell
mwmitchell / rsolr-extension.rb
Created May 12, 2011 01:55
force POST for all requests, and silence all errors
solr = RSolr.connect(:timeout => 60, :url => "http://localhost:8983/solr")
module RSolr4Duncan
def build_request path, opts
super path, opts.merge(:method => :post)
end
def send_and_receive path, opts
super rescue {}
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
\000-\0 31]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
@mwmitchell
mwmitchell / parser.clj
Created May 5, 2011 17:20
reconstitution of de-normalized hashes (1 level deep only)
(defn parse-de-normalized-list [items]
(let [r #"^.+::.+$"
reducer (fn [prod item]
(if-not (re-find r (:code item))
(let [child-r (re-pattern (str "^" (:code item) "::.+$"))
children (filter #(re-find child-r (:code %1)) items)
new-item (merge item {:children (vec children)})]
(merge prod new-item))
prod))]
(reduce reducer [] items)))