Announcing AtnNn’s Haxball Stadium Editor

No Comments Written by Etienne Laurin on 2011/12/17 in Haxball.

The latest Haxball update added a feature for custom stadiums in a JSON format.

With my new Stadium Editor, there is no more need for coding in JSON.



Features include:

  • A complete graphical interface.
  • The ability to create and modify all the supported shape types.
  • A property editor.
  • Copy/paste.
  • Easy undo.

Features being worked on include:

  • Snapping to grids and other objects.
  • Automatic 2-way or 4-way mirroring.
  • A color picker.



Please send feedback and bug reports as a comment on this post or in the bug tracker.


Writing Haskell Functions With Many Nameless Parameters

No Comments Written by Etienne Laurin on 2011/10/03 in Code.

Although it could be considered bad style, it is often useful to have functions that take a large amount of similar parameters that vary in type. I am going to demonstrate a technique that allows to write such functions without naming these parameters and making the function more readable.

The function I will use for demonstration is an example of a common pattern when working with JSON data.

{-# LANGUAGE UnicodeSyntax, OverloadedStrings #-}

import Data.Aeson
import Data.Aeson.Types
import Data.Text

person  String  Float  Bool  Value
person name height over18 = object [
  "name" .= name,
  "height" .= height,
  "over18" .= over18]

The name of each parameter is repeated three times. Writing many such functions is often done by copying and pasting, which is a red flag and a possible source of errors.

In an attempt to write reusable code, we can define a simple function that builds the result in small steps.

field  ToJSON a  Text  [Pair]  a  [Pair]
field k d v =  (k, toJSON v) : d

The order of the arguments is important because it fits well into the $- combinator. This combinator is the key to the whole exercise. It builds our desired multi-argument function without having to name the arguments.

infixr 3 $-
($-)  (d  a  e)  (e  k)  d  a  k
($-) f g d a = g $ f d a

(Some readers may recognise this relative of the infamous cartoon face operator ((.).(.)))

We can now rewrite the person function.

person'  String  Float  Bool  Value
person' = ($[])
  $  field "name"
  $- field "height"
  $- field "over18"
  $- object

The first part of the function body, ($[]), is the initial value used to build our object. The last part, $- object transforms the list that was built incrementally into the final result.

This technique becomes more powerful when you write other helper functions. For example, we can also have another function that ignores Nothing.

optfield  ToJSON a  Text  [Pair]  Maybe a  [Pair]
optfield k d (Just v) = field k d v
optfield _ d Nothing = d

The $- combinator’s usefulness is not limited to building JSON objects. It can be used to write many functions that need to combine heterogeneous values for which simple utility functions such as field and optfield can be written. Functions written in this style make cleaner, less repetitive code.


EDIT: made the type of $- more general


Siamsa Whistle and Fiddle: Week #3

No Comments Written by Etienne Laurin on 2011/10/03 in Music.

Previous week

Fiddle

We studied the full part A of Love at the Endings.

Whistle

We studied the Chicago reel. We practiced adding extra tonging, for example at the beginning of the tune:

With a possible cut.

We also studied some variations in part. The F♯ seems out of place, so it can be played closer to F♮. It can also be played as a rising roll. And because too many rolls do not always sound nice, they can be replaced.

Our next tune for this week is The Boys of Ballysodare reel. Brian Finnegan plays a fast version of this tune in a set he calls The Highland Fiddle


Siamsa Whistle and Fiddle: Week #2

No Comments Written by Etienne Laurin on 2011/09/23 in Music.

I am taking two classes this semester at the Siamsa School of Irish Music.

Fiddle

With Marc-Antoine in the fiddle class we started learning part A of Love at the Endings, a beautiful reel. The title comes from a play called Purple Dust, in which a man wins the heart of his beloved by promising her “things to say and things to do, and love at the endings”. The Comhaltas Archive has a recording of Ed Reavy, the composer, playing this tune. For this tune we practiced ornaments I had never used in a tune before: a roll on the low F♯ and a few cuts and slides.

My homework for this week: Practice part A with all the ornaments we saw.

Whistle

With Steve in the whistle class we studied a jig and a reel. We put aside the Man of Aran that we had started last week because the off-beat rolls seemed daunting to some.

We played the Jackie Small’s Jig together, a tune I first heard on a recording by Cormac Breatnac on his website, although he calls it the Tailor Small’s. I discovered that it was possible to cut a note immediately after a C♯.

We then learned the first part of the Chicago reel. It is one of the tunes available in the Foinn Seisiún collection. This tune is not as easy as it seems. The F♯ is not always played very sharp. The F♯ can also be rolled in a a weird sort of way by playing an E first and then a short roll on the F♯ (without tonguing). Also, the sequence that goes ecgc acgc should be played either without tonging or by tonging only the four C♯.

My homework for this week:

  • Practice the jig and both reels and the ornaments we saw
  • Practice cutting all notes in my range after a C♯
  • Bonus: try to roll an F♮

Visualise Persist Models Using Graphviz

No Comments Written by Etienne Laurin on 2011/09/14 in Code.

My current project uses the Yesod framework for web development. One of the advantages of Yesod is the Database.Persist library. It has type-checked queries, custom sql representations for types and automatic schema migration with postgresql, sqlite and mongodb support.

Here is a little script I wrote to visualise Persist data models.

persist-graph.hs

{-# LANGUAGE UnicodeSyntax, ViewPatterns #-}

-- usage:
--  persistent-graph < config/models > schema.dot
--  neato schema.dot -Tpdf > schema.pdf

import Database.Persist.Base (EntityDef(..), ColumnDef(..))
import Database.Persist.Quasi (parse)
import Data.List (intersperse)

main = do
  defs  getContents
  let schema = parse defs
  putStr $ convert schema

graphOpts = "node [shape=record]; overlap=false; splines=true;"

convert schema = unlines ["digraph {", graphOpts, unlines $ map entity schema, "}"] 

entity (EntityDef name _ cols _ _) = unlines $ [
  name ++ " [",
  "label=\"{" ++ name  ++ "|" ++
  (concat $ intersperse "|" (map column cols))
  ++ "}\"];"] ++
  map (links name) cols

column (ColumnDef name _ _) = "<" ++ name ++ "> " ++ name

links entity (ColumnDef name typ _) =
  if "dI" == take 2 (reverse typ)
  then entity ++ ":" ++ name ++ " -> " ++ reverse (drop 2 (reverse typ))
  else []

#define true false

One Comment Written by Etienne Laurin on 2011/03/16 in Code.

What is the output of the following C++ program?

#include <iostream>

#define true false
#define false true

int main(){ std::cout << (
        false ? "false" :
        true  ? "true"  :
                "mu"
) << "\n";}


xkcd in Russian

No Comments Written by Etienne Laurin on 2011/01/01 in Language.

Fans have been translating xkcd into russian.

Almost all comics have been translated, complete with title text and transcript for the visually impaired.

I surprised myself reading these, my Russian vocabulary is not as limited as I thought it was. I am still going to be creating Anki flashcards for many words and sentence fragments from these comics.

Notice how Facebook was translated as Вконтакте (Vkontakte). It is not very surprising, considering the popularity of the Facebook look-alike and it’s nice features.


Irish Music History

No Comments Written by Etienne Laurin on 2010/12/28 in Music.

There is a plethora of traditional Irish tunes available online from sources such as youtube or thesession.org. It is hard to find two recordings or transcriptions of the same tune that are actually the same tune. Because there are so many local variations, interchangeable parts and modern adaptations, finding the original version of a tune can be hard. How did the composer want the tune to be played? What notes and ornaments did he or she have in mind?

Danny boy is an example of a song that has a tumultuous history. The lyrics were added to a melody called Londonderry Air, which got its name because it was an untitled tune transcribed by someone from County Londonderry. But the tune did have a name: The Young Man’s Dream. On his website, Michael Robinson reveals the details on the history of this classic air (a fascinating read).

The book A History of Irish Music by William H. Grattan Flood lists most of the earliest collections of irish music from 1725 to 1887. These collections are all public domain.

Some are freely available from the IMSLP in PDF format:

Many other collections are available online on the IMCO but they require a proprietary plugin.

Recordings from the early ⅩⅩ century are also easy to find on the web:

Nothing short of a working time machine will make me hear the original versions of all the songs that were composed before music could be faithfully recorded.  But going through all these early transcriptions and recordings has given me another viewpoint on Irish music. It has also taught me new tunes and some lovely variations.


New Whistles

No Comments Written by Etienne Laurin on 2010/12/05 in Music.

I just added a new set of whistles to my collection!

I ordered them ten days ago from the Irish Whistle Shop. It’s a set of seven nickel-plated whistle bodies, one head and a plastic fipple. There is one body for each key between E (high) and B♭ (low). They were made by David O’Brien, serial number 773.

To give you an idea of how it sounds, here is the Song of the Garden played in the key of D (Source).

I love the sound, it’s very different than the sound I get from my Feadog whistle. The whistles require a little more breath and a lot more pressure. They have a wide bore and are very loud, especially in the second register.

On the Feadog, I have to blow the low E and the high B very softly to get a nice tone, but my new O’Brien in D will let me blow as hard as I want, all the way up to the high D. The Feadog has a breathy, lacking tone on the cross-fingered C♮. The same fingering on the O’Brien D sounds a lot better and it even has a thumb-hole for playing the C♮ perfectly. I play the recorder as well, so the thumb-hole is not a problem for me.

I tried the O’Brien whistle in all the keys I got. They all sound great except for the B♭, which is out of tune with itself harder to play in tune. I suspect I may be able to fix that by using the unusual ajustable window size (also known as embouchure size). Otherwise, The ajustable window size seems like a completely useless feature. Changing it by more than a few milimeters can make the whistle go out of tune or gives a horrible tone to either the first or the second register.

I highly recommend that you check out the Irish Whistle Shop and David O’Brien if you ever want to buy a good quality whistle from nice folks. Overall, my new instrument is now the favourite of my collection. But I am eagerly waiting for a Sindt whistle which is a lot more similar to the Feadog that I am used to playing, but, I believe, will have none of it’s flaws.

I’m editing this post to mention that, although I bought them second-hand, these whistles seem to have never been played before! I’ve owned them for less than a week and there are already large red marks around the finger holes where the nickel has rubbed off, letting the copper show. There was not even a hint of copper around any of the holes when I first received the whistles.


Cheating

No Comments Written by Etienne Laurin on 2010/11/21 in Code, Uncategorized.

I haven’t posted anything here in a long time, so I thought I might share a small log from freenode.


* s0lidnuts has joined ##prolog
< s0lidnuts> Hi. I'd like a commented version of the solution to the 8 queen problem. I do not know prolog nor have time to learn it now (school work). Anyone willing to help please pvt =)
< AtnNn> s0lidnuts: eight_queens([2,4,6,8,3,1,7,5]).
< s0lidnuts> AtnNn that's cheating

Somehow, this made me laugh more than anything else has this past week.