Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about python (old posts, page 83)

New rst2pdf feature: --strip-elements-with-class

First new fea­ture in rst2pdf in a long long time, but it was easy to do, and there was an ac­tu­al us­er need­ing it.

This ex­pos­es func­tion­al­i­ty rst2html al­ready had, so that's prob­a­bly why it was easy to do ;-)

In any case, what is it and what is it good for?

If you mark some­thing with a class, you can now omit it from the out­put:

.. class:: ignored

This will not be in the output if you use --strip-elements-with-class=ignored

And it's use­ful, for ex­am­ple, so you can keep slides and pre­sen­ta­tion notes in the same file. You just put your notes in a class you strip when pro­duc­ing the slides.

Since some class­es are au­to­mat­i­cal­ly as­signed for ad­mo­ni­tion­s, this is ex­tra sim­ple:

.. note:: This is a note admonition.

   Note admonitions always have the note class. So you can strip them easily.

And if you don't strip them, they will look pret­ty.

Nikola v5 Released

A new ver­sion of Niko­la is out! You can get it at the usu­al place.

This ver­sion is not com­plete­ly back­wards com­pat­i­ble, thus the new ma­jor ver­sion num­ber, but switch­ing to it should be easy-ish. If you are us­ing ver­sion 4.0.3:

  1. Re­­move your do­­do.py

  2. Use niko­la build in­stead of doit from now on

  3. use niko­la serve in­stead of doit serve, niko­la new_­post in­stead of doit new_­post, and so on. Some oth­er doit task are al­so con­vert­ed in­to niko­la com­mand you can get the list us­ing niko­la help

The in­te­gra­tion of doit in­to Niko­la is not done in a very nice way, that's still on­go­ing work, but it should be Good Enough To Work (T­M).

Hope you en­joy this re­lease!

Features

  • Tem­­plates now know their name from tem­­plate_­­name in their con­­tex­t.

  • Made most of Niko­la in­­­to Yap­sy plug­in­s.

  • Re­curse gal­­leries/ and ren­der each fold­er as a gallery.

  • Bread­­crumbs and fold­er links in im­age gal­­leries.

Bugfixes

  • Fixed doc in­­stal­la­­tion

  • Put we­bas­sets cache in cache/we­bas­sets

  • Up­­­date to doit 0.17

  • Don't crash on in­­­com­­plete tran­s­la­­tions

  • Fixed Is­­sue 160: ren­der_­­tags did­n't call scan_­­post­s()

  • Fixed Is­­sue 161: we­bas­sets set­t­ing USE_BUN­­DLES was ig­nored (fix by schet­ti­no72)

  • Fixed Is­­sue 153: in­­dex.txt was be­ing ig­nored in gal­­leries.

Nikola is Pluginificated.

Yes, I know that's not a re­al word.

So, the git mas­ter of Niko­la now has plug­ins. In fac­t, not on­ly does it have plu­g­in­s, but is ba­si­cal­ly made of plug­ins.

You see, the code used to most­ly be in­side a class (called Niko­la), and ... it had grown. That class had grown up to around 2000 lines of code. Which is com­plete­ly ridicu­lous.

So, us­ing Yap­sy I turned the code in­side out: al­most all the code that was in that mon­ster class was moved in­to plug­ins and the class turned in­to a smart plug­in load­er.

This has brought sev­er­al ad­van­tages:

  • Now you can ex­­tend Niko­la for your own pur­­pos­es. Just cre­ate a plug­in fold­er in your site, and put the ex­­tra func­­tion­al­i­­ty there.

  • Sup­­port for whole cat­e­­gories of things is now mod­­u­lar. Want to sup­­port a dif­fer­­ent markup? A dif­fer­­ent tem­­plate sys­tem? Just write a plug­in.

  • Want to add com­­plete­­ly new func­­tions to Niko­la? Like, say, a way to im­­port da­­ta from an­oth­er blog tool, or some­thing like plan­et soft­­ware? Well, just add a "com­­mand plug­in".

What has changed for the user?

  • You can delete do­do.py from your site.

  • Use niko­la build in­stead of doit

  • Use niko­la serve in­stead of doit serve

