Skip to content

Instantly share code, notes, and snippets.

Chris Granger ibdknox

Block or report user

Report or block ibdknox

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ibdknox
ibdknox / defpartial.clj
Created Jun 27, 2011
defpartial source
View defpartial.clj
(defmacro defpartial
"Create a function that returns html using hiccup. The function is
callable with the given name."
[fname params & body]
`(defn ~fname ~params
(html
~@body)))
(defpartial hello [person]
[:p "Hello " person])
@ibdknox
ibdknox / map.clj
Created Jun 28, 2011
defpartial with map
View map.clj
(defpartial post-item [{:keys [perma-link title md-body date tme]}]
[:li.post
[:h2 (link-to perma-link title)]
[:ul.datetime
[:li date]
[:li tme]]
[:div.content md-body]])
(defpartial posts-list [items]
[:ul.posts
View bot.clj
(defn my-bot []
(doseq [ant (my-ants)]
(let [f (closest ant (food))
food-dirs (shuffle (direction ant f))
dirs (concat food-dirs (shuffle directions))]
(when-let [dir (first (drop-while #(not (valid-move? ant %)) dirs))]
(move ant dir)))))
@ibdknox
ibdknox / cookies.clj
Created Jul 25, 2011
sessions and cookies
View cookies.clj
(require '[noir.cookies :as cookies])
(cookies/put! :user-id 2)
(cookies/get :user-id)
;; => 2
(cookies/get :username "anon")
;; => "anon"
;; you can also pass a map that has all the cookie's attributes
View complexparams.clj
(defpage [:get ["/user/:id" :id #"\d+"]] {:keys [id]}
(str "You are user number " id))
View genhandler.clj
(require '[noir.server :as server])
(server/load-views "src/noir-example/views")
(def handler (server/gen-handler {:mode :dev
:ns 'noir-example}))
View add.clj
(server/add-middleware my-middleware)
View solution.clj
#(:longest
(reduce
(fn [{:keys [longest cur] :as res} n]
(let [{:keys [cur] :as updated} (if (or (not (seq cur))
(> n (last cur)))
(update-in res [:cur] conj n)
(assoc res :cur [n]))
longest-cnt (count longest)
cur-cnt (count cur)]
(if (and (> cur-cnt 1)
View todos.clj
(ns todos.views.welcome
(:require [todos.views.common :as common]
[noir.content.pages :as pages]
[noir.response :as resp])
(:use noir.core
hiccup.core
hiccup.form-helpers
hiccup.page-helpers))
(defonce todos (atom {1 "Get milk"
View force-realized.clj
(ns cljs-test.client)
(defn now []
(. (js/Date.) (getTime)))
(let [nums (doall (range 0 1000000))
start (now)]
(doseq [n nums]
)
(. js/console (log (- (now) start))))
You can’t perform that action at this time.