Skip to content

Instantly share code, notes, and snippets.

@shaunr0b
shaunr0b / test_gist.rb
Created December 22, 2011 23:06
A simple test
class Search
include Mongoid::Document
field :query, :type => Hash
field :collection
embedded_in :user
def to_criteria
Mongoid::Criteria.new( collection.titleize.constantize ).fuse( query )
@shaunr0b
shaunr0b / us_counties.yml
Created December 31, 2011 18:59
A collection of all US Counties by State in YAML
Alabama:
- Autauga County
- Baldwin County
- Barbour County
- Bibb County
- Blount County
- Bullock County
- Butler County
- Calhoun County
- Chambers County
@shaunr0b
shaunr0b / identless-datomic-functions.clj
Last active August 29, 2015 13:57
Snippet that registers a Datomic attribute with function valueType; then create an enitity with a function. Next, retrieve the function via a query, bind it to a var, and invoke it using params.
(require '[datomic.api :as d])
(def uri "datomic:mem://hello")
(d/create-database uri)
;; Define a transaction to create an attribute with type function (:some/fn)
(def attribute-tx [ {:db/id (d/tempid :db.part/db)
:db/ident :regular/attribute
:db/cardinality :db.cardinality/one
; NUMBERS
(+ 5 5)
(* 5 5)
(/ 5 5)
(- 5 5)
(/ 2 3)
(/ 2.2 3.3)
(let [a (System/nanoTime)
b (Thread/sleep 2301)
c (System/nanoTime)]
(.toMillis java.util.concurrent.TimeUnit/NANOSECONDS
(- c a))) ; => 2301
(ns hello-world.core
(:require [org.httpkit.server :refer [run-server]]
[compojure.core :refer (GET defroutes)]
[compojure.route :as route]
[hiccup.core :refer (html)]
[hiccup.page :refer (html5)]
[ring.middleware.resource :refer (wrap-resource)]
[ring.middleware.file-info :refer (wrap-file-info)]))
(ns example.runner
(:require [taoensso.timbre :as timbre])))
(timbre/refer-timbre)
(defn run-service
"Apply each member of a collection to a function.
Collect and return simple profiling info,
success and failures."
@shaunr0b
shaunr0b / dropbox.clj
Last active August 29, 2015 14:04
Upload a file to dropbox abstraction
(defn save-file
"Saves a file to dropbox
dropbox component
data spittable data to save
file-label keyword file label
file-ext keyword file extension"
[dropbox data file-label file-ext]
(let [file-label (name file-label)
file-ext (name file-ext)
now (java.util.Date.)
@shaunr0b
shaunr0b / ari-firehose.clj
Last active August 29, 2015 14:05
Firehose
(def box (atom nil))
(def futures (atom nil))
{:a "1" :b "2"}
[:a "1"]
[:b "2"]
(defn my-fn [{input-map :key some-var :a} name [x y z] ]
;; in a cider repl
;; start system / webserver
(user/reset)
;; Start browser-connected repl
(require 'cljs.repl.browser)
(cemerick.piggieback/cljs-repl
:repl-env (cljs.repl.browser/repl-env :port 9000))
;; Visit http://localhost:3000 in Chrome.