Root shell or no root shell?

I'm developing a program which has to run with root privileges (e.g. to be able to execute mlock()). It's boring to su to root shell all the time, so I opened a terminal with root constantly logged on. Sometimes I type faster then I think, so to protect myself from typing the wrong thing into the wrong window, I executed unset PATH in the root shell. Now the root can't "accidentaly" execute anything. :)



Applied algebra

Today I faced a problem: how to generate a pseudo-random permutation of numbers in range [0,2^128), such that each number appears exactly once. An obvious solution is to initialize an array A[i]=i and then shuffle elements with repeated calls to random(). However, that would use a large amount of memory, which is not acceptable in this particular case.

So I remembered a bit of algebra that I learned long time ago at the university. It's about cyclic groups. Consider the sequence k*a0 % M for k = 0, 1, .... In my case M=2^128. This sequence generates all numbers less than M exactly once, provided that a0 and M are relatively prime. Shortly, a0 is a generator of an additive cyclic group where the set of elements are natural numbers in the range G=[0,2^128), and the operation is addition modulo M.

The code is even simpler (pseudo-C):

a = 0;
do {
/* use a in some way */
a += a0;
if(a > M) a -= M;
} while(a);

When a becomes 0 again, the whole group of M elements has been generated, so the loop exits. In other words, a has cycled through all elements in G exactly once. This is also connected with pseudo-random number generators. I'm not interested in the exact statistical properties of generated numbers; the only requirement is that consecutive numbers are "far enough" apart (which I define by chosing an appropriate constant a0).




I had the opportunity to talk on IRC with the programmer of this fractal generator. In the course of discussion, I came to the following idea: program the GPU to calculate mandelbrot zoom animation in real-time and set that animation as the desktop wallpaper. It'd be the coolest desktop ever seen (IMHO, much cooler than the current xgl hype). I believe that current GPUs are powerful enough to perform this task.

Of course, the most fun part would be GPU programming.



GPL vs. the world

After having participated in a debate around GPL, I decided that it's about the time to change licensing on two of my SW projects: hashed text utilities, and secure password generator. I have changed it from the GPL to the MIT/X license. I can't change licensing of the Raster Alchemy project since it was GPL'd to begin with.

I don't agree with the concept of "freedom" that GPL advocates are spreading around. There is no freedom where exists a must. (I'm referring to the viral nature of the GPL). An interesting view on the matter is this article.



Decent calculator

For a long time i have been looking for a decent scientific calculator to use on my computer. Apart from the ordinary capabilities, I need binary arithmetic (binary, decimal, octal and hexadecimal input/output) with usual logic operators. And it'd be nice if it were stack-oriented (RPN, as HP48 calculators).

Today I was programming something and I wished I had my HP48 with me. I couldn't find anything decent on the web, so I set to try the emacs calc. And there it was, with all the features I needed.



Tea in coffee

Have you ever wondered about the result of putting a teabag (and letting it stay for a while) into hot coffee? How would it taste like?



On commercial SW

I have discovered a down-side of commercial software: I have an installation of Mathematica 5.2. After recompiling my Linux kernel (I just added the ethernet driver in the kernel), my "machine ID" changed and I had to request a new license from Wolfram Research. It was relatively painless to get a new license code (this time!). At best, this relicensing is a minor nuisance, but at its worst, the Wolfram research might get suspicious and make it very hard for me to get a new license in the future (if I do it too often). So now it seems that I'm stuck with Linux 2.6.12 kernel in its current configuration.

Does anyone have more experience with Wolfram and "system transfer requests"?



TODO lists

Based on an admittedly small observation sample, I think that people who maintain TODO lists have much less "free time" than people who don't. Some even maintain their TODO lists in the lack of other work.

Personally, I don't maintain a TODO list, and I manage to finish all my work in time, and there's also some time left to have fun :) I do maintain a (small) text file named "TODO", but it contains very low-priority stuff, which can be done anytime (tomorrow or in a year; doesn't matter). And all of the things there are longer-lasting things (e.g. reading a book). It should really be called "REMINDERS" instead of "TODO, but "TODO" is shorter :).

Your opinion?



A bit on Java

I've read this excellent short essay. The thing that I disagree with is the following quote praising Java: "No more bounds errors, no more core dumps." This is a moot point after I've seen many Java programs printing NullPointerException on their stderr and continuing to run.

The key question is: how can you be sure that the program recovered to internally consistent state after such exception? Printing of such exception clearly indicates a bug somewhere. I'd rather have such a program crash (the sooner the better) than continue to run and producing possibly garbage results, and maybe storing them in some files or in database.

What do you think?



"Smart" x86 design

Modern x86 processors (Athlon, Pentium4) have split L1 data and instruction caches. What I'm trying to accomplish is that instructions are fetched from the L1 cache (the code is small enough to fit in), but that data fetches bypass the cache hierarchy and directly access memory. Even the code currently being executed from the L1 instruction cache should be read directly from memory if accessed by a memory-referencing instruction. (There are no writes, just reads).

This seems impossible to achieve on the AMD/Intel architecture. I tried several combinations with CR0.CD and MTRR settings and I can have one of the two extremes: 1) both code and data are served from the cache if found there, or 2) both code and data read directly from memory (and this includes every instruction executed).

How smart do you have to be to split L1 I&D caches, but not to provide separate control over them?