Sunday, July 14, 2013

Clojure Course in Edinburgh on 7 September


I'm pleased to announce that my Clojure Kickstart course will be held at Neo's offices at TechCube in Edinburgh on the 7th of September 2013.  This course is aimed at beginners and improvers who want to learn Clojure or push their existing skills on to the next level.  

Tickets are now available at http://clojure-kickstart-scotland.eventbrite.co.uk/ for £30.  Just to be clear, the fee is intended to cover costs and anything extra I make will be invested back into making the course even better.

The course will be heavily based on practical exercises.  You will learn...
  • The basic syntax and usage of Clojure
  • The core elements of the Clojure ecosystem
  • What sort of problems are people solving with Clojure in the real world
  • How to make the paradigm shift from Object Oriented to Functional Programming
  • Parallel/multi-threaded Clojure programming and Clojure's transactional memory model
Although Clojure is in its infancy in Scotland, the London community is very strong and I am  delighted to welcome London Clojurian Malcolm Sparks (https://juxt.pro) to Edinburgh as guest facilitator.  

Malcolm will be on hand to help you with the exercises and this is a rare opportunity to get a full-time Clojure programmer's insight on how you can improve your Clojure and Functional programming.  He will also be giving a talk on how Clojure is used in the real-world that will take us all beyond the texbook and into the trenches.

Saturday, February 9, 2013

Finding The Way

Everyone on the Internet is an expert.  Some of them might actually be.

It can be easy to feel like you are chasing an impossible goal when every blog you read makes it look like the author has it all sorted out and their code just flies off their finger tips ready for a quick spot of refactoring and then straight into production.

I don't think it's really like that but I still wonder sometimes if I could somehow make myself more productive by working slightly harder.

An old story  I found on the Aikido FAQ might tell you some of the mindset you ought to apply when studying martial arts and I think it applies to programming too.

A young boy traveled across Japan to the school of a famous martial artist. When he arrived at the dojo he was given an audience by the Sensei
"What do you wish from me?" the master asked. 
"I wish to be your student and become the finest kareteka in the land," the boy replied. "How long must I study?" 
"Ten years at least," the master answered. 
"Ten years is a long time," said the boy. "What if I studied twice as hard as all your other students?" 
"Twenty years," replied the master. 
"Twenty years! What if I practice day and night with all my effort?" 
"Thirty years," was the master's reply. 
"How is it that each time I say I will work harder, you tell me that it will take longer?" the boy asked. 
"The answer is clear. When one eye is fixed upon your destination, there is only one eye left with which to find the Way."



Sunday, January 20, 2013

todo.text


I've been looking for a todo app that fits my workflow.  It must...

  • Work across my devices
  • Allow me to do GTG style task tracking
  • Make it easy to categorise tasks HOW I WANT TO 

You would think it would be simple.  Indeed there are many apps that fit the first 2 categories but the last one is a killer and it seems that most task apps force you to organise your tasks by date (which is pointless when you have a calendar to do that) or priority (which is also pointless because priorities change according to your context).

However, Rob Lally recommended todo.text and it seems to fit the bill nicely.  It uses simple text files to store tasks and dropbox to sync them up between devices.  You also have a command line interface to enter and manage tasks and because it's just text you can sort, search, chop and change using normal UNIX tools.

I used the homebrew package to get started.  It doesn't work out of the box (for version 2.9m at least) but the instructions at http://dangerisgo.com/blog/2012/09/20/setup-todo-dot-txt-cli-on-osx-with-homebrew-and-dropbox/ did the trick.  

One little gotcha - when you change the home location in the cfg file to point at dropbox, make sure you comment out line 5 which sets the location to the install directory.

I'm planning a Clojure course In Scotland

The London Clojurians are running a Clojure dojo on the 29th of January.

This got me thinking that maybe would could do some kind of hands-on course or dojo in Scotland so I have created a survey to gather more information.

http://www.surveymonkey.com/s/WDCTMHM

Any help you can provide by completing and sharing this survey would be greatly appreciated.

Friday, January 13, 2012

Background process management

I ran an impromptu tutorial the other day on background process management from the bash command line with one of my colleagues. I thought it might be helpful to write it up for anyone else who might find it useful.

We were starting a redis server in this case, bit this works for any UNIX process.

So, we can start the server in the background by suffixing the command with an &

$ redis-server /usr/local/etc/redis.conf &

We can then list background processes by running

$ jobs
[1]+ Running redis-server /usr/local/etc/redis.conf &


The [1] indicates a job "handle" (I'm sure there is a proper name for it, but I don't know what it is), that we can pass to the following commands to manage the process:


- fg %1: pulls process 1 into the foreground
- bg %1: pushes process 1 into the background
- kill %1: kills process 1



If you start another process, it will be assigned the next available id which is %2 in this case

$ tail -f project.clj &
[2] 37913
$ (defproject show-grid "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.1"]])
$ jobs
[1]- Running redis-server /usr/local/etc/redis.conf &
[2]+ Running tail -f project.clj &


