This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def db-conn {:classname "org.postgresql.Driver" | |
:subprotocol "postgresql" | |
:subname "//localhost:5432/scale" | |
:user "scale" | |
:password "scale"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def db-pool {:datasource (doto (new org.postgresql.ds.PGPoolingDataSource) | |
(.setServerName "localhost") | |
(.setDatabaseName "scale") | |
(.setUser "scale") | |
(.setPassword "scale") | |
(.setMaxConnections 1))}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> (from :table1) | |
(where (and (< :table1/a 5) (= :table1/b "x")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(filter (and (< :table1/a 5) (= :table1/b "x")) (collect :table1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(sequel/filter (sequel/and | |
(sequel/< :table1/a 5) | |
(sequel/= :table1/b "x")) | |
(sequel/collect :table1)) |
OlderNewer