Skip to content

Instantly share code, notes, and snippets.

@zakwilson
zakwilson / gist:9835180
Created March 28, 2014 15:16
Mirah declaration/scope issue
package com.classifyr.hello_world
import android.app.Activity
import android.widget.Button
import android.widget.Toast
import android.view.View
import android.view.View.OnClickListener
import android.hardware.SensorManager
description "train the spam filter"
instance $x
stop on reddit-stop or runlevel [016]
respawn
respawn limit 10 5
nice 10
@zakwilson
zakwilson / korma-npe.clj
Created December 2, 2011 18:27
Basic example with 0.3.0-alpha5 showing exception
(defdb db
(postgres {:password "a-password", :user "timeline", :db "timeline"})
(defentity tag
(database db)
(table :tags)
(pk :tag))
(sql-only (select tag))
@zakwilson
zakwilson / CQL-query.clj
Created December 1, 2011 09:39
Query in CQL
(defn user-feedback [user-id]
(-> (select users (where (= :users.id user-id)))
(join items (where (= :items.user_id :users.id)))
(join reservations (where (or (= :renter :users.id)
(= :item :items.id))))
(join feedback (where (= :reservation :reservations.id)))
distinct
(project [:feedback.id :feedback.reservation :feedback.score :feedback.sender :feedback.comment])))
(def bot-name "irclj_bot_test")
(def irc-server "irc.freenode.net")
(def irc-channel "#clojure")
(def msgs (agent []))
(def info (agent []))
(defn log-info [{:keys [nick channel message irc errors doing]}]
(send info conj message))
#app/models/document.rb
class Document < ActiveRecord::Base
has_attached_file :attachment, styles: {html: {}}, :processors => [:htmlprocessor]
attr_accessor :attachment_file_name
end
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" [
(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"
(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)))))))
(defmethod learn :unique-cat [how items]
(fn [corpus]
(merge-with merge-item
corpus
items)))