Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

The day we saw the dinosaur (an Ada Lovelace Day story)

To­day, March 24th is Ada Lovelace day, a day of blog­ging to cel­e­brate the achieve­ments of wom­en in tech­nol­o­gy and sci­ence.. I am tak­ing the lib­er­ty to tag this as python so it ap­pears in the right plan­et­s, but that's just to pro­mote Ada Lovelace day. Sor­ry 'bout that.

I will write about the on­ly per­son who ev­er taught me pro­gram­ming, Clau­di­a. I was young, so the earth was still luke­war­m, the day we saw the di­nosaur.

I was just a green sopho­more in the School of Chem­i­cal En­gi­neer­ing where, para­dox­i­cal­ly I would nev­er take a chem­istry class, be­ing an ap­plied math stu­dent and all that, and at the time "per­son­al com­put­er­s" were a nov­el­ty, a toy of the up­per mid­dle class.

We had spent the first two months of the se­mes­ter learn­ing how to pro­gram the ob­vi­ous way: writ­ing as­sem­bler for a fic­tion­al ma­chine on pa­per by hand, when Clau­dia broke the news, we were go­ing to see a re­al com­put­er.

No, not a PC, not even an XT, but a re­al com­put­er, the one re­al com­put­er in all the uni­ver­si­ty, and you could hear the type switch­ing to bold as she spoke about it. Sad­ly it was not as re­al as the one at the re­search fa­cil­i­ty (A Mini­VAX!) but it was a re­al enough PDP.

We would not be al­lowed to ac­tu­al­ly use it un­til the fol­low­ing year, but ... well, it was still some­thing spe­cial.

I had been programming for years, even for a year before I saw my first (seriosuly not real) computer, I had followed BASIC programs in my head for days, imagining the space invaders float on the screen of my mind, and stepped into writing machine code inside REM statements in my Timex Sinclair 1000 onto the luxury of a C64, but never noone had taught me anything.

Our small class (maybe 10 stu­dents) spent end­less hours do­ing things like tra­verse a ma­trix, first by rows, thn by column­s, then in a spi­ral from the top-left, writ­ing pro­grams that fol­lowed our end­less source of al­go­rithm­s, the nu­mer­i­cal so­lu­tions guide.

First as­sem­bler, then For­tran, we learned.

She was my Mr. Miyag­i, I was a het­ero­sex­u­al Ralph Mac­chio, and I fig­ured out the most im­por­tant thing about pro­gram­ming: I was aw­ful at it.

Over the next 20 years that sit­u­a­tion has been slow­ly im­prov­ing, but I nev­er again had some­one teach me pro­gram­ming. Clau­dia had al­ready taught me ev­ery­thing I need­ed to know, that code can al­ways im­prove, that there's more than one way to skin a cat.

