Skip to content

Instantly share code, notes, and snippets.

from decorator import decorator
import inspect
@decorator
def deco(f, *a, **kw):
# set a default keyword arg
if 'foo' not in kw:
kw['foo'] = 'bar'
return f(*a, **kw)
(def route-list (atom {}))
(defmacro with-name
[name route]
(swap! route-list assoc name (nth route 1))
route)
;; Needs to get fancier to handle generating routes with parameters
(defn url-for
[route-name]
(import 'org.apache.commons.mail.SimpleEmail)
(doto (SimpleEmail.)
(.setHostName "smtp.gmail.com")
(.setSslSmtpPort "465")
(.setSSL true)
(.addTo "[email protected]")
(.setFrom "[email protected]" "Lucky Clojurian")
(.setSubject "Hello from clojure")
(.setMsg "Wasn't that easy?")
(.setAuthentication "[email protected]" "yourpassword")
(defmacro handle-failure
[& forms]
(let [[body handler] (split-with (complement handler-form?) forms)
e# (symbol "errors")]
`(kit/with-handler
~@body
(kit/handle validation-error [~e#]
~@(rest (first handler))))))
(def db-conn {:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "//localhost:5432/scale"
:user "scale"
:password "scale"})
(def db-pool {:datasource (doto (new org.postgresql.ds.PGPoolingDataSource)
(.setServerName "localhost")
(.setDatabaseName "scale")
(.setUser "scale")
(.setPassword "scale")
(.setMaxConnections 1))})
(ns scale.core
(:use compojure.core, ring.adapter.jetty, hiccup.core
[clojure.contrib.sql :as sql])
(:import javax.sql.DataSource, org.postgresql.ds.PGPoolingDataSource))
(declare scale-app)
(def rows-to-show 10)
(def db-conn {:classname "org.postgresql.Driver"
(-> (from :table1)
(where (and (< :table1/a 5) (= :table1/b "x"))))
(filter (and (< :table1/a 5) (= :table1/b "x")) (collect :table1))
(sequel/filter (sequel/and
(sequel/< :table1/a 5)
(sequel/= :table1/b "x"))
(sequel/collect :table1))