Skip to main content

Ralsina.Me — Roberto Alsina's website

Rst2pdf 0.16 is out!

Fi­nal­ly, a new re­lease of rst2pdf!

You can get it at its site: http://rst2pdf.­google­code.­com

rst2pdf is a tool to con­vert re­struc­tured text (a light, cool markup lan­guage) to PDF us­ing re­port­lab in­stead of La­TeX.

It has been used for many things, from book­s, to mag­a­zi­nes, to brochures, to man­u­al­s, to web­sites and has lots of fea­tures:

  • Font em­bed­d­ing (T­TF or Type1 fonts)

  • Cas­­cad­ing Stylesheets

  • Ex­treme­­ly flex­i­ble plug­in ar­chi­tec­­ture (y­ou can do things like ren­der the head­­ings from ar­bi­­trary SVG files!)

  • Sphinx in­­te­­gra­­tion.

  • Con­­fig­urable page lay­outs

  • Cus­­tom cov­­er pages via tem­­plates

  • And much, much more...

The big­gest change in 0.16 is sure­ly the im­proved sup­port for Sphinx 1.0.x so if you are us­ing Sphinx, you re­al­ly want this ver­sion.

Al­so, it has a ton of bug­fix­es, and a few mi­nor but use­ful new fea­tures.

Here's the whole changel­og if you don't be­lieve me:

  • Fixed Is­­sue 343: Plugged mem­o­ry leak in the RSON pars­er.

  • Fix for Is­­sue 287: there is still a cor­n­er case if you have two sec­­tions with the same ti­tle, at the same lev­­el, in the same page, in dif­fer­­ent files where the links will break.

  • Fixed Is­­sue 367: ger­­man-lo­­cal­ized dates are MM. DD. YYYY so when used in sphinx's tem­­plate cov­­er they ap­­peared weird, like a list item. Fixed with a mi­nor work­around in the tem­­plate.

  • Fixed Is­­sue 366: links to "#" make no sense on a PDF file

  • Made de­f­i­ni­­tions from de­f­i­ni­­tion lists more sty­lable.

  • Moved de­f­i­ni­­tion lists to Split­­Ta­bles, so you can have very long de­f­i­ni­­tion­s.

  • Fixed Is­­sue 318: Im­­ple­­men­t­ed Do­­main spe­­cif­ic in­­dex­es for Sphinx 1.0.x

  • Fixed In­­dex links when us­ing Sphinx/pdf­builder.

  • Fixed Is­­sue 360: Set lit­er­al.­­word­Wrap to None by de­­fault so it does­n't in­­her­it word­Wrap CJK when you use the oth­­er­­wise cor­rect ja­­pa­­nese set­t­ings. In any case, lit­er­al blocks are not sup­­posed to wrap at al­l.

  • Switched pdf­builder to use Split­­Ta­bles by de­­fault (it made no sense not to do it)

  • Fixed Is­­sue 365: some TTF fonts don't val­i­­date but they work any­way.

  • Set a valid de­­fault baseurl for Sphinx (makes it much faster!)

  • New fea­­ture: --use-num­bered-links to show sec­­tion num­bers in links to sec­­tion­s, like "See sec­­tion 2.3 Ter­mi­­na­­tion"

  • Added stylesheets for land­s­cape pa­per sizes (i.e: a4-­­land­s­cape.style)

  • Fixed Is­­sue 364: Some op­­tions not re­spec­t­ed when passed in per-­­doc op­­tions in sphinx.

  • Fixed Is­­sue 361: mul­ti­­ple line­breaks in line blocks were col­lapsed.

  • Fixed Is­­sue 363: strange char­ac­ters in some cas­es in math di­rec­­tive.

  • Fixed Is­­sue 362: Smarter au­­to-en­­clos­ing of equa­­tions in $...$

  • Fixed Is­­sue 358: --re­al--­­foot­notes de­­faults to False, but help text in­­di­­cates de­­fault is True

  • Fixed Is­­sue 359: Wrong --­­fit-back­­­ground-­­mode help string

  • Fixed Is­­sue 356: mis­s­ing cells if a cell spawns rows and col­umn­s.

  • Fixed Is­­sue 349: Work cor­rec­t­­ly with lan­guages that are avail­able in form aa_bb and not aa (ex­am­­ple: zh_c­n)

  • Fixed Is­­sue 345: give file/­­line in­­­fo when there is an er­ror in a raw PDF di­rec­­tive.

  • Fixed Is­­sue 336: JPEG im­ages should work even with­­out PIL (but give a warn­ing be­­cause sizes will prob­a­bly be wrong)

  • Fixed Is­­sue 351: foot­note/c­i­­ta­­tion re­f­er­ences were gen­er­at­ed in­­­cor­rec­t­­ly, which caused prob­lems if there was a ci­­ta­­tion with the same text as a head­­ing.

  • Fixed Is­­sue 353: bet­ter han­dling of graphviz, so that it works with­­out vec­­tor­pdf but gives a warn­ing about it.

  • Fixed Is­­sue 354: make todo_n­ode from sphinx cus­­tom­iz­a­ble.

  • Fixed bug where nest­ed lists broke page lay­out if the page was smal­l.

  • Smarter --in­­line-links op­­tion

  • New ex­ten­­sion: fan­­cyti­tles, see //ral­si­­na.me/we­blog/­­post­s/B­B906.html

  • New fea­­ture: tab-width op­­tion in code-block di­rec­­tive (de­­faults to 8).

  • Fixed Is­­sue 340: end­notes/­­foot­notes were not styled.

  • Fixed Is­­sue 339: class names us­ing _ were not us­able.

  • Fixed Is­­sue 335: ug­­ly crash when us­ing im­ages in some spe­­cif­ic places (looks like a re­­port­lab bug)

  • Fixed Is­­sue 329: make the fig­ure align­­men­t/­­class at­tributes work more like La­­TeX than HT­M­L.

  • Fixed Is­­sue 328: list item styles were be­ing ig­nored.

  • Fixed Is­­sue 186: new --use-float­ing-im­ages makes im­ages with :align: set work like in HT­M­L, with the next flow­able flow­ing be­­side it.

  • Fixed Is­­sue 307: head­­er/­­foot­er from stylesheet now sup­­ports in­­­line rest markup and sub­­sti­­tu­­tions de­fined in the main doc­u­­men­t.

  • New pdf_­­toc_depth op­­tion for Sphinx/pdf­builder

  • New pdf_use_­­toc op­­tion for Sphinx/pdf­builder

  • Fixed Is­­sue 308: com­­pat­i­­bil­i­­ty with re­­port­lab from SVN

  • Fixed Is­­sue 323: er­rors in the con­­fig.sam­­ple made it work weird.

  • Fixed Is­­sue 322: Im­age sub­­sti­­tu­­tions did­n't work in doc­u­­ment ti­­tle.

  • Im­­ple­­men­t­ed Is­­sue 321: un­der­­line and strikethrough avail­able in stylesheet.

  • Fixed Is­­sue 317: Ug­­ly er­ror mes­sage when file does not ex­ist

