Caused by: java.lang.RuntimeException: No such var: json/pprint

Clojure, Clojurescript No Comments »

If you get (for example when using a later version of cljsbuild):

Caused by: java.lang.RuntimeException: No such var: json/pprint

You may need

Hope it helps.

[Slashdot] [Digg] [Reddit] [] [Facebook] [Technorati] [Google] [StumbleUpon]

Hippo CMS and PostgreSQL – The Setup

Hippo CMS, PostgreSQL No Comments »

The original instructions on the Hippo site are somewhat outdated. Moreover, the linked blog post is currently down but still has a copy:

Most of the instructions are still relevant but it’s probably unnecessary to install HST 2, so the first step can be skipped.

The instructions starting at “Go to your-project-dir/cms/src/main/webapp/WEB-INF…” are still correct, however in the repository.xml the section

  <Security appName="Jackrabbit">
    <AccessManager class=""/>
    <LoginModule class=""/>

now has to be 

  <Security appName="Jackrabbit">
    <SecurityManager class=""/>
    <AccessManager class=""/>
    <LoginModule class=""/>

because of an upgrade. Note the new SecurityManager tag. You otherwise get

java.lang.ClassCastException: cannot be cast to

As for step three, it’s now unnecesary to copy around any jar files.

Simply add a dependency in <cms_root>/cms/pom.xml like so:


Then run

mvn clean install

and enjoy a scalable and flexible backend for your Hippo CMS.

[Slashdot] [Digg] [Reddit] [] [Facebook] [Technorati] [Google] [StumbleUpon]

Date Formats in Clojurescript

Clojure, Clojurescript No Comments »

Formatting dates in JavaScript can be tricky, even getting the name of the month.

It’s possible to use the clunky $.datepicker.formatDate (); from jquery.ui, but in Clojurescript we have the Google Clojure library at our disposal.

Its goog.i18n.DateTimeFormat class has a few useful functions that can be applied like so:

Example usage:

> (format-date-generic :LONG_DATE (js/Date.))

> “July 14, 2012”

> (format-date-generic “dd MMMM yyyy” (js/Date.))

> “14 July 2012”

> (format-date-generic “MMMM” (js/Date.))

> “July”

Ah, there’s the name of the month!

[Slashdot] [Digg] [Reddit] [] [Facebook] [Technorati] [Google] [StumbleUpon]

Thumbs from Downloaded Images in Clojure

Clojure No Comments »

The code creates a thumb from either a local file or a remote URI. It combines ideas from a blog post dealing with image downoads in clojure and an older post dealing with thumbnail creation.

(import javax.imageio.ImageIO)
(import java.awt.image.BufferedImage)
(use '[ :o nly [as-file input-stream output-stream] :as io])
(defn make-thumbnail-generic [input new-filename width]
(let [img (javax.imageio.ImageIO/read input)
imgtype (java.awt.image.BufferedImage/TYPE_INT_ARGB)
width (min (.getWidth img) width)
height (* (/ width (.getWidth img)) (.getHeight img))
simg (java.awt.image.BufferedImage. width height imgtype)
g (.createGraphics simg)]
(.drawImage g img 0 0 width height nil)
(.dispose g)
(javax.imageio.ImageIO/write simg "png" (as-file new-filename))))
(defn make-thumbnail-from-file [filename new-filename width]
(make-thumbnail-generic filename new-filename width))
(defn make-thumbnail-from-stream [uri file width]
(with-open [in (io/input-stream uri)
out (io/output-stream file)]
(make-thumbnail-generic in out width)))

Example usage:

(make-thumbnail-from-stream some-image-url (str “~/my_thumbs/” (some-image-id) “.png”) 100)


[Slashdot] [Digg] [Reddit] [] [Facebook] [Technorati] [Google] [StumbleUpon]

Naïveté to Brilliance

Clojure No Comments »

Unlike Scala, even beginning learners of Clojure will experience the fun of functional programming almost immediately. 

Converting the Rails function “simple_format” from Ruby

def simple_format(text, html_options={}, options={})
        text = text ? text.to_str : ”
        text = text.dup if text.frozen?
        start_tag = tag(‘p’, html_options, true)
        text.gsub!(/\r\n?/, “\n”)                    # \r\n and \r -> \n
        text.gsub!(/\n\n+/, “</p>\n\n#{start_tag}”)  # 2+ newline  -> paragraph
        text.gsub!(/([^\n]\n)(?=[^\n])/, ‘\1<br />’) # 1 newline   -> br
        text.insert 0, start_tag
        text = sanitize(text) unless options[:sanitize] == false

to Clojure (leaving out options)

(defn simple-format [text]
  (let [patterns 
      {#"\r\n?" "\n"  #"\n\n+" "</p>\n\n<p>" #"([^\n]\n)(?=[^\n])” (str #”$1″  “<br />”)}
    (str “<p>” (reduce #(clojure.string/replace %1  (key %2) (val %2)) text patterns) “</p>”)))

illustrates the fundamental naïveté of imperative programming with its silly reassignments, incidental state and mutability. It’s laughing at this and marvelling at the sheer brilliance of Clojure in equal measure that make Clojure so much fun.

[Slashdot] [Digg] [Reddit] [] [Facebook] [Technorati] [Google] [StumbleUpon]