Killing a process will free up it's handle and it will be reused. This means that for most casual uses, you will only need %1 and, occasionally, %2 unless you run a lot of deamons for some reason.

$ kill %2
[2]+ Terminated: 15 tail -f project.clj
$ jobs
[1]+ Running tail -f project.clj &
$ tail -f README &
[2] 37927

## Usage
FIXME: write
## License
Copyright (C) 2011 FIXME
Distributed under the Eclipse Public License, the same as Clojure.
$ jobs
[1]- Running tail -f project.clj &
[2]+ Running tail -f README &


The problem with simply putting things into the background is that the standard output stream for the process remains attached to your terminal and it will continue to write to your session while you are trying to work on other things. Usually, you want to run the process silently and log the output to a file using nohup like this. Notice that we have merged the stdout and stderr streams so nothing gets lost.

$ nohup redis-server /usr/local/etc/redis.conf > ./redis.log 2>&1 &
[1] 21212
$ tail -f redis.log
[21212] 10 Jan 11:16:39 * Server started, Redis version 2.4.2
[21212] 10 Jan 11:16:39 * DB loaded from disk: 0 seconds
[21212] 10 Jan 11:16:39 * The server is now ready to accept connections on port 6379
[21212] 10 Jan 11:16:39 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:16:44 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:16:49 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:16:54 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:16:59 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:17:04 - 0 clients connected (0 slaves), 922288 bytes in use
[21212] 10 Jan 11:17:09 - 0 clients connected (0 slaves), 922288 bytes in use

Friday, December 23, 2011

lein uberjar ClassNotFoundException

This is probably documented somewhere, but it didn't come up in my searches and it took me forever to find out the cause of the problem so I'm posting it here for the greater good, general advancement of humankind and other worthy reasons.

I had a normal leiningen project with the :main attribute set in project.clj

(defproject clojure-diff "1.0.0-SNAPSHOT"
  ; Dependencies etc omitted for clarity
  :main clojure-diff.server
)

It runs fine using lein run but when I ran lein uberjar and then executed the jar file, I got a class not found error.

$ java -jar clojure-diff-1.0.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.NoClassDefFoundError: clojure_diff/server
Caused by: java.lang.ClassNotFoundException: clojure_diff.server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


The solution is to specify :gen-class when defining the main namespace.  This means a .class file will be generate ahead of time when compiling the jar.  Obvious when you know how!

(ns clojure-diff.server
  (:gen-class)
  ; more namespace setup)

; .. stuff

(defn -main []
  (run-jetty #'clojure-diff.server/app {:port 8080}))


Tuesday, August 23, 2011

Rawk

I've created a gem called rawk.  It's a ruby DSL for command-line processing stream processing based on the classic AWK utility.   I wrote it because I like using awk, but I find it's lack of useful data structures a bit of a pain.  Rawk provides the same block-based processing, but using good old ruby.

Let's take an example.  I want to pretty-print the name and last modification date from a directory where the  filename starts with 'd'


$ ls -l /bin | rawk '
  start do 
    puts %q{Files n /bin starting with "d"}
    @hits = 0
  end


  every do |record|
    if record.cols[8] =~ /^d/
      puts %Q{  "#{record.cols[8]}" modified #{record.cols[6..7].join(" ")}}
      @hits += 1
    end
  end


  finish do 
    puts "#{@nr} files were processed"
    puts %Q{#{@hits} files start with "d"}
  end
'
Files n /bin starting with "d"
  "date" modified Dec 2010
  "dd" modified Dec 2010
  "df" modified Dec 2010
  "domainname" modified Jun 2010
38 files were processed
4 files start with "d"


You can install rak by running "gem install rawk"

See my github page for more information and detailed documentation on how to use rawk.