People believe anything on the Internet.

I just saw this on a place I won't both­er link­ing:

This oc­to­ber has 5 fri­days, 5 sat­ur­days and 5 sun­days. This hap­pens on­ly ev­ery 823 years. And I am ground­ed all mon­th!

Re­al­ly, it's not worth link­ing to be­cause it's ev­ery­where

There are vari­a­tion­s, of course, 5 sun­day/­mon­day/tues­days, dif­fer­ent month­s, etc.

But why are peo­ple fall­ing for that? I mean, it's pret­ty ob­vi­ous if you think 2 min­utes that there's no way it can be true!

  1. The length of oc­­to­ber is fixed (31 days).

  2. Since weeks are 7 days, you have 4 weeks + 3 days in oc­­to­ber.

  3. If oc­­to­ber starts on a fri­­day, those last three days are go­ing to be fri­­day/sat­ur­­day/­­sun­­day.

So, for this thing to be true, Oc­to­ber 1st would have to be a fri­day on­ly once ev­ery 823 years. Sounds pret­ty stupid when you say it that way, right?

I re­al­ly have no idea how any­one with half a brain can fall for it, but I have seen peo­ple I know have a func­tion­al cor­tex do it. Com­ments en­cour­aged :-)

Como ser un nerd en argentina y no morir en el intento

