Slide transitions between html sections using jquery

I needed to make the picture in my head of the interface and workflow for my pet project clojure-blog more concrete.

To split tasks up in multiple steps for the user (not the communication to the server) was essential. The transition Gnome 3 uses in “System Settings” was what I was looking for.

I’ve googled for it several hours only to find complex examples of something the almost did what I wanted.

I finally gave in and started to put something together which I expected to be at least as complex as all the code I had already seen through my search for a solution… it wasn’t :)

The following is some very nice (short and readable) piece of very generic code which uses the new html5 tag section and normal links with internal references to structure the content.

You can demo an example of it here on jsFiddle

Both the html and js is clean… styles for body and h1 can safely be removed together with all css properties defining colors and margin.

A plugin system for clojure-blog

In order to support different syntax for posts, smileys and hook-ins in general I searched the web for inspiration and found the following link which have some cool info:

http://stackoverflow.com/questions/10272559/how-best-to-structure-and-build-clojure-apps-with-plugins

I’ve started small and decided to support changing the post content via a hook-in before handing it over to the html generator Enlive. The way it works is by registering any number of functions which can transform post content in a chain (vector). Zero functions means no transformation and the post content is serves as-is.

Here is some example code which can demo the thoughts behind the design so far:

(defonce changes (atom []))

(defn reg-change
  "Registers a fn (change) to a hook"
  [hook-name f]
  (swap! hook-name conj f))

(defn apply-changes
  "Applies all changes in the vector to the input"
  [change-vec input]
  (reduce #(%2 %1) input @change-vec))

(apply-changes changes "Test is good")

(defn good-is-bad [text] (clojure.string/replace text "good" "bad"))

(reg-change changes good-is-bad)

(apply-changes changes "Test is good")

A blog in Clojure

I decided to write a blog in Clojure - my reasons:

  • It is alot more motivating working on something “real” - and I need practice to learn
  • Make markdown syntax for blog posts a first class citizen. This is is a tough fight with Wordpress (was? - haven’t poked at for some time now). Though wysiwyg (html) is just as important… now I just have to figure out a way to make both work well in parallel :D
  • Instead of just storing posts in the database and generating pages dynamic on request, I want the blog to generate static html pages whenever a post is created or updated. The same with comments.

I have put my code on Github and I’ll share my design ideas as it progresses.

Lazy import of csv file in Clojure

I’ve been looking at Clojure now and then for a while… really wanna learn this stuff :) The other day I needed to import a very large CSV file… and it seemed like a good problem to try solve in Clojure.

I’m using Leiningen and started with the following project setup.

project.clj:

(defproject bbr "1.0.0"
  :description "Import BBR data"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [org.clojure/java.jdbc "0.0.6"]
                 [mysql/mysql-connector-java "5.1.6"]
                 [clojure-csv "2.0.0-alpha2"]])

core.clj:

(ns bbr.core
  (:require [clojure-csv.core :as csv]
            [clojure.java.jdbc :as sql])
  (:use [clojure.java.io :only [reader]]))

(def db {:classname "com.mysql.jdbc.Driver"
         :subprotocol "mysql"
         :subname "//localhost:3306/mydb"
         :user "root"})

(defn parse-row [row]
  (let [v (first (csv/parse-csv row :delimiter \;))]
    (zipmap [:kvhx :road :no :floor :door :zip_code :city] v)))

(defn parse-file
  [filename]
  (with-open [file (reader filename :encoding "ISO-8859-1")]
    (sql/with-connection db
      (doseq [line (line-seq file)]
        (let [record (parse-row line)]
          (sql/update-or-insert-values "bbr" ["kvhx=?" (:kvhx record)] record))))))

The above should be able to import VERY large CSV files into the database because it reads one line from the file at the time.

Quick Launch Looking Glass

Today I took the plunge into something I’ve been wanting to do for a very long time: help developing Open Source Software. I’ve started off small :) I’ve been messing around with gnome-shell and looking into how extensions work. What better way to start than scratching and itch? I found it annoying to press Alt+F2 followed by “lg” and Enter to open Looking Glass (Gnome 3’s integrated debugger and inspector tool) all the time.

Now I’ve created a small extension which binds opening Looking Glass to a keyboard shortcut for Gnome 3.2.

To install: download Quick Launch Looking Glass and install it using gnome-tweak-tool or by extraction it in:

~/.local/share/gnome-shell/extensions/

Followed by a restart of gnome-shell.

I haven’t been able to figure out how to add a new custom key binding for a gnome-shell extension so I’ve used the reserved “run command 9” by Metacity until I figure out something better.

If you haven’t bound it already - here is an example on how to bind it to the key F12:

gconftool-2 -s --type string "/apps/metacity/global_keybindings/run_command_9" 'F12'

If the extension is enabled then Looking Glass will open when you press F12 (just close it by hitting Escape like normal).