Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Python no es un formato de archivo de configuración.


Si te­nés que pre­gun­tar si es bue­na idea, no te­nés una bue­na ra­zó­n. Si es­tás se­gu­ro de que te­nés una bue­na ra­zó­n, en­ton­ces tal vez ten­gas una.

Hay mu­chos mo­ti­vo­s, pe­ro voy a men­cio­nar do­s, y ofre­cer una su­ge­ren­cia.

Py­thon es só­lo lec­tu­ra, y con­fi­gu­rar no es pro­gra­ma­r.

Se­gu­ro, es fá­cil usar py­thon co­mo ar­chi­vo de con­fi­gu­ra­ció­n. Lo im­por­tás y ahí es­tán los da­to­s. Pe­ro aho­ra tu sin­ta­xis de con­fi­gu­ra­ción es un len­gua­ge de pro­pó­si­to ge­ne­ra­l, que pue­de ha­cer co­sas co­mo mos­trar un diá­lo­go cuan­do lo leé­s.

Tu con­fi­gu­ra­ción aho­ra de­pen­de de to­da la in­ter­ne­t, el har­dwa­re, el cli­ma, en­tra­da in­te­rac­ti­va, y el so­ftwa­re ins­ta­la­do en el sis­te­ma. ¿Po­de­ro­so? Sí. ¿Bue­na idea? A ve­ce­s. Pe­ro tu apli­ca­ción aho­ra no pue­de con­fi­gu­rar­se a sí mis­ma.

Si que­rés guar­dar al­gún ti­po de con­fi­gu­ra­ció­n, no vas a po­de­r. Así que pa­ra la ma­yo­ría de las apli­ca­cio­nes in­te­rac­ti­vas de es­cri­to­rio sim­ple­men­te no sir­ve, y no de­be­rías ha­cer­lo, nun­ca.

¿Y qué pa­sa con he­rra­mien­tas no in­te­rac­ti­va­s? Bue­no, usar py­thon sig­ni­fi­ca que otras he­rra­mien­tas tam­po­co pue­den es­cri­bir en ese ar­chi­vo, lo que te saca po­de­r. El po­der de he­rra­mien­tas usan­do he­rra­mien­tas es una de las co­lum­nas que sos­tie­nen la com­pu­ta­ción mo­der­na, y te aca­bás de ra­jar a vos mis­mo de ese eco­sis­te­ma. De­pen­dien­do de qué len­gua­je usa la otra he­rra­mien­ta, ca­paz que ni si­quie­ra pue­de leer tu con­fi­gu­ra­ció­n.

¿Y qué pa­sa cuan­do al­guien te di­ce "po­né es­to en tu con­fig pa­ra ha­cer X"? Bue­no, en ge­ne­ra­l, si el ar­chi­vo apro­ve­cha que es­tás usan­do py­thon pa­ra ha­cer al­go in­te­re­san­te, no po­dés es­tar se­gu­ro de que an­de. Es co­mo co­piar y pe­gar có­di­go de un fo­ro a tu pro­gra­ma. ¿Vos es­pe­ra­rías que an­de?

En­ton­ce­s, no po­dés es­cri­bir­lo, no po­dés sa­car ayu­da de in­ter­ne­t, no po­dés usar he­rra­mien­tas que ac­ce­dan a ese ar­chi­vo.

Tam­bién sig­ni­fi­ca que pa­ra ma­ne­jar el ca­so más ge­ne­ral de có­mo con­fi­gu­rar tu apli­ca­ció­n, ne­ce­si­tás ser pro­gra­ma­do­r. Pa­ra la enor­me ma­yo­ría de las apli­ca­cio­nes, eso no es ne­ce­sa­rio. Si tu apli­ca­ción só­lo pue­de ser con­fi­gu­ra­da por pro­gra­ma­do­res, es muy po­si­ble que ya ha­yas fra­ca­sa­do en su de­sa­rro­llo (hay ecep­cio­nes ob­vias y otras no tan­to­).

