Skip to main content

Ralsina.Me — Roberto Alsina's website

Senses

While walk­ing along the riv­er be­fore dawn I laid down on a bench and looked up, and saw the tree, clear and green against the or­ange clouds in the night sky, and thought, hey, that looks cool, and tried to take a pic­ture.

The screen in my cam­era stayed ob­sti­nate­ly black. I changed set­tings, moved ISOs, touched on dif­fer­ent places try­ing to con­vince it to fo­cus and set aper­ture for the dark­est or the light­est ar­eas of what I knew to be there.

And it re­mained black. And sud­den­ly, I had a dis­sent­ing opin­ion, that there was not a clear green tree there, and that the sky was not full of or­ange cloud­s, but that it was all black, star­less and emp­ty, emp­ty of tree, of cloud.

I placed my hand above the cam­er­a, hop­ing to catch a glim­mer of it, and stil­l, the dis­play was a square of dark­ness sep­a­rat­ing my fin­gers from my ar­m, as emp­ty as be­fore, mock­ing me fea­ture­less.

Why was it so black, if I could see clear­ly. If there were lamp­posts giv­ing light, and I could see clear­ly, and there was a tree. I knew the cam­era worked. What was I do­ing, by the river, at 4AM, on a tues­day, lay­ing on a bench, look­ing up, with a cam­er­a?

You ex­pect your sens­es to work. You ex­pect to per­ceive what is there, and not per­ceive what is not. You ex­pect to see re­al­i­ty, to not see ir­re­al­i­ty, to lis­ten to things, to not lis­ten to un­things, to touch truth, to smell shit.

What would hap­pen if you had two sets of sens­es, two vi­sion­s, and they dis­agreed, and you were not sure which one to trust, which one is right, which one is true? What would hap­pen if the cam­era was right and my eyes were wrong, and I was ac­tu­al­ly not see­ing, but imag­in­ing, and the truth was emp­ty, and the tree was not there, and the sky was black.

Then I en­abled flash, and the ug­ly pic­ture con­vinced me to, some­day, get a bet­ter cam­er­a, and nev­er for­get to take my gas­tri­tis medicine when go­ing for trips on iso­lat­ed lo­ca­tion­s.

Nikola 1.1 is out!

A sim­ple yet pow­er­ful and flex­i­ble stat­ic web­site and blog gen­er­a­tor, based on doit, mako, do­cu­tils and boot­strap.

I built this to pow­er this very site you are read­ing, but de­cid­ed it may be use­ful to oth­er­s. The main goals of Niko­la are:

  • Small code­base: be­­cause I don't want to main­­tain a big thing for my blog

  • Fast page gen­er­a­­tion: Adding a post should not take more that 5 sec­onds to build.

  • Stat­ic out­­put: De­­ploy­­ment us­ing rsync is smooth.

  • Flex­i­ble page gen­er­a­­tion: you can de­­cide where ev­ery­thing goes in the fi­­nal site.

  • Pow­er­­ful tem­­plates: Us­es Mako

  • Clean markup for post­s: Us­es Do­cu­tils

  • Don't do stupid build­s: Us­es doit

  • Clean HTML out­­put by de­­fault: Us­es boot­s­trap

  • Com­­ments out of the box: Us­es Dis­­qus

  • Tags, with their own RSS feeds

  • Easy way to do a blog

  • Stat­ic pages out­­­side the blog

  • Mul­ti­lin­gual blog sup­­port (my own blog is en­g­lish + span­ish)

I think this ini­tial ver­sion achieves all of those goal­s, but of course, it can be im­proved. Feed­back is very wel­come!

Niko­la's home page is cur­rent­ly http://niko­la-­gen­er­a­tor.­google­code.­com

Unicode in Python is Fun!

As I hope you know, if you get a string of bytes, and want the text in it, and that text may be non-asci­i, what you need to do is de­code the string us­ing the cor­rect en­cod­ing name:

>>> 'á'.decode('utf8')
u'\xe1'

How­ev­er, there is a gotcha there. You have to be ab­so­lute­ly sure that the thing you are de­cod­ing is a string of bytes, and not a uni­code ob­jec­t. Be­cause uni­code ob­jects al­so have a de­code method but it's an in­cred­i­bly use­less one, whose on­ly pur­pose in life is caus­ing this pe­cu­liar er­ror:

>>> u'á'.decode('utf8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1'
in position 0: ordinal not in range(128)

Why pe­cu­liar? Be­cause it's an En­code er­ror. Caused by call­ing de­code. You see, on uni­code ob­ject­s, de­code does some­thing like this:

def decode(self, encoding):
    return self.encode('ascii').decode(encoding)

The us­er wants a uni­code ob­jec­t. He has a uni­code ob­jec­t. By def­i­ni­tion, there is no such thing as a way to ut­f-8-de­code a uni­code ob­jec­t. It just makes NO SENSE. It's like ask­ing for a way to comb a fish, or climb a lake.

What it should return is self! Also, it's annoying as all hell in that the only way to avoid it is to check for type, which is totally unpythonic.

Or even bet­ter, let's just not have a de­code method on uni­code ob­ject­s, which I think is the case in python 3, and I know we will nev­er get on python 2.

So, be aware of it, and good luck!

How it's done

I added a very mi­nor fea­ture to the site. Up here ^ you should be able to see a link that says "reSt". If you click on it, it will show you the "source code" for the page.

I did this for a few rea­son­s:

  1. Be­­cause a com­­ment seemed to sug­­gest it ;-)

  2. Be­­cause it seems like a nice thing to do. Since I so like reSt, I would like oth­­ers to use it, too. And show­ing how easy it is to write us­ing it, is cool.

  3. It's the "free soft­­ware-y" thing to do. I am pro­vid­ing you the pre­­ferred way to mod­­i­­fy my post­s.

  4. It was ridicu­lous­­ly easy to ad­d.

Al­so, if you see some­thing miss­ing, or some­thing you would like to have on the site, please com­men­t, I will try to add it.


Contents © 2000-2021 Roberto Alsina