Category: Uncategorized
Hidden PI
The people from Gaussianos.com (spanish blog abouth math) posted a couple of algorithms to calculate Pi and asked readers to provide some more.
I recently read on The Computational Beauty of Nature that Pi is hidden in the Mandelbrot set:
Take the mandelbrot iteration function:
z0 = 0
z = z^2 + c
And the initial complex number:
c = -3/4 + a * i
That set of complex numbers lays just between the two main parts of the body of the set, it is also known as the 'neck' (since it joins the cardiod with the biggest 'head').
For a = 0 the point belongs to the mandelbrot set. Let k be the number of iterations needed for a point (c = -3/4 + a * i) to reach modulus greater than 2 (escape radius), as a approaches to zero, k * a approaches to pi.
I wrote a simple C program that shows this (http://dev.gentoo.org/~ferdy/stuff/pi_mandel_gmp.c). When compiled, linked against libgmp and run, it outputs something like the following:
a || k || aprox. pi --------++-----------++----------- 1 || 3 || 3.0000000 0.1 || 33 || 3.3000000 0.01 || 315 || 3.1500000 0.001 || 3143 || 3.1430000 0.0001 || 31417 || 3.1417000 1e-05 || 314160 || 3.1416000 1e-06 || 3141593 || 3.1415930 1e-07 || 31415927 || 3.1415927
It is an utterly expensive and pointless way to calculate pi, but it is one of the most obscure and weird ways to do it ![]()
Of course, all the credit goes to Dave Boll, who discovered the fact on 1991.
- ferdy
Random Git Stuff
Switching between projects using different SCMs is painful sometimes, and I always fail to remember the branch I'm on in my Git repositories. I use some bashrc/PS1 magic to show some SCM information in my PS1, I thought someone would find it useful: bashrc-scm.
Lately I've been working on RepoDoc whenever I've found a bit of free time. We are using Git as our SCM mainly because it is easy and very flexible and we can follow a pseudo-centralized workflow that probably only suits us :) We faced some problems with it but given the flexibility of Git, fixing them was really easy.
We keep a central repository with one branch per committer plus master. Those are the top-level branches, and not everybody can update every brach, so the traditional Unix filesystem permissions doesn't solve our problem. Then we can create as many temporal branches as we want under the tmp/ directory.
Also, we decided to keep a 'fast-forward only' policy on top-level branches, so everything has to be cooked in temporal branches first and then cleanly merged into top-level branches.
To enforce both policies (permissions and 'fast-forward only') we call a script from the update hook who does all the magic: http://dev.gentoo.org/~ferdy/stuff/enforce-perms. The users-allowed file is something like:
refs/heads/master$ alice bob refs/heads/alice$ alice refs/heads/bob$ bob refs/heads/eve$ eve refs/heads/tmp/ ^ refs/tags/ alice
Today I also decided to hack a CIA bot to send repodoc stats. It was fairly easy since the ciabot.pl included in Cogito did almost everything I wanted. However, being a perl-ignorant I rewrote the whole thing in bash to suit my needs, grab it from http://dev.gentoo.org/~ferdy/stuff/ciabot.bash.
For those with the ability to read or understand some Spanish I wrote a little introduction to Git: http://dev.gentoo.org/~ferdy/git-intro/
I have also been trying to import the gentoo-x86 module into Git without much luck, both parsecvs and git-cvsimport failed, I'll probably try Tailor later. I haven't payed much attention to it anyway, since I'm a bit busy with university stuff. I guess I should seek help in the Git mailing list once I take it seriously.
Oh, and by the way, there is a new Git version in the tree. Go grab it!
- ferdy
PAY, it depends on how do you understand licenses
Hey PAY!
The answer to your question about free licenses depends on how you understand a license. What do you want to do ? protect the work or give rights to your users ?
If you see the license as a way to protect the code itself (the music in this particular case); then there is no way the BY-SA is 'more free' than the BY-NC-SA.
However, some people (me among them) think licenses are meant to give rights to users. With this idea, the BY-SA is far 'more free' than the BY-NC-SA; because the former allows derivatives works not allowed by the latter. Following with this argument you come to the conclusion that the BY is the 'most free' among the CreativeCommons licenses.
Of course thats only my opinion and since IANAL I might be totally off.
Cheers,
Ferdy
... then switch to PostgreSQL
David::, if you can't use MySQL; then try to switch to PostgreSQL. BTW, enjoy with it :)
Simplest bash quine ?
Playing around with some of the new bash-3 features I accidentally found a really simple quine:
[ $ ~ ] cat quine.bash
echo ${BASH_COMMAND}
[ $ ~ ] bash quine.bash
echo ${BASH_COMMAND}
[ $ ~ ]
Of course it only works on bash-3. I don't know if that's 'cheating'... but oh well... it's still interesting heh :)
Cheers,
Ferdy