¡Ah, el con­se­jo! Bue­no, es "no ha­gas eso­". Y el co­ro­la­rio es "con­fi­gu­rá usan­do da­to­s, no có­di­go­". Usá INIs, XM­L, YA­M­L, JSO­N, o ar­chi­vos de tex­to, o lo que quie­ra­s, pe­ro no có­di­go.

PD: Mi úl­ti­mo pro­yec­to, Niko­la usa py­thon co­mo len­gua­je de con­fi­gu­ra­ció­n. Creí te­ner una bue­na ra­zó­n. No era cier­to.

The Future of PyQt by Example

Th­ree years ago, I started a se­ries of long pos­ts ca­lled "P­y­Qt by Exam­ple". It rea­ched fi­ve pos­ts be­fo­re I aban­do­ned for a se­ries of rea­sons that do­n't ma­tter an­y­mo­re. That se­ries is co­ming ba­ck star­ting next week, rew­ri­tten, im­pro­ved and ex­ten­de­d.

It wi­ll do so in a new si­te, and the "ol­d" pos­ts wi­ll be re­ti­red to an ar­chi­ve pa­ge. Wh­y? We­ll, the te­ch­no­lo­gies us­ed in so­me of them are ob­so­le­te or do­n't qui­te wo­rk no­wa­da­ys. So, the new ver­sions wi­ll be the pre­fe­rred ones.

And whi­le I am not pro­mi­sing an­y­thin­g, I ha­ve enou­gh wri­tten to make this so­me­thing qui­te lon­ge­r, mo­re ni­ce­ly la­youte­d, mo­re in­te­res­ting and make it co­ver mo­re groun­d. BU­T, whi­le doing so­me che­cks on the tra­ffic sta­tis­ti­cs for the old pos­ts, so­me things po­pped ou­t.

This was very popular

About 60% of my si­te's tra­ffic goes to tho­se fi­ve pos­ts. Out of about 1200 pos­ts over 12 year­s, 60% of the viewers go to the 0.4% of the pa­ges. That is a lo­t.

It's a long tail

The tra­ffic has not de­crea­sed in th­ree year­s. If an­y­thin­g, it has in­crea­sed

A long and ta­ll tai­l.

So, all this means the­re is a de­si­re for Py­Qt do­cu­men­ta­tion that is not sa­tis­fie­d. I am not sur­pri­s­e­d: Py­Qt is grea­t, and the re­co­m­men­ded book is not free, so the­re is bound to be a lot of de­man­d.

An­d, he­re's the no­t-­so­-­ro­sy bi­t: I had unob­tru­si­ve, re­le­van­t, ou­t-o­f-­the-wa­y-­bu­t-­vi­si­ble ads in tho­se pa­ges for mo­re than two year­s. Of the 70000 uni­que vi­si­tor­s, not even one cli­cked on an ad. Do­n't wo­rr­y, I was not ex­pec­ting to get mo­ney out of them (al­thou­gh I would lo­ve to so­me day co­llect a $100 che­ck ins­tead of ha­ving google hold my mo­ney for me ad eter­nu­m).

But rea­ll­y? Not even one ad cli­ck? In mo­re than two year­s, thou­san­ds of peo­ple? I ha­ve to won­der if I just attract cheap peo­ple ;-)

PyCamp Empieza el Viernes

Así que va a es­tar bue­ní­si­mo. Pa­ra mí es una ra­ra opor­tu­ni­dad de po­der pa­sar unos días dán­do­le ma­ni­ja a pro­yec­tos per­so­na­le­s, sin que me in­te­rrum­pan pa­va­das co­mo fa­mi­lia, tra­ba­jo, co­ci­na­r, o so­cia­li­za­r, ex­cep­to con otros ner­d­s.

Se­gu­ro, pue­de lle­gar a ha­ber al­gún oca­sio­nal pa­seo en mo­no­ci­clo, lec­cio­nes de ma­la­ba­res, o prác­ti­ca de ti­ro, pe­ro en se­rio, tres o cua­tro días só­li­dos de ha­ckin­g.

