Mein(un)sinn

Fork me on GitHub

Deploying Clojure Apps on Giant Swarm (Docker)

| Comments

Recently I’ve been playing around with Clojure and docker. Docker provides your app with an isolated container on a Linux machine, sharing the same system resources, while isolating them from the other containers. This has the benefit of providing a separation between apps on a Linux host system, which is much more light weigh than full blown VMs (Virtual Machines).

In this blog post I will describe the setup I used to deploy my pet project named money-balance (a Clojure app) on giantswarm.io, a docker host in Germany. They are currently still in the alpha phase and looking for early adopters, but so far everything was working flawlessly for me. You can find them on gitter.

Versioning Work Notes With Git on Mac

| Comments

I started to keep a loose log of todo’s and related useful information at work. This log is a simple text, file which I use in a append-only fashion. New information gets added at the top, using markdown notation.

Our company provides we with a Google Account, so I put my notes into Google Drive to back it up. You can choose Dropbox or a private git repository for hat matter.

But having just a plain file, makes it hard to keep track of when an entry was made. So I started to use git to take care of the versioning for me. I still keep my files in Google Drive and do not push the git repository, because I’m only interested in the versioning, and not in collaboration of backup.

However I would like for commits to happen on a regular basis instead of me having to remember to also make a commit after changing a file.

Since the usage of cron is discouraged on mac I looked into using apples launchctr deamon.

Launch Control works by loading job descriptions from .plist files, which are noting more than xml files, which are easy enough to write my hand.

You will find your Launch Control files in ~/Library/LaunchAgents.

Here is the plist file I use for my notes velrok.gittify-notes.plist:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>velrok.gittify-notes.plist</string>

    <key>WorkingDirectory</key>
    <string>/Users/velok/Google Drive/notes</string>

    <key>WatchPaths</key>
    <array>
        <string>/Users/velok/Google Drive/notes</string>
    </array>

    <key>ProgramArguments</key>
    <array>
        <string>git</string>
        <string>commit</string>
        <string>-a</string>
        <string>-m</string>
        <string>"snapshot"</string>
    </array>

    <key>ProcessType</key>
    <string>Background</string>
</dict>
</plist>

WorkingDirectory sets the working directory for all the program calls, which makes it very convenient to write out the necessary git calls.

WatchPaths defines an array of path to watch for changes, which is a perfect fit for my notes versioning problem, because it facilitates the triggering of commits every time I save, but not during the long hours I might not change anything at all.

ProgramArguments is essentially the command line call separated in its components. I’m simply adding all the changed files and create a commit with a fixed message.

You will obviously have to have your notes directory initialized as a git repository git init.

If it also contains files that you do not wish to have included I would recommend adding them to a .gitignore file.

To actually register this job and have Launch Control run it you have to load your file launchctl load velrok.gittify-notes.plist. To stop execution of your script you need to unload it launchctl unload velrok.gittify-notes.plist.

Now you should have your git versioned directory of plain text notes running and the launchctrl daemon trigger new commits every time you save your notes file. There is a slight delay of a couple of seconds between the save and the actual commit. Just run “git log” in your notes directory to see a log of commits. A call to git blame notes.md will show you the file contents with time stamps next to each line, so you know, when they changed last.

Developers Love Bacon - Conference

| Comments

bacon

BACON is a two-day conference on all the things developers love.

And that is exactly what it is. A friendly get together of people that like to code and other things they are interested in. All talks are limited to 30 min and come in a huge variety. Thus the talks are more about general inspiration than about hard facts.

Moving to London: Banks and Money

| Comments

money

I moved to London two days ago to start my new job here. So this is an attempt to collect information and sources that I found useful. This article is specifically about Money and basic Banking stuff.

Clojure Lesson Learned

| Comments

background

I started programming Clojure about 5 month ago. So I am fairly new to the language. I’m using Clojure to write my master thesis, which is a recommendation engine for advertisement. When you start to build a recommendation engine stuff like Mahout can be a big help. But it’s java :(, which is very unproductive to write. So I looked into jython and jruby, which enable you to write python and ruby respectively, that runs on the JVM. Sadly neither did the trick. Jython is missing a simple way to bundle everything up in one uber.jar while jruby had some issues finding the correct constructor for one of the mahout classes :(. So I seized that opportunity to learn Clojure, and I regret not a second of it.

I’m now using Clojure and Leiningen. I chose Parallel Colt as my matrix library, where I use wrapper functions to provide a nicer Clojure interface.

I use incanter for basic data analysis and visualisation.

Clojure Getting Started: Setting Up

| Comments

Setting Up a Project

Clojure runs on the JVM so you need a recent JDK version installed (Java 6 or newer should do).

To create a new Clojure project we use Leiningen. On Mac OS it’s just a

1
brew install leiningen

away.

This will install Leiningen 2. Version 2 breaks compatibility with the old plugin system, but most projects that supply Leiningen have a description how to add them to your project.clj for each version. However if you start a new project, always go with Leiningen 2.

To create our getting started project (we will name it greenfield-clojure) run:

1
lein new greenfield-clojure

This will create a new folder. For the rest of this writing all file paths will be relative to this folder.

You should see a project.clj file looking something like this

1
2
3
4
5
6
(defproject greenfield-clojure "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.5.1"]])

As you can see Clojure itself is defined as a dependency. As of this writing the latest version is 1.5.1 .

Now run

1
lein deps

which will download and install all specified dependencies.

During this project we will add additional dependencies to this project. CloJars is a repository for Clojure libaries. There you can find a lot of interesting stuff. You can also include Java dependencies from Maven Central. Please consult the Leiningen sample.project.clj for further information.

Moving the Counter Into the Foreach Loop

| Comments

Recently I did a little code review for a friend of mine. He needed a counter while iterating items of a list. He solved it the same way I did - many times befor, always a little bit annoyed by the fact that I needed to declare and incredent the counter myself.

1
2
3
4
5
6
stuff = ["some thing", "some thing else"]

i = 0
for thing in stuff:
  print "processing item {} of {}".format(i + 1, len(stuff))
  i += 1

Python comes with this nice for i in list formulation, so taking care of a counter seperatly seamed wrong.

update

Big thanks to Rafa Rodríguez for pointing me to enumerate

1
2
3
4
stuff = ["some thing", "some thing else"]

for i, thing in enumerate(stuff):
  print "processing item {} of {}".format(i + 1, len(stuff))

You can skipp the rest :) .

Hello World

| Comments

Hello world, again.

This is about the 4th blog I started.

This time it should be around for longer, beacaue octopress is nicer than wordpress - from a programmers standpoint :) . Also since it’s hosted on github - I will not losse it.

“The significant problems we face cannot be solved at the same level of thinking we were at when we created them.”
- Albert Einstein (1879-1955)
clojure
1
2
3
4
(defn hello [name]
  (println "hello, " name))

(hello "world")
python
1
2
3
4
def hello(name):
  print "hello, ", name

hello("world")
ruby
1
2
3
4
5
def hello(name)
  puts "hello, #{name}"
end

hello "world"