Sunday, March 28, 2010

Shell knowledge contest: report

Shell knowledge contest is over!

At the last minute it turned out that projector for displaying slides was not available. We worked around this by retranslating slides on several participants' personal netbooks (which was a very good idea, worth remembering). I generated two sets of slides, one with an answer slide after each question slide (for displaying on my laptop) and one without answers for displaying on participants' netbooks, so that an answer could not be revealed (intentionally or not) too early.

Slides (questions+answers, 20 of them) are available, so you can try to answer the questions yourself. They are in Russian, but the essential part is the shell code, whose output or effect you need to predict, and the answers. If there is some demand I could translate them to English completely.

There were two leaders, Evgeniy Berkovich and Yuriy Chumak, who gave 7 right answers. To determine the winner I used a set of additional questions about which function definitions are valid, and Yuriy Chumak won.

For me, the funniest question was the following one (#16, translated to English): what is the output of the following shell script?

f () { echo "The ambulance phone number is $13"; }
f `seq 0 12`

Anyone without any knowledge of shell scripting could suppose that the answer is 03 or 103 (103 is used for the calls from mobile phones), but nobody gave the correct answer!

But in general the level of shell knowledge was higher than I expected, for almost all questions (except 1 or 2) there was at least one correct answer.

Some links to other people's impressions (in Russian):

Thanks to all who participated!

Wednesday, March 24, 2010

Announce: Shell knowledge contest

When: This Saturday, March 27. We meet at 15.00 and event starts at 16.00

Where: Ukraine, Odessa, Bazarnaya str. 2. See foss-fest.com.

What: A contest on Shell scripting knowledge.

In what form: I give you some code, you tell me what it does. Seems easy, huh?

Why: Even if you don't win, you'll definitely find a lot of surprising (and maybe even useful) things about the plain old UNIX Shell.

Registration: yes, please

Note: The contest will be a part of FOSS Fest. I'm not organizing it, so things like time or venue might change — better check the site.

Monday, March 22, 2010

Zurihac: some critique

Zurihac, a Haskell hackathon hosted this time in Zurich by Google, has just ended. This was the biggest Haskell hackathon so far, bringing together over 80 hackers from Europe and nearby continents.

Here are some links:

No doubt organization of such event is a great work, and we all are grateful to organizers for Zurihac becoming reality. But still I'd like to highlight some things which IMO were not thought out enough. Hopefully this list will be useful for future Hackathons organizers.

  • Accomodation Joachim Breitner wrote:
    ok, there seems to be a relatively large number of people staying at the Backpackers. Maybe we can arrange with the hostel that they know about this conference. Then we can register individually and they can just put us together in rooms? Might be more efficient that finding groups of four ourselves. Maybe the local team can talk to them and put information about that on the wiki?
    Unfortunately, this wasn't done.
  • Food There were two issues.

    First, it was too many of us to fit into one restaurant. What could be done: make a wiki page; list some nearby restaurants; make people organize themselves more or less uniformly. What was done: we were just told not to go altogether to the one place.

    Another problem: some (most?) of the restaurants were closed on Sunday. I believe that it might be easier just to call nearby restaurants and find out which are open; then repeat the procedure described above. In contrast, we were told «go there; and if it is closed, well, go somewhere else»

  • Power plugs It was a surprise for most of us that Switzerland has different powerplugs than the rest of Europe. Fortunately, the issue was resolved (personally I thank Simon Meier for lending a cable), but it would nice if we knew about problem in advance. (For instance, organizers of Utrecht hackathon last year kindly reminded us of the possible problems).
  • Duration This hackathon was almost twice as short as the Utrecht one (20 hours against 36 last year).
  • Talks For some reason, talks and demos were postponed to the Sunday evening (they were scheduled for 16.30 and if I recall correctly began around 17.00. As a result, people who had to leave early (due to their flights/trains) missed the talks.
  • Registration This one is not addressed to organizators directly, but rather to attendees. At the moment there are only 57 attendees on the wiki. It's only about 70% of the total number of registered participants. I'd like that coverage to be bigger.

So, once again — Hackathon is held, code is written and talks are given. Only these little things, when done, make a nice feeling that you are cared for. So please, next time, try to do them ;-)

It would be also interesting to hear other opinions from attendees and organizers.

Sunday, March 14, 2010

Sharing the budget with hledger

This time I'd like to tell you how we use hledger in our small family. Here I'll present our experience in question/answer form.

  1. How to make ledger file accessible by different users?

    First, choose a location for the ledger file. According to FHS it probably belongs somewhere in /var. For ourselves I just chose to place it in my home directory.

    Then, for hledger to find your ledger file, just set the environment variable LEDGER to the location chosen. E.g. append

    export LEDGER=~you/.ledger
    

    to the /etc/profile. If you chose to place ledger file in your home, make sure that other users have permissions to access them. Like:

    chgrp users ~you ~you/.ledger
    chmod g+x ~you
    chmod g+r ~you/.ledger
    
  2. How to organize accounts?

    The overall account structure won't be much different from what you'd use without sharing. However, for each account you have to decide whether to make it shared or per-user. For example, some expenses are shared (such as house-keeping expenses) and some may be not (differentiating transport expenses may give an evidence about how much everybody spends on that).

    Shared accounts will have the usual form Expenses:Taxes and per-user ones will have the form Expenses:Transport:Leonard, Expenses:Transport:Sheldon etc.

    In our case, we only divide (for obvious reasons) the «wallet» account which tracks the cash one carries with himself.

    In general, some support for shared/differentiated accounts could be built in hledger itself, but we still can solve many problems, see below.

  3. Our transactions interfere when finding similar transactions.

    Ours did too! Until I came up with the patch (now merged into the main repository) which allows filtering relevant transactions by account.

    To demonstrate the problem, suppose my wife has just ended entering her transactions. Among others was:

    2010/02/26 tansport
        Expenses:Transport       20
        Assets:Wallet:Maria
    

    Now I'm going to enter my transactions. Among others there is similar transaction for my transportation, but it differs in the second account, it is Assets:Wallet:Roman. Of course, hledger doesn't know about this, so it suggest Maria's transaction for me as a template and I have to enter the correct account manually.

    As a workaround for this with the patch mentioned above you can invoke hledger add with additional parameter -- filter for relevant transaction. For example, I will invoke hledger as hledger add Roman which will result in the correct template transaction.

    To automate this, you can add to your ~/.profile the following code:

    function hledger
    {
        HLEDGER=/usr/local/bin/hledger
        case "$1" in
            add)
                shift
                $HLEDGER add Roman "$@";;
            *)
                $HLEDGER "$@" ;;
        esac
    }
    

    This works for us because almost every transaction involves wallet account. In a different workflow this may work not so well (because some transactions may not involve any of the differentiated accounts). In some sense this is a hack caused by hledger not making distinction between shared and diffirentiated account.

  4. How to achieve consistency in using ledger?

    By the definition of the ledger file format, hledger does not and cannot force you to explicitly create account before using it. Thus nothing prevent you (or other users) from making a typo or just using different account names -- for instance you use Expenses:Transport:Subway but your wife uses Expenses:Subway. If you are aware of this, it can be easily corrected using sed (thanks to simple ledger format), but it is usually difficult to spot.

    That's why I added a new option, --no-new-accounts (now in the main repo), which makes hledger add not to accept new accounts, i.e. accounts which are not yet present in ledger file. This is of course not a guarantee (users already have access to ledger file, so they can do whatever they want) but a good measure.

    Thus, for other users you can add to their ~/.profile the following definition:

    function hledger
    {
        HLEDGER=/usr/local/bin/hledger
        case "$1" in
            add)
                shift
                $HLEDGER add Maria --no-new-accounts "$@";;
            *)
                $HLEDGER "$@" ;;
        esac
    }
    

    You can also use this option by default for yourself, turning it off in the rare cases when you really want to add a new account.