CSON Configuration files2013-12-27

CoffeeScript is a brief and clear language that is also very readable once one becomes used to it. Still many people dislike it and for good reasons. A lot of the tooling that is available for Javascript does not exist for coffee script and it can be surprising to see the Javascript that a snippet of CoffeeScript compiles into.

Most annoying is the lack of correct line numbers in stack traces, though. This is a real bummer and makes it a big challenge to work with Coffeescript as the main language in a large project, but lets not get into that.

The point I wanted to make is that CSON (CoffeeScript Object Notation) is a great format for configuration, and it is easy to read.

parseCSON = (str) ->
  return (new Function coffee.compile "return {\n#{str.replace /^/gm, '  '}}", bare: 1)()

The above function could read a file formatted like coffee script:

  cats: ['abe', 'babe']
  count: 101
  location: process.env.PREFIX + '/foo/bar'

I think this type of dynamic CSON is a much better format than JSON for configuration files. The notation is more forgiving and it is possible to do minimal computations, like accessing process.env. This is a feature that should be used with discipline to avoid actual code in configuration files.

GNU Make and Guile Scheme2013-12-20

I recently discovered that Guile Scheme integration has been added to GNU Make 4.0 among a good deal of other nice features.

Scheme is an interesting programming language and I was a bit excited about the possibility of using Scheme in Make to create useful build tools. Maybe a handful of useful tools will be built with Guile for Make over time?

Unfortunately I think that this is probably not something that will have much success. The syntax to call Guile in a Makefile is rather clunky and most of the more complex actions that could be done in Scheme are probably better done using external tools written in more broadly understood languages with bigger and more complete libraries...

The Arch Linux GNU Make package depends on Guile, which means that Scheme scripts for makefiles are here to stay. But are these useful for something else beyond one-off calculations and simple text manipulation?

Andandole Beats2013-09-25

Have some nice beats: andandole beats.

JS1k: Moth Goo2013-04-01

My js1k entry has been accepted! You can find it at js1k.com here.

Note that a bug causes the game to fail loading, so you may have to reload the page after clicking the above link. Irritating bug, i know.

I have had great fun making this entry to the spring competition and it has been amazing to see how much that can be done in 1024 bytes of Javascript. Do take a look at the demos. There are some truly awe inspiring examples and creative ideas.

In terms of fun the JS1k competition owes a lot to the world of byte saving techniques and tools that are being built to automate this such as jscrush or crunchme.

Also the Canvas element is really amazing. MDN has some good canvas docs.

Custom git log2012-12-18

The most interesting tools I have used to examine the git log include tig for use in the terminal, gitk which gives a very nice graphical overview and the fugitive plugin for using git from vim.

Despite all these nice tools I often use the git log command in the terminal because it is quick and easily to type. I have used this git log alias in my ~/.gitconfig quite a lot:

lg = log  --graph --decorate --date-order --pretty=oneline --date=local --abbrev-commit --all

I wanted to improve on this and lo! this script was created:

  gitShortLog() {
      local ymd=$(date +%F)
      local ym=$(date +%Y-%m)
      local y=$(date +%Y)
      local f="%w($(($COLUMNS - 4)), 0, 9)%C(cyan)%ad %C(magenta)%aE%Cgreen%d %Creset%s"
      git log --graph --date-order --date=iso --abbrev-commit --color --all \
              --pretty=format:"$f" $@ \
              | sed -e 's/ [+-][0-9][0-9][0-9][0-9] / /' \
                      -e 's/@[a-z0-9_.\-]\+//i' \
                      -e "s/${ymd} \\|${ym}-\\|${y}-//" | less
  alias gl='gitShortLog'

This script includes the date and time of a commit, the user that created the commit and a short status message. Some superfluous information is removed, i.e. the time offset (+0100), the domain of the committer (assuming that the username part of email addresses is unique, which it often is) and the part of the date that corresponds to the current moment (i.e. only 10-11 is displayed if the commit date is 2012-10-11 and the current year is 2012).

Using a shell function The instead of a git log alias allows use of the $COLUMNS variable to calculate where to break lines. The %w() format option takes care of that. Subtracting 4 from $COLUMNS made the output a bit nicer to look at.

The three invocations of the date command could probably be avoided by making the sed regex a bit nicer,...

Line Length Vim plugin2012-12-04

Released the line_length vim plugin which lets you set a maximum line length. Lines that are longer than this maximum will have the overflowing parts marked with a custom background color.


For a long time I have not updated this site, but now is the time to revive some of the content that could once be found here... ☺