Skip to content

Instantly share code, notes, and snippets.

View lrenn's full-sized avatar

Luke Renn lrenn

  • Philadelphia, PA
View GitHub Profile
(deftest test-encrypt-decrypt
(let [message "Foo Bar Bizz Buzz"
algorithm "AES/CBC/PKCS5Padding"
param (gen-iv-param 16)]
(is (= (decrypt *secret-key* algorithm param
(encrypt *secret-key* algorithm param message))
message))))
(defn login-view [flash]
(html [:html
[:body
[:h2 "Login"]
(if-let [message (:message flash)]
[:h4 message])
(form-to [:post "/login"]
(text-field :username)
(password-field :password)
(submit-button "Login"))]]))
; Could use http://github.com/mmcgrana/ring/blob/24fe773f62026b95e275468f6875812f87989508/src/ring/file_info.clj
(def *default-mimetypes*
{"xml" "text/xml"})
; Being kind of lazy here :)
(defn- extension
[s]
(nth (re-find #"\.(.*$)" s) 1 ""))
; Note, this won't work on routes that return a string since we already default
(import 'java.io.ByteArrayOutputStream)
(import 'java.io.ByteArrayInputStream)
(import 'com.lowagie.text.Document)
(import 'com.lowagie.text.DocumentException)
(import 'com.lowagie.text.Paragraph)
(import 'com.lowagie.text.pdf.PdfWriter)
(defn gen-pdf-stream [title]
(let [doc (new Document)
stream (ByteArrayOutputStream.)
(defn with-uri-rewrite
"Rewrites a request uri with the result of calling f with the
request's original uri. If f returns nil or the original uri no
rewrite occurs."
[handler f]
(fn [request]
(let [uri (:uri request)
rewrite (f uri)]
(if-not (or (nil? rewrite)
(= uri rewrite))
;;; ant/xml way
;;; supports :transitive true/false and :conf "configuration/scope".
;;; This is obviously pretty basic...
(ns cake.tasks.ivy
(:use cake cake.ant clojure.contrib.prxml
[clojure.java.io :only [writer]]
[cake.project :only [group]])
(:import [java.io File]
[org.apache.tools.ant.taskdefs Copy Delete ExecTask Move]
(deftask ivy-publish-local #{resolve}
"Publish this project to the local ivy repository."
(ant IvyPublish {:resolver "local"
:forcedeliver "true"
:srcivypattern "ivy-[revision].xml"
:artifactspattern "[artifact]-[revision].[ext]"}))
;; removing the :forcedeliver "true" and it works.
(defn make-mapping [task attrs]
(.addMapping task (make IvyMakePom$Mapping attrs)))
(deftask ivy-pom #{resolve}
"Create a pom file."
(ant IvyMakePom {:ivy-file "ivy.xml" :pom-file "pom.xml" }
(make-mapping {:conf "default" :scope "compile"})))
;; quick and dirty, but that's what needs to be done to support inner classes.
(defn make*
([class attrs]
(let [attrs (merge (defaults class) attrs)]
(doto (make* class)
(set-attributes! attrs))))
([class]
(if-let [parent-class (.getDeclaringClass class)]
(.newInstance (.getConstructor class (into-array [parent-class])) (into-array [(.newInstance parent-class)]))
(let [signature (into-array Class [Project])]
[resolve] org.clojure#clojure;1.1.0 by [org.clojure#clojure;1.2.0] in [dev
elop]
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| master | 0 | 0 | 0 | 0 || 0 | 0 |
| default | 43 | 33 | 33 | 7 || 35 | 32 |
| develop | 6 | 3 | 3 | 2 || 4 | 3 |
---------------------------------------------------------------------