Mi idea es tra­ba­jar en pro­yec­tos re­la­cio­na­dos con Niko­la mi ge­ne­ra­dor de si­tios es­tá­ti­co­s, así que si te in­te­re­sa y vas a py­cam­p, ha­ble­mo­s.

Y si te in­te­re­sa pe­ro no vas a py­cam­p, no hay mo­ti­vo pa­ra no ha­cer un sprint vir­tua­l. Hay in­ter­ne­t. Hay IR­C. Voy a te­ner tiem­po. ¡Es un fin de se­ma­na lar­go! Por fa­vor com­par­tí ideas en el gru­po niko­la-­dis­cuss y ve­re­mos qué po­de­mos im­ple­men­ta­r, o por lo me­nos em­pe­za­r.

Un Verificador de links simple para Nikola

Es­te script es un muy sim­ple ve­ri­fi­ca­dor de li­nks que se ase­gu­ra que las pá­gi­nas que Niko­la ge­ne­ra no ten­gan li­nks ro­to­s. Va a ser par­te de Niko­la pro­pia­men­te di­cho una vez que es­té más pu­li­do y doit so­por­te lis­tar los tar­ge­ts

Para probarlo, bajalo y ejecutálo desde el mismo lugar donde está tu, inmediatamente después de un doit.

import os
import urllib
from urlparse import urlparse

import lxml.html

def analyze(filename):
        # Use LXML to parse the HTML
        d = lxml.html.fromstring(open(filename).read())
        for l in d.iterlinks():
            # Get the target link
            target = l[0].attrib[l[1]]
            if target == "#":  # These are always valid
            parsed = urlparse(target)
            # We only handle relative links.
            # TODO: check if the URL points to inside the generated
            # site and check it anyway
            if parsed.scheme:
            # Ignore the fragment, since the link will still work
            # TODO: check that the fragment is valid
            if parsed.fragment:
                target = target.split('#')[0]
            # Calculate what file or folder this points to
            target_filename = os.path.abspath(
                os.path.join(os.path.dirname(filename), urllib.unquote(target)))
            # Check if it exists, or report it
            if not os.path.exists(target_filename):
                print "In %s broken link: " % filename, target
    except Exception as exc:
        # Something bad happened, report
        print "Error with:", filename, exc

# This is hackish: we use doit to get a list of all
# generated files. Minor modifications would let you check
# the non-generated files as well.

for task in os.popen('doit list --all', 'r').readlines():
    task = task.strip()
    if task.split(':')[0] in (
        'render_site') and '.html' in task:
            # It looks like a generated HTML file

Confessions of a Troll

And then he told me "Rober­to's a known trol­l" and I was like "re­al­ly?" he seems like a nice guy!

—Not say­ing who said it

So, that hap­pened a while ago in a din­ner. And I am that trol­l. I must con­fess it, so here it is. I have a long, long, long his­to­ry of trolling. Per­haps I could ra­tio­nal­ize it in­to just be­ing ar­gu­men­ta­tive, or just en­joy­ing a good ar­gu­men­t, but no, re­al­ly, I de­rive plea­sure from see­ing peo­ple re­act to what I say.

That could maybe be in some way con­struc­tive, I could just do it to make peo­ple see things from a dif­fer­ent an­gle, and in my good mo­ments I do that. But in oth­ers I just find some­one I dis­like, or some­one who says some­thing that rubs me the wrong way, and I ... well, it's not pret­ty.

What I usu­al­ly do is up the ante. I es­ca­late. I say out­ra­geous things. Usu­al­ly just slight­ly more out­ra­geous than what the oth­er guy says, so I can still ra­tio­nal­ize it as "he start­ed it", or "he de­serves it" but hon­est­ly, deep in­sid­e, I know it's not true. I know I am be­ing nasty be­cause I like it. And that suck­s. It sucks that I have this mean streak in me, and I can't get rid of it. It sucks that I have fun in­sult­ing the oth­er poor bas­tard.