This is a span­ish-on­ly post, it makes no sense for any en­glish-read­er­s: it's about how to buy elec­tron­ics in Ar­genti­na.


Intro

Ser un nerd en Ar­genti­na tiene mu­chos prob­le­mas. Uno de el­los es que los pre­cios que nos quieren co­brar por casi cualquier chiche elec­tróni­co es ridícu­lo.

Otro de los prob­le­mas es que el 99% de la gente no sabe co­mo hac­er para que no les afa­nen de esa man­er­a. Y ojo, no hablo de con­tra­ban­dear, hablo de us­ar tus dere­chos y tus re­cur­sos legales. Aclaro: no soy abo­gado, si sigu­ien­do es­tos con­se­jos vas pre­so, es cosa tuya, yo di­go lo que creo que es­tá bi­en nomás.

Así que es­ti­ma­dos lec­tores, acá es­tá mi guía para com­prar chich­es sin ten­er que em­peñar un riñón (que tam­bién es ile­gal, ya que es­ta­mos).

Lo primero que nece­sitás es pa­cien­ci­a. Al­gunos de los mecan­is­mos que te voy a con­tar ll­e­van uno o dos meses, o re­quieren co­lab­o­ración de ter­ceros. Pero bueno, so­mos nerd­s, re­solver prob­le­mas es lo nue­stro.

Chucherías Chinas

Ten­go un boni­to mi­cro­sco­pio de bol­sil­lo de 80x que me com­pró mi es­posa. Cos­to? $90. Es un juguete buenísi­mo, re ed­uca­tivo, y cuan­do tenía 6 años hu­biera da­do la fig­u­ri­ta difí­cil (era la tarán­tu­la) por uno de es­tos.

Cos­to en chi­na? U$S 9.39, con en­vío gratis

O sea, la mi­tad. Y co­mo sale menos de U$S 25, de he­cho es le­gal traer­lo por correo y no pagás tasa de ad­u­a­na.

De to­das for­mas, prob­a­ble­mente no ten­gas que ir a la ad­u­a­na porque....

Pero ponéle que pagás la tasa. Con tasa y todo, son U$S 15, o sea $60. Si pasás por la ad­u­a­na a ve­ces y no te mo­les­ta hac­er co­la un ra­to (ll­e­vate un li­bro)....

Pero es aún mejor. Porque en http://DealEx­treme.­com tenés un mod­e­lo de 150x por U$S 12! De he­cho, tenés 36 mod­e­los de mi­cro­sco­pios!

Por ejem­plo, en http://al­iba­ba.­com hay al­go así co­mo 35000 vende­dores de tablets con An­droid. Al­gu­na te va a servir ;-)

Aho­ra bi­en, supong­amos que te de­cidiste y te en­car­gaste al­go de Chi­na o sim­i­lar, qué tenés que saber:

  • Guardá la "fac­­tu­ra" que te dá el sitio, y la URL del pro­­duc­­to.

    La fac­­tu­ra suele ser un HT­M­L, im­primí­­lo. Cuan­­do re­tirás en Ad­u­a­­na lo nece­sitás. No lo muestres de en­­trada! Só­­lo si te lo pi­­den.

  • Andá dis­­puesto a pa­­gar. Es al cuete dis­­cu­tir. Tené en cuen­­ta que aún con lo de la ad­u­a­­na es bara­­to, y no te ha­­gas mala san­­gre.

  • Si vas tipo 10:30 suele haber poca gente.

  • Andá tran­quilo, ll­e­­vate al­­go para en­treten­erte porque en una de esas ll­e­­va un ra­­to. Igual hay sil­las, que se yó, no es la muerte de nadie.

