Skip to main content

Ralsina.Me — Roberto Alsina's website

Refreshed rst-cheatsheet

A while ago, I cre­at­ed a 2-­page PDF ver­sion of the re­struc­tured text quick­start meant to be print­ed, fold­ed in half and kept handy un­til you fi­nal­ly re­mem­ber how to do foot­notes (10 years and still wait­ing, in my case).

It was brought to my at­ten­tion that the github project did not men­tion how to build it. Then I no­ticed that not on­ly it did­n't ex­plain that, it was al­so miss­ing crit­i­cal files.

So, I added the files, fixed a cou­ple of things that were not work­ing per­fect­ly with the lat­est rst2pdf and there is now a fresh PDF ready for you!

Nikola Can Parse That

Just for com­plete­ness' sake I have gone over Wikipedi­a's list of light­weight markup lan­guages and added sup­port in Niko­la (a stat­ic site and blog gen­er­a­tor) for a cou­ple of them: BB­Code and tx­t2­tags, which brings the num­ber of sup­port­ed markup for­mats to 7 (the oth­ers are re­Struc­tured tex­t, mark­down, HTM­L, tex­tile and Wik­i).

Of the list of markup lan­guages, the on­ly miss­ing ones with a Python im­ple­men­ta­tion are Asci­iDoc and Mark­down Ex­tra.

Why both­er with this? It's not as if there was some­one ask­ing for BB­Code sup­port. How­ev­er, one of the us­es I want to sup­port is ar­chiv­ing sites. Sup­pose you have a fo­rum you want to shut down? I want you to be able to ar­chive it (even if it's some work) and keep the da­ta out there. A wik­i? Same thing.

This is a first step in that di­rec­tion.

Make Me Talk

One of the things that have helped me be less shy and thus have helped me move for­ward in life is speak­ing in pub­lic. How­ev­er, I have been speak­ing in pub­lic very lit­tle these last cou­ple of years.

So, make me do it more. I am look­ing for­ward to speak­ing in places I haven't been. If it's not hor­ri­bly far from Buenos Aires, I may not even ask you to pay for my trip and/or hotel, I will pay for it my­self if the event is in­ter­est­ing or the place looks like a fun place to trav­el to.

I can speak about python, free soft­ware in gen­er­al or oth­er things you may sug­gest, and I can do it in span­ish or in eng­lish.

Mardel->Retiro->San Isidro->Ezeiza->Dallas->San Francisco

I am at a Canon­i­cal thing in San Ma­teo (right next to San Fran­cis­co). Ar­rived yes­ter­day, and have my last free day to­day, so I need to get some sight­see­ing done.

For starter­s, here's the trip gallery, not very full yet but go­ing to post the as I get them.

But the trip...

I was in Mar del Pla­ta vis­it­ing fam­i­ly on thurs­day, and had tick­ets for Buenos Aires at mid­night. At 9 PM... long dis­tance driv­ers strike. All bus­es sus­pend­ed. Ran to the train sta­tion to see if there was a chance of get­ting one: no tick­ets for a week. Se­ri­ous­ly con­sid­er­ing a 500KM taxi ride.

At 11P­M... strike sus­pend­ed! So, get the fam­i­ly, get the bags, get on the bus... no, sor­ry, you can't get on the bus be­cause you are an id­iot and you bought them for the wrong day. Re­al­ly, I bought tick­ets for thurs­day 00:05 not fri­day 00:05.

In a busy va­ca­tion town, at mid­night, with­out tick­et­s... ok, so we bought new tick­ets for 15 min­utes lat­er. If it's a prob­lem you can fix with a giv­en amount of oney, at least that puts a cer­tain val­ue on how uch of a mo­ron yours tru­ly is. I am about 120 dol­lars worth of mo­ron.

So, new tick­et­s. but they are not (of course) tick­ets to where I live, they are tick­ets for BUenos Aires Re­tiro bus sta­tion, which is about 25KM away from home.

So, at 00:30 we get on the bus, at 5:45 we are at re­tiro, at 6:00 we are on a car, at 6:45 we are at home. At 7:00 I am asleep. At 9:00 I am awake and ready for work!