I could even say that most of the peo­ple I troll are trolls them­selves. But that's not re­al­ly an ex­cuse. If they de­served con­tempt for their trolling, then I am just as de­serv­ing for mine. I am sure they, al­so, have their rea­sons and those rea­sons sound per­fect­ly ra­tio­nal to them­selves.

I could say that I of­ten troll those who spread poi­sonous speech. That I troll those who are spread­ing mis­in­for­ma­tion and evil ideas. And yes, that is true, but again, I could re­ply with­out trolling. I could re­ply ra­tio­nal­ly, and just point out where they are say­ing non­sense, where they are spread­ing stu­pid­i­ty, and avoid the flair, avoid the gra­tu­itous in­sult.

I could say that I troll those who both­er me per­son­al­ly out of their own free will. So yes, telling a Je­ho­vah's Wit­ness that I will be at the door as soon as I wash my hands of the blood sac­ri­fice I make to Sa­tan is fun­ny, but why is it any bet­ter than just telling them I am not in­ter­est­ed.

Oh, sure, I could say that telling some­one who in­sult­ed me "opin­ions are like ass­holes, and so are you" is some­what clev­er, but I could just say "y­ou are wrong, rude, and un­de­serv­ing of my at­ten­tion".

I sure could say that trolling some­one who is rude, in­sult­ing, ob­nox­ious and dis­rup­tive may teach him (it's al­ways a he, is­n't he?) a lesson, but it's just not true. They just see those re­spons­es as chal­lenges.

I could say that feed­ing the oth­er troll is just harm­less fun, but it's not true be­cause I know it hurts peo­ple, and cre­ates an ob­nox­ious en­vi­ron­men­t. I could say that trolling those who de­serve to be trolled is fair. But it's not true be­cause I am noone's judge.

So, if I have trolled you, ac­cept this post as an apol­o­gy. Not a "sor­ry if I of­fend­ed you" apol­o­gy, but a straight apol­o­gy. I am sor­ry I trolled you. I will try to stop.

I will not stop say­ing and writ­ing what I think, and I will not ab­stain from re­ply­ing to oth­er peo­ple's opin­ion­s, but I will do a hon­est try to do it in a not-trolling man­ner, of of­fer­ing my opin­ion as it is, in­stead of as a per­for­ma­ce to make the oth­er one feel hu­mil­i­at­ed or hurt or un­de­serv­ing.

Be­cause, and here is my on­ly piece of ex­cuse: I hate bul­lies. I was sent to school two years too ear­ly. So that you have an idea how that can af­fect some­one, I am of av­er­age height, but un­til I was 13 I was con­vinced I was very short. I man­aged to be­come a de­cent swim­mer, but un­til I was 12 or so, I was con­vinced I sucked at all sports and games. I was in­ceas­ing­ly bul­lied since I first ev­er met my "peer­s" un­til I was able to kick the crap out of them. I be­came a tough kid. I could take a beat­ing like you can't imag­ine, be­cause I was too small to hit back, and the on­ly way not to be a to­tal los­er was to keep get­ting up and go­ing to be beat­en again, while mak­ing sar­cas­tic com­ments.

And it turned out that those sar­cas­tic com­ments worked. I got my ass kicked, but the next day that kid re­mem­bered how I was get­ting back on my feet and jok­ing about his moth­er. And that, of course, lead to fur­ther bul­ly­ing. When I was about 12, I was so ex­treme, I scared ev­ery­one so much, they stopped. I was scary. I talked like a freak­ing psy­cho. I prob­a­bly was close to be­ing one.

And the les­son I learned was that if you make fun of peo­ple, they got hurt enough to want to avoid it lat­er. So, I was, in fac­t, a bul­ly my­self. And thus, I be­came that which I hat­ed. I have had bet­ter times and worst times, I have been more in con­trol and not so much. And it has tak­en me a long time to fig­ure this out. I don't like what I be­came. So I will stop. And I am sor­ry.

Just gen­tle rib­bing and self­-dep­re­ca­tion from now on. Prom­ise.

Contents © 2000-2023 Roberto Alsina