Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Templates that create templates...

... or why flex­i­bilty is good some­times.

Af­ter some dab­bling with Lurk­er, I de­cid­ed it's just too much trou­ble for the pro­to­type site and went look­ing for al­ter­na­tive mail­ing list archiver­s.

I found few, and de­cid­ed to try MHonArc.

Then I tried to make it fit the rest of the site. Ouch.

It's not that MHonArc does­n't pro­vide a way to cus­tom­ize the gen­er­at­ed HTM­L. It pro­vides one.

A ter­ri­bly con­vo­lut­ed one where in­stead of writ­ing a tem­plate for MHonArc to fill it has its tem­plate and it's filled from the da­ta and from a re­source file you write.

For ex­am­ple, I ex­pect­ed writ­ing a tem­plate like this (s­tupid ex­am­ple):

<h1> my archives </h1>
${toolbar}
${contents}

So that MHonArc would put a tool­bar and the con­tents where I tell it to.

In re­al­i­ty, MHonArc has a hard­cod­ed tem­plate like this:

IDXPGSSMARKUP
IDXPGBEGIN
    LISTBEGIN
        (AUTHORBEGIN |
         DAYBEGIN |
         SUBJECTBEGIN)?
        LITEMPLATE+
        (AUTHOREND |
         DAYEND |
         SUBJECTEND)?
     LISTEND
    DOC?
IDXPGEND

And you tell it what IDXP­GEND should be, or it us­es its de­fault val­ue. And there is one of these things, with sim­i­lar but dif­fer­ent vari­ables, for each kind of page it gen­er­ates.

So, you can cus­tom­ize your lay­out by putting things like this in a re­source file:

<IdxPgEnd>
$MY-FOOTER-LINK$
</body>
</html>
</IdxPgEnd>

Which is doable. But you end with stat­ic pages. How can you make that work well with a mod­ern site with­out du­pli­cat­ing the whole base lay­out? Not to men­tion all the niceties like hav­ing your user­name in the tool­bar and what­ev­er.

Gen­er­ate page tem­plates in­stead.

I cus­tom­ized the MHonArc lay­out to gen­er­ate neat Mako tem­plates that in­her­it the "re­al" base lay­out tem­plate.

I on­ly had to be care­ful to es­cape the $ signs as $$ if I want­ed them to sur­vive un­til Mako saw them.

Then cre­ate a view that pro­cess­es the tem­plates in­stead of serv­ing the stat­ic files and it works like a char­m.

A sim­ple, but neat hack­let, I think.

Everything is still around

For a project I am do­ing for one of my cus­tomer­s, I need­ed a mail­ing list ar­chive. I looked, and it seems the nicer one is Lurk­er.

Sad­ly, there are no RPM pack­ages, so I had to build it man­u­al­ly... and ran in­to mimelib. Which, look­ing closer, is the same mimelib from Doug Saud­er I used in KRN back in the late 90s.

And which I had a hand in GPLing, too. And it's still in use. One of the things I al­ways liked about FLOSS: noth­ing ev­er re­al­ly gets thrown away.

