Skip to content

Instantly share code, notes, and snippets.

View brentonashworth's full-sized avatar

Brenton Ashworth brentonashworth

View GitHub Profile
(ns hammock-cafe.ui.history
(:require [io.pedestal.app.protocols :as p]
[io.pedestal.app.util.log :as log]
[io.pedestal.app.messages :as msg]))
(def last-page (atom nil))
(def dispatchers (atom {}))
(defn navigate [token]
(def default-special-fns
(let [load-file-fn (fn [repl-env file] (load-file repl-env file))]
{'in-ns (fn [_ quoted-ns] (set! comp/*cljs-ns* (second quoted-ns)))
'load-file load-file-fn
'clojure.core/load-file load-file-fn
'load-namespace (fn [repl-env ns] (load-namespace repl-env ns))}))
(defn repl
"Note - repl will reload core.cljs every time, even if supplied old repl-env"
[repl-env & {:keys [verbose warn-on-undeclared special-fns]}]
(ns hack.queue)
(defn log [form]
(.log js/console (pr-str form)))
(defprotocol Queue
(pop [this])
(empty? [this])
(peek [this])
(append [this x]))
;; This is a clojure.test test case which enters a value in a form
;; field in the browser, clicks the submit button and checks that the
;; correct information is displayed in the page and that the client
;; and server state is as it should be. 'database' is an atom in the
;; server and 'state' is an atom in the browser.
(deftest test-enter-name
(reset! database #{})
;; evaluate two forms in the browser in the start.view namespace
(cljs-eval start.view
(dom/set-value :name-input "Ted")
@brentonashworth
brentonashworth / gist:1343920
Created November 7, 2011 00:50
ClojureScript Demo
;; ClojureScript Demo
;; ==================
(use 'cljs.closure)
;; ClojureScript compiler examples
(println (-compile '(defn add [a b] (+ a b)) {}))
(println (-compile '(defn add [& args] (reduce + args)) {}))
@brentonashworth
brentonashworth / gist:926824
Created April 19, 2011 04:42
Add request header into to form input
(defform foo-form "/foo"
:fields [(hidden :id)
(hidden :remote-addr)
(textfield "Enter Your Foo" :foo)]
:on-cancel "/"
:on-success
#(do
(flash-put! :message (str %))
"/")
:defaults (fn [request]
@brentonashworth
brentonashworth / gist:904481
Created April 5, 2011 20:32
Polymorphic on return type
{-# LANGUAGE TypeSynonymInstances #-}
class TwoOf a where
twoOf :: String -> a
instance TwoOf Bool where
twoOf str = length str >= 2
instance TwoOf String where
twoOf str = take 2 str
user=> (use 'leibniz.derivative)
nil
user=> (def y '(* (+ (* 3 ?x) 4) (+ (* 4 ?x) 6)))
#'user/y
user=> (def fy (f [?x] y))
#'user/fy
user=> (fy 7)
850
user=> (deriv y ?x)
(+ (* 24 ?x) 34)
$(function() {
$("#hire-date").datepicker({dateFormat: 'yy-mm-dd'});
$("#language").autocomplete({source: "langs-starting-with"});
$("#name").blur(function() {
validateField("name");
});
div.sandbar-field {
position: relative;
}
div.sandbar-form div.error-message {
height: 24px;
padding-left: 24px;
background: url(../images/warning.png) no-repeat 4px -2px;
color: red;
vertical-align: bottom;