Clojure compojure app in Heroku

Tried out today the clojure compojure app deployment into heroku.com cloud service. Deployment didn’t went as smoothly as one might have expected:

  1. By default it wanted to use Java6 instead of Java7.
  2. App didn’t start.
  3. It wanted to use older (< 2.0) Leiningen by default.
  4. App was oddly named in the heroku’s end,  and resulted non-descriptive domain url.

These all were easy to fix:

  1. Add a new file into your project’s root:
     echo "java.runtime.version=1.7" > system.properties
  2. Add a new file into your project’s root:
     echo "web: lein ring server-headless $PORT" > Procfile
  3. Add into project.clj file:
    :min-lein-version "2.0.0"
  4. You can simply rename the app through the heroku dashboard  and app’s settings pane, with rename functionality. Note that the heroku git repository name also changes, so you have to manually change it into your local project’s ./git/config-file so you can continue pushing into production.

Weather Forecaster Statistics

As a coder, one sometimes wonders if anybody uses your online service. Therefore, when Weather Forecaster went online on this site, I put a simple statistics collector for the ‘spell castings’ of it. Here are the results for year 2013, and it clearly shows that there are some users.
Forecasts 2013
Note, that no data is collected about the actual users. So there is no data of how many unique users there are, or where they hail from. I am happy, if there is even one user!

Clojure Schema validation

Schema is a Clojure library for declarative data description and validation. Basically it will throw exception when data is not what it is supposed to be.

Couldn’t find by googling a way to enable date to be either existing or not known (null). So when I figured it out, I wanted to share solution with everybody. The example requires that the person has a name (String), but birthdate (Date) is not required.

1
2
3
4
5
6
7
8
9
(:require [schema.core :as s])
 
(defn person
  [name born]
  (s/validate s/Str name)
  (s/validate (s/either java.util.Date (s/pred nil?)) born)
  {:name name
   :born born
  })

Oh, and it is also possible to combine different types like Integers and Strings for enum validation:

1
2
3
4
5
6
7
8
9
(:require [schema.core :as s])
 
(defn person
  [name hands]
  (s/validate s/Str name)
  (s/validate (s/enum 1 2 "none") hands)
  {:name name
   :hands hands
  })

Obawangchicheng got finished?

Well, it didn’t. The project is insane, but still slowly progressing. Here is a collage of pictures (360 °) of current status of the project. Oh, I have my both children now roaming the region with me, as I turned the world into an inhouse server.

Just a reminder, that every block is mined first, and then placed by hand one by one.