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
def build_conditions | |
conditions = [] | |
def condition(cond, &f) | |
if block_given? | |
conditions.concat yield(cond) | |
else | |
conditions.concat lambda {|c| {c => params{c}}}.call | |
end | |
end | |
condition("address") do |addr| |
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 zpmap [f coll] | |
(apply concat | |
(pmap #(doall (map f %)) | |
(partition-all (Math/ceil (/ (count coll) | |
(float (+ 2 (.availableProcessors | |
(Runtime/getRuntime)))))) | |
coll)))) | |
; This is intended for a fast f and large coll, where pmap performs poorly. | |
; It provides a nearly 2x speedup over map on dual-core machines I've tried it on; |
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 'clojure.contrib.seq-utils) | |
(defn npmap [n f coll] | |
(apply concat | |
(pmap #(doall (map f %)) | |
(partition-all (Math/ceil (/ (count coll) | |
(float n))) | |
coll)))) | |
(defn fac |
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
Starting remote lein swank ... | |
Exception in thread "main" java.lang.NullPointerException (NO_SOURCE_FILE:0) | |
at clojure.lang.Compiler.eval(Compiler.java:4658) | |
at clojure.core$eval__5236.invoke(core.clj:2017) | |
at clojure.main$eval_opt__7411.invoke(main.clj:227) | |
at clojure.main$initialize__7418.invoke(main.clj:246) | |
at clojure.main$null_opt__7446.invoke(main.clj:271) | |
at clojure.main$main__7466.doInvoke(main.clj:346) | |
at clojure.lang.RestFn.invoke(RestFn.java:426) | |
at clojure.lang.Var.invoke(Var.java:363) |
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
(= follow-threshold* 5) | |
; ... | |
(def titlelink (s url user) | |
(tag (td class 'title) | |
(if (cansee user s) | |
(do (let toself (blank url) | |
(tag (a href (if toself (item-url s) url) | |
rel (unless (or toself |
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
(defmethod learn :unique-cat [how items] | |
(fn [corpus] | |
(merge-with merge-item | |
corpus | |
items))) |
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 search-items [terms & [cat]] | |
(let [terms-seq (map sql-wildcard | |
(s/split terms #"[ \t]+"))] | |
(select (if cat | |
(items-by-cat cat) | |
items) | |
(where (or (apply or (map (partial ilike :longdesc) terms-seq)) | |
(apply or (map (partial ilike :shortdesc) terms-seq))))))) |
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 trie.core | |
(:refer-clojure :exclude (merge contains?)) | |
(:use clojure.test)) | |
;; some generic trie (prefix tree) functions | |
(def box list) | |
(defn trie | |
"Returns trie for single seq s" |
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
Started POST "/documents" for 127.0.0.1 at 2011-10-21 20:52:27 -0400 | |
Processing by DocumentsController#create as HTML | |
Parameters: {"Filename"=>"Contract.odt", "_urcollege_session"=>"BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWIxODBkMTJhOWNlMDg1ZTY1NzZiZWM5ZGUxYjgxNGMxBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMXM0bzNzY3Z3TWE4WVh6UGZXandkRzJvTFkvVjJvcWNDRUo0M1JjQ1dnTUk9BjsARg==--4e8e0ce753d8618b22cc2e18e80bc753b4831f35", "authenticity_token"=>"s4o3scvwMa8YXzPfWjwdG2oLY/V2oqcCEJ43RcCWgMI=", "folder"=>"/documents/", "attachment"=>#<ActionDispatch::Http::UploadedFile:0x0000000588afe0 @original_filename="Contract.odt", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"attachment\"; filename=\"Contract.odt\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/tmp/RackMultipart20111021-29558-ungtwg>>, "Upload"=>"Submit Query"} | |
(0.1ms) BEGIN | |
SQL (5.1ms) INSERT INTO "documents" ("attachment", "created_at", "processed", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [ |
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
#app/models/document.rb | |
class Document < ActiveRecord::Base | |
has_attached_file :attachment, styles: {html: {}}, :processors => [:htmlprocessor] | |
attr_accessor :attachment_file_name | |
end | |
OlderNewer