Some mi­nor things still need do­ing in this area (no­table, fix­ing the doc­s), but the main refac­tor­ing is there.

Taxes, Game Theory, and Python (Part 1 of 2)

Be­fore I gave up on be­com­ing an ed­u­cat­ed man, I stud­ied math. And to this day it piss­es me that noone has fig­ured out how to make math in­ter­est­ing to the math­-a­verse. Here's a small at­temp­t.

Let's con­sid­er the fol­low­ing sce­nar­i­o, based com­plete­ly on things I know, not things I do ;-)

Sup­pose that in a city called San Isidro, there is a house. Hous­es in San Isidro pay a mu­nic­i­pal tax, in ex­change for the ser­vice of garbage col­lec­tion, street sweep­ing, tree trim­ming, and street light­ing.

It's a very small tax, but let's say it's $100 a month be­cause it's a nice, easy to han­dle num­ber.

Al­so, San Isidro is in a coun­try called Ar­genti­na. In that coun­try there are sev­er­al laws that af­fect the home own­er­s:

  1. You can't sell a house if you owe any tax­es.

  2. The own­er has a 1% chance of wan­t­ing to sell the house each month.

  3. Debts ex­pire af­ter 5 years.

  4. If you are sued and you lose, you pay they oth­­er guy's lawyer fees.

  5. Lawyer fees are capped to 25% of the mon­ey be­ing dis­­put­ed.

  6. Lawyers are re­luc­­tant to help you sue some­one if they get very lit­­tle mon­ey (de­fined as less than $2000)

  7. If sued by the city for owed tax­es, the own­er al­ways los­es.

  8. Un­­paid tax­es ac­crue 2% com­­pound in­­ter­est mon­th­­ly. So, if you don't pay your $100, you will owe $102, then $104.04, $106.0128 etc.

With all those el­e­ments in place, let's play a game called "Tax Golf"!

The game is played by an in­de­ter­mined num­ber of play­ers called own­ers and one spe­cial play­er called city.

The game is played to 100 "month­s" or un­til all prop­er­ty has been sol­d.

The goal of the game, for the own­er­s, is to pay as lit­tle mon­ey as they can. The score is cal­cu­lat­ed like this: amount of mon­ey you paid di­vid­ed by the time you owned the house.

The own­er with the low­est score is the win­ner.

The goal of the game for the city, is to get as much mon­ey as he can. He's not com­pet­ing against the play­er­s, for him it's a sort of soli­taire where he com­petes against his past per­for­mance.

This, my friends is math. Math is a tool that helps you (a­mong oth­er things) do the right thing in this sort of com­pli­cat­ed, ar­bi­trary, re­al life sce­nari­o.

So, what's a good strat­e­gy for a own­er, and for the city?

In a sec­ond post next wednes­day, I will give some an­swers to those ques­tion­s, us­ing python.

Improved Wordpress.com Importer and a Question

Thanks to the co­op­er­a­tion of Hu­mi­tos who gave me his word­press back­up, I did some im­prove­ments in the word­press.­com im­port fea­ture of Niko­la, my stat­ic web­site/blog gen­er­a­tor

So, if you were to try to use nikola_wordpress_importer from master now, it would:

  1. Not crash ;-)

  2. Down­load at­­tach­­ments

  3. Fix links to at­­tach­­ments so they work on the new site

How­ev­er, I am now un­sure of what ex­act­ly is in word­press.­com's ex­port XML file. The posts them­selves are in this for­m:

Muchas gracias Nico por hacer el video este. Groso, quedó muy bueno.

[youtube=http://www.youtube.com/watch?hl=es&v=882qxARXa6c]

Two things jump to me:

  1. That's not HTML

  2. WTF is that youtube thing?

I am hav­ing some suc­cess pro­cess­ing it as mark­down, since that han­dles the para­graph breaks and some oth­er stuff. Maybe the youtube em­bed­ding is done with a mark­down ex­ten­sion?

Any­one knows?


Contents © 2000-2023 Roberto Alsina