Cómo Pagar

La más fá­cil es Pay­Pal. Si tenés tar­je­ta de crédi­to es triv­ial.

El amigo que viene de afuera

Sí tenés un cono­ci­do que vi­a­ja al ex­te­ri­or con reg­u­lar­i­dad:

  • Podés com­prar en USA y que te re­ci­­ba y traiga las cosas.

  • Has­­ta U$S 300 (si el que vi­a­­ja es ar­­gen­ti­no) no se pa­­ga ad­u­a­­na. Se pa­­ga el 50% por en­ci­­ma de esa cifra.

  • Si es un ex­­tran­­jero que trae una cosa propia "en uso" y te la vende acá, no creo que ten­­gas que pa­­gar im­­portación (no es­­­toy se­guro)

Veamos un ejem­plo!

  • Una HP mi­ni com­pra­­da acá: $1999, o U$S 500

  • Com­pra­­da en US­A: U$S 329.

    • Pa­­­gan­­­do ad­u­a­­­na con fran­qui­­­ci­a: U$S 345

    • Pa­­­gan­­­do ad­u­a­­­na ful­l: U$S 495 (ahí no con­viene ;-)

Pero que te pare­cería ten­er la mis­ma net­book por U$S 180?

Bueno, re­sul­ta que HP (y to­das las em­pre­sas) venden pro­duc­tos "re­fur­bished" o sea rea­condi­ciona­dos. Nor­mal­mente no te vas a dar cuen­ta de nada, tienen un rayón mín­i­mo, o al­go así. Hoy la mis­ma net­book es­ta­ba a U$S 179.90. Nor­mal­mente salen más o menos la mi­tad. Y vienen con garan­tía.

Y fi­játe que la HP mi­ni por U$S 180, pa­gan­do la ad­u­a­na ful­l... cues­ta el 54% de lo que sale la nue­va acá. Eso es ne­go­cio.

Al­ter­na­ti­va­mente, Ciu­dad del Este (Paraguay) es­tá muy cer­ca de Ar­genti­na. Y es muy bara­to com­prar elec­tróni­cos ahí. Y tenés los U$S 300 de fran­qui­ci­a.

Pero hay más! Un ciu­dadano paraguayo que visi­ta ar­genti­na puede traer cier­tas cosas con cier­tos límites. Hay que hablar con él y co­or­di­nar!

Si no conocés a nadie... bueno, andá de paseo a cataratas! Pasala bi­en! Y com­prate una cá­mara o lo que sea en la ex­cur­sión a Ciu­dad del Este.

Accesorios

No com­pres ac­ce­so­rios orig­i­nales. Por ejem­plo: la batería orig­i­nal de re­puesto de mi eeePC 701? U$S 110, 3 el­e­men­tos. La "trucha" de 6 el­e­men­tos? U$S 40.

Conclusión

Ojalá sir­va de al­go, si tenés más tips pone­los en los co­men­tar­ios!

Making your app modular: Yapsy

That a plug­in ar­chi­tec­ture for a com­plex app is a good idea is one of those things that most peo­ple kin­da agree on. One thing we don't quite agree is how the heck are we go­ing to make out app mod­u­lar?

One way to do it (if you are cod­ing python) is us­ing Yap­sy.

Yap­sy is awe­some. Al­so, yap­sy is a bit un­der­doc­u­ment­ed. Let's see if this post fix­es that a bit and leaves just the awe­some.

Up­date: I had not seen the new Yap­sy doc­s, re­leased a few days ago. They are much bet­ter than what was there be­fore :-)

