Wednesday, October 28, 2009

A good article on the problems in the Finnish startup environment

Finland is Missing the Bowling Alley or How to Find the First Pin

The linked article discusses well why it is hard for Finnish software startups to become major worldwide players.

Tuesday, October 27, 2009

A correct implementation for the 'halts' function in the Buddhist context

Yields a correct answer for all programs P.
halts P = 無

Monday, October 26, 2009

Flu^3

We all have noticed the mass media hysteria around 'swine flu'. Give it a cool name and it feels more dangerous. Make it dangerous and sell more papers. Were there a high profile war going on, the press would have other things in mind. Now it is the flu, however.

What a coincidence that I just got my third flu virus infection this month only. Normally I get flu once/twice a year. Haven't caught the SWINE (it intimidates more in caps, doesn't it) version yet, though - so they say. I'm going to write to Guinness if I get my fourth infection.

All this even though I use Linux.

Sunday, October 25, 2009

Feynman on the feeling of inadequacy

The linked quote is great, well worth linking!

You have no responsibility to live up to it!

Saturday, October 24, 2009

Book: Founders at Work

I'm only halfway reading Jessica Livingston's Founders at Work - stories of startups' early days, but I can already say that this will be one of the top books I have read this year.

Did you know that Yahoo, then already one of the biggest sites in the world, was running on diesel fuel for several days during a power outage?

Friday, October 23, 2009

New startup and a word about types

It's been a while. I joined a new tech startup in Helsinki and have had no time to write to my blog. But I'm always returning! See?

My summer adventures at TKK went smoothly and I'm happy that I had the opportunity to work in a very interesting project and enhance my C/C++ skills there. Now I'm writing mostly Python and it feels great after months of C, almost like if somebody just imported antigravity. I have to admit, I have long been a strong proponent of explicit typing as it is a form of self-documentation, but when you just need to build something quickly, as in startups, explicit types are simply slowing you down. I need to add that I'd still love static typing, something Python does not offer.

Days are already dark in Helsinki and it's getting cold. Now we have to face six months of darkness, which is always so... intriguing. I have always wondered though how quickly it passes. Now that I have Python with me, the spring will surely return in no time.

Have you ever wondered why your relatives are always asking for your help with computers? It's not that they are stupid, but the computers are still way too difficult to use. That's going to change in the next decade(s). I bet the whole platonic idea of the computer is going to change. It'll be more like that everything is a computer, and we will start calling these devices something else that more accurately describes their function.

Wednesday, September 9, 2009

Adding a license text to a set of files using sed

The problem: I needed to add (prepend) a license text to a set of source files.

I thought sed might be a good tool for this task. Having not done anything but trivial sed scripts in the past, I took a look in the web for advice.

I was faced with the following script (I already lost the original URL, I'm sorry):


1{h; r [file]
D;}
2{x; G; }



It needs some explaining. Sed works by maintaining two data buffers: the pattern space and the hold space. A sed execution cycle is performed for each input line. First the input line is placed in the pattern space. Then the commands are (conditionally) executed. Finally, the contents of the pattern space are printed to stdout (if not explicitly prevented). The hold space maintains its contents between two cycles. The pattern space on the other hand is cleared between two cycles.

The GNU sed manual explains the used commands as follows.

h - "Replace the contents of the hold space with the contents of the pattern space."

r [file] - "Queue the contents of filename to be read and inserted into the output stream at the end of the current cycle, or when the next input line is read. Note that if filename cannot be read, it is treated as if it were an empty file, without any error indication."

D - "Delete text in the pattern space up to the first newline. If any text is left, restart cycle with the resultant pattern space (without reading a new line of input), otherwise start a normal new cycle."

x - "Exchange the contents of the hold and pattern spaces."

G - "Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space. "


So the program is performing the job as follows. The first set of commands is executed only for the first line of the input. The first line is copied to the hold buffer. After that, the file [file] is queued to be printed to stderr in the end of the current cycle. Finally, the contents of the pattern space is deleted (so that the first line won't be printed just yet).

Now the file [file] (containing the license text) has been printed. Nothing else has been printed. Also, the first line has been saved to the hold space. Looks good. The second set of commands do the rest. These commands are executed for the second line of the input only. First the contents of the hold space and the pattern space are switched. Now the hold space contains the second line of the input and the pattern space contains the first line of the input. Now a newline and the contents of the hold space are appended to the pattern space. The pattern space now contains the first two lines of the input in correct order. Next, the cycle ends and the contents of the pattern space are printed.

No commands are executed for the remaining lines of the input. They are just printed by default. We have printed the license text, the first line of the input, the second line of the input and the rest of the input in correct order - effectively prepending the license text on the input files.

Now considering the license text is located at /tmp/license, the following code is exactly what is needed to do the job for each *.c and *.h files in the current directory.


sed -i '1{h; r /tmp/license
D;}
2{x; G; }' *.[ch]