That the di­nosaur was re­al and that some day soon my com­put­er would be faster and nicer than the di­nosaur was then, and that pro­gram­ming was cool, and that if I could find a way to draw a poly­no­mi­al graph hor­i­zon­tal­ly on a print­er with­out ev­er hav­ing the whole graph in mem­o­ry (it did­n't fit), those fu­ture com­put­ers would do awe­some things, and that I was one of the many who would help bring that to re­al­i­ty.

That talk­ing about code was fun in it­self, that you could make a mod­est liv­ing and be hap­py about it, that you could in any case make jig­saw puz­zles in your spare time and keep on teach­ing or what­ev­er.

And lat­er the di­nosaur's bones were scav­enged in­to a line of racks hold­ing router­s, and its glass ter­mi­nals are de­stroyed, and the gold in its teeth was stolen and the rare bus ca­bles sol­d, and its cir­cuits scrapped, but I saw the di­nosaur alive, and Clau­dia taught me how to make it jump, and for that, I will al­ways be grate­ful.

Grok 1.0 Web Development

Ha­bién­do­lo leí­do (¡­per­dón por la de­mo­ra!) es­tas son mis con­clu­sio­nes:

Es­tá bien es­cri­to. La ex­po­si­ción es cla­ra y el au­tor co­no­ce el te­ma y lo que quie­re de­ci­r.

Me im­pre­sio­nó lo di­rec­to del en­fo­que de Grok cuan­do lo com­pa­ro con lo que va­ga­men­te re­cuer­do de an­ti­guas ex­pe­rien­cias con Zo­pe. La idea de un fra­mewo­rk ági­l, mo­derno y sim­ple so­bre la re­co­no­ci­da­men­te po­ten­te ba­se de Zo­pe tie­ne mu­cho mé­ri­to.

Por otro la­do, no es­toy real­men­te con­ven­ci­do de de­jar Djan­go pa­ra los pe­que­ños pro­yec­tos web que ten­go en car­pe­ta, pe­ro si es­tás bus­can­do un fra­mewo­rk, y no te­nés mu­cho in­ver­ti­do en otro, va­le la pe­na con­si­de­rar Gro­k.

Y, si que­rés apren­der Gro­k, es­te li­bro te sir­ve.

Se pue­de leer un ca­pí­tu­lo de mues­tra u ob­te­ner más in­for­ma­ción so­bre el li­bro

rst2pdf 0.14 released!

It's my plea­sure to an­nounce that I just up­load­ed rst2pdf 0.14 to the site at http://rst2pdf.­google­code.­com.

Rst2pdf is a pro­gram and a li­brary to con­vert re­struc­tured text di­rect­ly in­to PDF us­ing Re­port­lab.

It sup­ports True Type and Type 1 font em­bed­ding, most raster and vec­tor im­age for­mat­s, source code high­light­ing, ar­bi­trary text frames in a page, cas­cad­ing stylesheet­s, the full re­struc­tured text syn­tax and much, much more.

It al­so in­cludes a sphinx ex­ten­sion so you can use it to gen­er­ate PDFs from doc­u­ments built with Sphinx.

In case of prob­lem­s, please re­port them in the Is­sue track­er (http://­code.­google.­com/p/rst2pdf/is­sues/list) or the mail­ing list (http://­group­s.­google.­com/­group/rst2pdf-dis­cuss)

This re­lease fix­es sev­er­al bugs and adds some mi­nor fea­tures com­pared to 0.13.2. Here are some of the changes:

  • Fixed Is­­sue 197: Ta­ble bor­ders were con­­fus­ing.

  • Fixed Is­­sue 297: styles from de­­fault­­.j­­son leaked on­­to oth­­er syn­­tax high­­­light­ing stylesheet­s.

  • Fixed Is­­sue 295: key­­word re­­place­­ment in head­­er­s/­­foot­ers did­n't work if ###­­Page### and oth­­ers was in­­­side a ta­ble.

  • New fea­­ture: odd­­e­ven di­rec­­tive to dis­­­play al­ter­­na­­tive con­­tent on odd­­/even pages (good for head­­er­s/­­foot­er­s!)

  • Switched all stylesheets to more read­­able RSON for­­mat.

  • Fixed Is­­sue 294: Im­ages were de­­formed when on­­ly height was spec­i­­fied.

  • Fixed Is­­sue 293: Ac­­cept left­­/­­cen­ter/right as align­­ments in stylesheet­s.

  • Fixed Is­­sue 292: sep­a­rate style for line num­bers in code­blocks

  • Fixed Is­­sue 291: sup­­port class di­rec­­tive for code­blocks

  • Fixed Is­­sue 104: to­­tal num­ber of pages in head­­er/­­foot­er works in all cas­es now.

  • Fixed Is­­sue 168: linenos and linenothresh­old op­­tions in Sphinx now work cor­rec­t­­ly.

  • Fixed re­­gres­­sion in 0.12 (in­ter­ac­­tion be­tween rst2pdf and sphinx math)

  • Doc­u­­men­t­ed ex­ten­­sions in the man­u­al

  • Bet­ter styling of bul­let­s/items (Is­­sue 289)

  • Fixed Is­­sue 290: don't fail on bro­ken im­ages

  • Bet­ter font find­­ing in win­­dows (patch by tech­­tonik, Is­­sue 282).

  • Fixed Is­­sue 166: Im­­ple­­men­t­ed Sphinx's hlist (hor­i­­zon­­tal list­s)

  • Fixed Is­­sue 284: Im­­ple­­men­t­ed pro­­duc­­tion lists for sphinx

  • Fixed Is­­sue 165: De­f­i­ni­­tion lists not prop­er­­ly in­­­den­t­ed in­­­side ad­­mo­ni­­tions or ta­bles.

  • SVG Im­ages work in­­­line when us­ing the inkscape ex­ten­­sion.

  • Fixed Is­­sue 268: TOCs shift­ed to the left on RL 2.4

  • Fixed Is­­sue 281: sphinx test au­­to­­ma­­tion was bro­ken

  • Fixed Is­­sue 280: wrong page tem­­plates used in sphinx

En­joy!

Si lo vamos a hacer, vamos a hacerlo bien!

Acá es­tá el th­read.

Es la­aaar­go, pe­ro bue­no, re­sul­ta­do fi­na­l, co­mo soy un ner­d, soy un pro­gra­ma­do­r, y los pro­gra­ma­do­res pro­gra­man hi­ce el pro­gra­ma.

Lo que me sor­pren­dió fué que ape­nas lo em­pe­cé a ha­ce­r, es­te pro­gra­ma com­ple­ta­men­te des­car­ta­ble, que no sir­ve pa­ra na­da... es­tu­ve re pro­li­jo.

  • Usé do­c­­trings.

  • Usé do­c­­tes­­ts.

  • Lo hi­­ce con cui­­da­­do con el uni­­co­­­de.

  • Los co­­­men­­ta­­rios son ade­­cua­­dos

  • La fa­c­­to­­­ri­­za­­ción en fun­­cio­­­nes es­­tá bien he­­cha

Ha­ce ape­nas un año no hu­bie­ra he­cho to­do eso. Me pa­re­ce que es­toy ter­mi­nan­do una eta­pa en mi (len­ta, a los tro­pe­zo­nes) evo­lu­ción co­mo pro­gra­ma­do­r, y es­toy pro­gra­man­do me­jor que lo que ve­nía ha­cien­do.

Me pa­sa­ba mu­cho que co­mo py­thon te de­ja ha­cer las co­sas rá­pi­do, las ha­cía rá­pi­do y ma­l, o len­to y bien. Aho­ra las ha­go rá­pi­do y (creo) bien, o por lo me­nos me­jo­r, o al me­nos me­nos peo­r.

De pa­so: és­te es un ex­ce­len­te ejer­ci­cio pa­ra pro­gra­ma­do­res "ju­nio­r"!

  • In­­vo­­­lu­­cra ma­­ne­­jo de strings que pue­­de (o no) re­­so­l­­ve­r­­se con re­­gexps

  • Usar tes­­ts ha­­ce las co­­sas más fá­­ci­­les en vez de más di­­fí­­ci­­les

  • Te ha­­ce "pen­sar en uni­­co­­­de"

  • El al­­go­­­ri­t­­mo en sí no es di­­fí­­ci­­l, pe­­ro es al­­go tra­m­­po­­­so

De pa­so, acá es­tá el (tal vez pa­vo­ta­men­te so­brees­tu­dia­do) pro­gra­ma en cues­tió­n, ga­so­.­py:

# -*- coding: utf-8 -*-

"""
Éste es el módulo gasó.

Éste módulo provee la función gasear. Por ejemplo:

>>> gasear(u'rosarino')
u'rosarigasino'
"""

import unicodedata
import re

def gas(letra):
    '''dada una letra X devuelve XgasX
    excepto si X es una vocal acentuada, en cuyo caso devuelve
    la primera X sin acento

    >>> gas(u'a')
    u'agasa'

    >>> gas (u'\xf3')
    u'ogas\\xf3'

    '''
    return u'%sgas%s'%(unicodedata.normalize('NFKD', letra).encode('ASCII', 'ignore'), letra)

def umuda(palabra):
    '''
    Si una palabra no tiene "!":
        Reemplaza las u mudas de la palabra por !

    Si la palabra tiene "!":
        Reemplaza las "!" por u

    >>> umuda (u'queso')
    u'q!eso'

    >>> umuda (u'q!eso')
    u'queso'

    >>> umuda (u'cuis')
    u'cuis'

    '''

    if '!' in palabra:
        return palabra.replace('!', 'u')
    if re.search('([qg])u([ei])', palabra):
        return re.sub('([qg])u([ei])', u'\\1!\\2', palabra)
    return palabra

def es_diptongo(par):
    '''Dado un par de letras te dice si es un diptongo o no

    >>> es_diptongo(u'ui')
    True

    >>> es_diptongo(u'pa')
    False

    >>> es_diptongo(u'ae')
    False

    >>> es_diptongo(u'ai')
    True

    >>> es_diptongo(u'a')
    False

    >>> es_diptongo(u'cuis')
    False

    '''

    if len(par) != 2:
        return False

    if (par[0] in 'aeiou' and par[1] in 'iu') or \
    (par[1] in 'aeiou' and par[0] in 'iu'):
        return True
    return False

def elegir_tonica(par):
    '''Dado un par de vocales que forman diptongo, decidir cual de las
    dos es la tónica.

    >>> elegir_tonica(u'ai')
    0

    >>> elegir_tonica(u'ui')
    1
    '''
    if par[0] in 'aeo':
        return 0
    return 1

def gasear(palabra):
    """
    Convierte una palabra de castellano a rosarigasino.

    >>> gasear(u'rosarino')
    u'rosarigasino'

    >>> gasear(u'pas\xe1')
    u'pasagas\\xe1'

    Los diptongos son un problema a veces:

    >>> gasear(u'cuis')
    u'cuigasis'

    >>> gasear(u'caigo')
    u'cagasaigo'


    Los adverbios son especiales para el castellano pero no
    para el rosarino!

    >>> gasear(u'especialmente')
    u'especialmegasente'

    """
    #from pudb import set_trace; set_trace()

    # Primero el caso obvio: acentos.
    # Lo resolvemos con una regexp

    if re.search(u'[\xe1\xe9\xed\xf3\xfa]',palabra):
        return re.sub(u'([\xe1\xe9\xed\xf3\xfa])',lambda x: gas(x.group(0)),palabra,1)


    # Siguiente problema: u muda
    # Reemplazamos gui gue qui que por g!i g!e q!i q!e
    # y lo deshacemos antes de salir
    palabra=umuda(palabra)

    # Que hacemos? Vemos en qué termina

    if palabra[-1] in 'nsaeiou':
        # Palabra grave, acento en la penúltima vocal
        # Posición de la penúltima vocal:
        pos=list(re.finditer('[aeiou]',palabra))[-2].start()
    else:
        # Palabra aguda, acento en la última vocal
        # Posición de la última vocal:
        pos=list(re.finditer('[aeiou]',palabra))[-1].start()

    # Pero que pasa si esa vocal es parte de un diptongo?

    if es_diptongo(palabra[pos-1:pos+1]):
        pos += elegir_tonica(palabra[pos-1:pos+1])-1
    elif es_diptongo(palabra[pos:pos+2]):
        pos += elegir_tonica(palabra[pos:pos+2])


    return umuda(palabra[:pos]+gas(palabra[pos])+palabra[pos+1:])

if __name__ == "__main__":
    import doctest
    doctest.testmod()

Contents © 2000-2023 Roberto Alsina