Here's the gen­er­al idea be­hind yap­sy:

  • You cre­ate a Plug­in Man­ag­er that can find and load plug­ins from a list of places (for ex­am­­ple, from ["/us­r/share/ap­p­­name/­­plu­g­in­s", "~/.ap­p­­name/­­plu­g­in­s"]).

  • A plug­in cat­e­­go­ry is a class.

  • There is a map­ping be­tween cat­e­­go­ry names and cat­e­­go­ry class­es.

  • A plug­in is a mod­­ule and a meta­­da­­ta file. The mod­­ule de­fines a class that in­­her­its from a cat­e­­go­ry class, and be­­longs to that cat­e­­go­ry.

    The meta­­da­­ta file has stuff like the plug­in's name, de­scrip­­tion, URL, ver­­sion, etc.

One of the great things about Yap­sy is that it does­n't spec­i­fy too much. A plug­in will be just a python ob­jec­t, you can put what­ev­er you want there, or you can nar­row it down by spec­i­fy­ing the cat­e­go­ry class.

In fac­t, the way I have been do­ing the cat­e­go­ry class­es is:

  • Start with an em­p­­ty class

  • Im­­ple­­ment two plug­ins of that cat­e­­go­ry

  • If there is a chunk that's much alike in both, move it in­­­to the cat­e­­go­ry class.

But trust me, this will all be clear­er with an ex­am­ple :-)

I will be do­ing it with a graph­i­cal PyQt ap­p, but Yap­sy works just as well for head­less of CLI app­s.

Let's start with a sim­ple ap­p: an HTML ed­i­tor with a pre­view wid­get.

//ralsina.me/static/yapsy/editor1.jpeg

A sim­ple ed­i­tor with pre­view

Here's the code for the ap­p, which is re­al­ly sim­ple (it does­n't save or do any­thing, re­al­ly, it's just an ex­am­ple):

But this ap­pli­ca­tion has an ob­vi­ous lim­it: you have to type HTML in it. Why not type python code in it and have it con­vert to HTML for dis­play? Or Wi­ki markup, or re­struc­tured tex­t?

You could, in prin­ci­ple, just im­ple­ment all those mod­es, but then you are as­sum­ing the re­spon­s­abil­i­ty of sup­port­ing ev­ery thing-that-­can-be-­turned-in­to-HTM­L. Your app would be a mono­lith. That's where yap­sy en­ters the scene.

So, let's cre­ate a plug­in cat­e­go­ry, called "For­mat­ter" which takes plain text and re­turns HTM­L. Then we add stuff in the UI so the us­er can choose what for­mat­ter he wants, and im­ple­ment two of those.

Here's our plug­in cat­e­go­ry class:

Of course what good is a plug­in ar­chi­tec­ture with­out any plug­ins for it? So, let's cre­ate two plug­ins.

First: a plug­in that takes python code and re­turns HTM­L, thanks to pyg­ments.

See how it goes in­to a plug­ins fold­er? Lat­er on we will tell yap­sy to search there for plug­ins.

To be rec­og­nized as a plug­in, it needs a meta­da­ta file, too:

And re­al­ly, that's all there is to mak­ing a plug­in. Here's an­oth­er one for com­par­ison, which us­es do­cu­tils to for­mat re­Struc­tured Tex­t:

And here they are in ac­tion:

//ralsina.me/static/yapsy/editor2.jpeg

reSt mode

//ralsina.me/static/yapsy/editor3.jpeg

Python mode

Of course us­ing cat­e­gories you can do things like a "Tool­s" cat­e­go­ry, where the plug­ins get added to a Tools menu, too.

And here's the ap­pli­ca­tion code:

In short: this is easy to do, and it leads to fix­ing your ap­pli­ca­tion's in­ter­nal struc­ture, so it helps you write bet­ter code.

Full source code for ev­ery­thing.


Contents © 2000-2024 Roberto Alsina