A more complex quine

A follow-on from my earlier post about quines.

With just a little bit of spare time…

After my earlier post I thought I might try to make a more complex quine. I decided to make a counting quine; where there is a number in the source code and each time you run the code the number is incremented. For this to be interesting (even to be really noticeable) I formatted the numbers as a 5×7(ish) grid of characters. For example:

  #   ##  ####
 ##  #  #    #
  #    #   ###
  #   #      #
 ### #### ####

(although the line-spacing here makes them harder to read than a text editor or GitHub.)

The first thing I realised as I was exploring with this idea was that Continue reading

Quines

I was recently reminded of the concept of a quine. A quine is a computer program which takes no arguments and whose output is it’s own source code. It’s a neat little idea.

Let’s write

I’d seen some quines but hadn’t studied their solutions. So I though I’d try my hand and see how I would go at writing one. I used my current language-of-choice, Groovy. I’ve put my code, including a shell script to test your quines, up in a Github repo at https://github.com/dnahodil/groovy-quine.

So let’s get started. Create a new Continue reading

My first community presentation

Over the last 6 months I’ve attended a few nights at my local web developer group, Webdev 42°. For a little while I’ve thought that I should do a presentation of my own.

Originally I had thought about presenting about Groovy and Grails as I use them at my workplace, and I think that knowing about them would really open the eyes of anyone who develops webapps on the JVM. However after thinking about it more I realised that Continue reading

Adding Groovy extension modules to a Grails application

If you’re a Grails developer then once you’ve found a Groovy extension module you’ll want to include it into your Grails application. If the library is available through Maven or Grapes then it’s easy to include. If you only have the jar then you’ll probably have more difficulty.

I found this question on StackOverflow to have good information on the changes you’ll have to make to have the library included in your application.

There is also a Jira ticket for Grails to address the fact that you need to add this code to load such libraries.
Update: Fixed in Grails 2.4.4.

An extension for Groovy Lists – a less strict alternative for first(), last(), etc.

A follow-on from my earlier post An extension for Groovy Lists – getting the only element of a List

A common use case (for me, at least)

I have often found myself with cases where I want to try to get an element from a list knowing that the later code will behave as expected, regardless of whether the element was present or not. An example of this:

if (!playersStillToPlay.isEmpty()) {
    currentPlayer = playersStillToPlay.head()
    playersStillToPlay = playersStillToPlay.tail()
}
else {
    currentPlayer = null  // Needs to be null if playersStillToPlay was an empty list
                          // If playersStillToPlay was empty it doesn't matter what playersStillToPlay is after this point so I don't change it
}

if (currentPlayer) {
    // Do the things
    // Use value of playersStillToPlay
}

To suit this type of situation I wanted versions of first(), last(), etc. which were Continue reading