I work in­ter­mit­tent­ly while pack­ing bags and such, at 5:30PM am on a car to Ezeiza (35km ride). When we are en­ter­ing the air­port, smoke starts com­ing out of the AC (did I men­tion that the AC was bro­ken and it's rough­ly 1.5 hours in bad traf­fic in 30C, un­der the sun, to get to the air­port? I should have!).

So, ap­par­ent­ly the car is on fire, but just a lit­tle bit, the smoke goes away, I get off the car, meet Lu­cio, we do our check­in, I have a cup of cof­fee, at 10:00 PM I am on the plane.

But we have to wait 30 min­utes in the run­way be­cause of traf­fic. Al­so, the cap­tain men­tions that this is the plane's last flight be­cause it's too old and is be­ing sold for scrap. So we are fly­ing in scrap. Al­so, half the screens don't work, it has a whoop­ing 6 movies you can watch, and ... they have spe­cif­ic start­ing times. Yes, you say "hey, I feel like atch­ing Tak­en 2!" and you are pre­sent­ed with a nice sign giv­ing you the op­tion of "want to start watch­ing it even though it start­ed 45 min­utes ago, or would you rather wtch it in 63 min­utes?".

This was my first trip in Amer­i­can Air­li­nes, is it al­ways like this?

We ar­rive in Dal­las, go through what it feels like twelve se­cu­ri­ty check­s, cus­toms check­s, den­tal check­s, and we get to the ac­tu­al USo­fA. Then Lu­cio says "OM­FG we don't have the same plane to SF!", but it's just that he's look­ing at the wrong board­ing pass.

So, to get to our plane, we get on the mono­rail, and go to the ex­act op­po­site end of the air­port, and we get in the plane with 5 min­utes to spare. Since I missed din­ner in the pre­vi­ous flight be­ing asleep, and break­fast was ab­so­lute­ly pa­thet­ic, and the new flight (a 3:50 hours one) in­cludes no meal­s, I get an ap­ple frit­ter from Dunkin Donut­s.

Oh, ap­ple frit­ter. I don't know if you re­al­ly are this de­li­cious, or I am just so hun­gry, but I loved you. You were so sweet and smooth, so sug­ary and ap­ple-y, your tex­ture so nice and your size so huge. I did love you, ap­ple frit­ter. Even if I sus­pect you gave me food poi­son­ing, it was all worth it. I'll al­ways re­mem­ber you.

So, we get on a 757 which is com­plete­ly filthy. I sus­pect the rea­son it does­n't fall apart is the willpow­er of the bazil­lion dust mites that make a liv­ing in the rat­ty seat­s. It has 14" CRT screens ev­ery few rows, and the view out the win­dow is amaz­ing, so I de­cide to look out in­stead.

We get to the air­port and we took the mono­rail, and got to pick our rental car. Giv­en the choice, of course I picked a Blue Nis­san Ver­sa! Good Car!

http://heroeswiki.com/images/thumb/b/b2/Nissan_versa.jpg/250px-Nissan_versa.jpg

I know noone re­mem­ber­s, but He­roes 1st sea­son was kin­da cool.

We have to get to our Seg­way tour in 2.5 hours. So we skip the hotel, put the suit­cas­es in the trunk, and head to Fish­er­man's Whar­f. We park, have a meal, walk there, are ear­ly, get a cup of cof­fee, get on the seg­ways, and had a ton of fun.

//ralsina.me/galleries/san_francisco_2013/P1010162.JPG

That's Al­ca­traz in the back, that's two nerds hav­ing un in the fron­t.

Af­ter we were done, we saw the sea li­ons at Pier 39, got a cup of cof­fee and a cheese sand­wich, and got back on the car, with the idea of go­ing back. Of course we did­n't ac­tu­al­ly have GP­S, or a phone that worked in the US, but we had cached map­s! And a vague idea of where the ho­tel was! So we even­tu­al­ly got there, got in­to the room, got in­to the in­ter­net, called the fam­i­ly, and I passed out of ex­haus­tion at rough;y mid­night Ar­gen­tine time, two days af­ter I got on the bus in Mar del Pla­ta.

And then I woke up, and wrote this.

Adding Support for a Markup to Nikola

One of the goals for Niko­la, my stat­ic site/blog gen­er­a­tor is that it should be easy to ex­tend. For ex­am­ple, to­day I added sup­port for two markup­s: tex­tile and Cre­oleWi­ki.

Since Niko­la al­ready sup­port­ed HTM­L, re­Struc­tured­Text and Mark­down, adding a cou­ple more is not very dif­fi­cult. Here's how:

  1. Cre­ate a .plug­in file like this one:

[Core]
Name = textile
Module = compile_textile

[Documentation]
Author = Roberto Alsina
Version = 0.1
Website = http://nikola.ralsina.me
Description = Compile Textile into HTML

Then you need to cre­ate a python mod­ule called (in this case) com­pile_­tex­tile.py

That file is boil­er­plate plus two meth­od­s, com­pile_html and cre­ate_­post

The com­pile_html method takes two ar­gu­ments, one file from which it reads the markup, and one to write HTM­L. Ex­am­ple:

def compile_html(self, source, dest):
    if textile is None:
        raise Exception('To build this site, you need to install the "textile" package.')
    try:
        os.makedirs(os.path.dirname(dest))
    except:
        pass
    with codecs.open(dest, "w+", "utf8") as out_file:
        with codecs.open(source, "r", "utf8") as in_file:
            data = in_file.read()
        output = textile(data, head_offset=1)
        out_file.write(output)

Make sure to use ut­f8 ev­ery­here.

The cre­ate_­post func­tion is used to cre­ate a new, emp­ty, post with some meta­da­ta in it. Ex­am­ple:

def create_post(self, path, onefile=False, title="", slug="", date="", tags=""):
    with codecs.open(path, "wb+", "utf8") as fd:
        if onefile:
            fd.write('<notextile>  <!--\n')
            fd.write('.. title: %s\n' % title)
            fd.write('.. slug: %s\n' % slug)
            fd.write('.. date: %s\n' % date)
            fd.write('.. tags: %s\n' % tags)
            fd.write('.. link: \n')
            fd.write('.. description: \n')
            fd.write('--></notextile>\n\n')
        fd.write("\nWrite your post here.")

The meta­da­ta has to be in the form ".. field­name: field­val­ue" and usu­al­ly needs to be wrapped in a com­ment so that it's not shown in the out­put.

The one­file pa­ram­e­ter means you have to write that meta­da­ta in the post. If it's False, you don't.

In some rare cas­es (Cre­ole, I am look­ing at you) com­ments are not sup­port­ed and you should raise an ex­cep­tion if one­file is True.

And that's it, markup sup­port is fair­ly easy to add as long as there is a python im­ple­men­ta­tion of a func­tion to con­vert markup in­to htm­l.


Contents © 2000-2023 Roberto Alsina