The Shadow of the Lion (Heirs of Alexandria, #1)

Cover for The Shadow of the Lion (Heirs of Alexandria, #1)

Review:

An in­ter­est­ing al­ter­na­tive his­to­ry idea, where mag­ic works and re­li­gion is ac­tu­al­ly true, even if not ex­act­ly sim­i­lar to what we know to­day, and a rec­og­niz­able world.

I liked the sec­ond part bet­ter, but this is not bad at al­l.

New library: ChipScene

This is the re­al out­come of my Py­Week fail­ure: a neat li­brary.

Take Chip­munk and Qt mash them up, and what do you get?

A OpenGL-ac­cel­er­at­ed, mul­ti­plat­for­m, easy-­to-use play­ground!

But watch the sil­ly video that shows no in­ter­est­ing fea­tures in­stead:

You can't see it but there are 29 bal­loon­s, num­bered, that bounce around hap­pi­ly.

Per­for­mance in the video sucks be­cause I had to dis­able OpenGL in or­der to cap­ture it cor­rect­ly (and video record­ing kills my note­book,any­way). That de­mo nor­mal­ly runs in 3 sec­ond­s, not 57.

Here's the non-boil­er­plate code for that de­mo:

def fillWorld(scene):
  items=[]
  for x in range(1, 29):
      b=cs.CPBodyItem(bpos=[0+13*random.randint(0,25), -50-30*random.randint(0,10)],m=10)
      s=cs.CPCircleShapeItem(10, b, e=.5, offset=[0, 0])
      t=QtGui.QGraphicsSimpleTextItem(str(x), s)
      t.setPos(-5, -5)
      items.append(b)
  items.append(cs.CPSegmentShapeItem([0, 50], [500, 450], 1, None, e=.7))
  items.append(cs.CPSegmentShapeItem([0, 450], [500, 50], 1, None, e=.7))

  for i in items:
      scene.addItem(i)

Neat, is­n't it?

You can get it at the Chip­Scene google code project in­clud­ing, of course, the source.

The unfatomable improbability of my existence.

I am do­ing this as a pub­lic ser­vice for USA read­er­s, be­cause you are like­ly to be in con­tact with some­one who be­lieves evo­lu­tion of life is in­cred­i­bly un­like­ly. Af­ter al­l, many of your pres­i­den­tial can­di­dates don't be­lieve in evo­lu­tion. Which would be sad if it was­n't be­cause I ex­pect some of them do but are afraid of los­ing the ig­no­rant re­li­gious fa­nat­ic vote (which makes it just lame).

You will some­times see some­one say some­thing like "that's un­like­ly!. The odds of A are 1 in 1000 and the odds of B are 1 in 500, so the odds of A and B are 1 in 500000!".

This ar­gu­ment is very, very, very wrong. But for those with an in­tu­itive knowl­edge of prob­a­bil­i­ty it looks good, be­cause they know that the odds of a coin flip com­ing heads is 1/2 and the odds of 2 con­sec­u­tive heads is 1/2 * 1/2 = 1/4 and so on.

Now, let's con­struct me this way (warn­ing: made up num­bers ahead­).

I am ar­gen­tini­an. There's rough­ly 35M ar­gen­tini­ans out of 6000M hu­man­s. That's about 1 in 171.

I am male. That's about 1 in 2.

I am a bit over me­di­an height. That's al­so 1 in 2.

I have a beard. I am guess­ing 1 in 10.

I wear size 41 shoes. That's about 1 in 4.

I use glass­es: I'd say 1 in 5.

I get dizzy rid­ing bus­es: About 1 in 100.

I am mar­ried: 1 in 4.

I have a child: 1 in 2.

I have a son: 1 in 4.

He is 4 months old: 1 in 200

So, I have a 1 in 87 552 000 000 chance of ex­ist­ing. And I could make those odds much low­er. Af­ter al­l, I was born in 1971, mi favourite colour is green and my name is Rober­to.

There are two rea­sons why you should nev­er trust this kind of num­ber ma­nip­u­la­tion un­less you re­al­ly, re­al­ly know what you are do­ing.

  1. You can't just mul­ti­­ply any­thing. These odds have to be about sta­tis­ti­­cal­­ly in­­de­pen­­dent var­i­ables.

For ex­am­ple, I get 1 in 8 from hav­ing a child, and hav­ing a son.

Yes, maybe the odds of some­one hav­ing a child are 1 in 2, and the odds of some­one hav­ing a son is 1 in 4, but those are cor­re­lat­ed. The odds of hav­ing a son if you have a child are about 1 in 2. The odds of hav­ing a child if you have a son are 100% :-)

If two vari­ables are cor­re­lat­ed you can not mul­ti­ply their prob­a­bil­i­ties.

A much sil­li­er ex­am­ple.Imag­ine there are ten coun­tries, each with 1 tenth of the pop­u­la­tion.

The odds of be­ing from A is 1/10. But he is al­so not from B,C,D,E,F,G,H,I, or J! There's a 9/10 chance for each one of those fact­s!

So, the odds of be­ing from A and not fro­many­where else is 1/10 times 9/10 ... that's al­most 1 in 26!

And since the same rea­son­ing ap­plies to each coun­try, it turns out there is al­most a 60% chance the next ba­by will not be born in any one of the ten coun­tries.

See how stupid that sound­s? Of course when cor­re­la­tion is more sub­tle, it's hard­er to fig­ure out, and you will not be able to do this while ar­gu­ing.

  1. Add ran­­dom un­­like­­ly da­­ta.

This is slight­ly trick­ier, be­cause it may be what you re­al­ly want­ed to do. Yes, me be­ing ex­act­ly the way I am is ex­treme­ly un­like­ly. How­ev­er, some­thing more or less like me is not.

Yes, I am un­like­ly but that's triv­ial. How­ev­er, if you are go­ing to ap­ply this kind of rea­son­ing in oth­er cas­es it gets sil­ly quick. Here's an ex­am­ple:

Imag­ine a lot­tery with 6-dig­it num­ber­s. To­day, the win­ner is 123456. Yes­ter­day it was 654321.

The odds of those num­bers be­ing the win­ners is 1 in 1 000 000 000 000. But it's ob­vi­ous that if you make two draws, some two num­bers will come up! And what­ev­er they are, they will be just as un­like­ly!

That some­thing spe­cif­ic is un­like­ly does­n't al­ways mat­ter, be­cause the im­por­tant thing is the chance of some kind of thing hap­pen­ing, not of one spe­cif­ic thing.


And when/if you have a kid,and he/she/it asks you why he should study math, show him his kind of thing and tell him why:

Math makes it hard­er for peo­ple to lie to you.


Contents © 2000-2024 Roberto Alsina