Posts about programming (old posts, page 14)

2007-11-15 16:23

Bash does thing I never suspected.

Try this and be amazed:

$ cat < /dev/tcp/gsmtp163.google.com/25
220 mx.google.com ESMTP 12si345086nzn

Be honest: did you know bash could do that? I didn't until finding it in the man page

Now try this and be amazed it doesn't work (yes, it's in the docs):

$ cat /dev/tcp/gsmtp163.google.com/25
cat: /dev/tcp/gsmtp163.google.com/25: No such file or directory

And remember, on unix everything is a file, but maybe that file is only there in some very specific circunstances.

UPDATE: There is a chance this will not work in your distro, specifically Debian.

2007-11-05 17:34

Coming soon...

I have managed to create the most bizarre way to write a spreadsheet engine in Python.

I still need to polish some things, but here are the highlights:

  • Your formulas compile to C
  • C is inlined using Instant

Yes, that means you edit a cell in the GUI and you need to wait until gcc compiles the thing.

Is it going to be useful? Probably not. Is it cool? I say yeah.

I will polish it somewhat, create a sttandalone engine, and show it here.

2007-10-18 17:37

Use YUI RTE.

No, do not use the alternatives. Use the Yahoo User Interface Rich Text Editor.

Why?

  • It's maintained
  • It at least tries to work with all browsers
  • You can use it hosted at yahoo
  • It's nice and easy to use
  • It has an image upload extension already.

2007-10-15 12:37

rst2pdf: now with working tables

Yup. Figured out column/cell spans in reportlab, found old rst2rst code that regularizes the table row/columns to be all the same number of elements, and voilá, tables work, including examples like this:

+---------------------------------+
| header                          |
+==========+======================+
|          |    tr                |
+  tl      +------------+---------+
|          |    c       |  br     |
+----------+------------+         +
|           bl          |         |
+-----------------------+---------+

Which generates nicely on PDF now. See it

The bad side is that it's now not a single file anymore, so I am needing a place to host SVN and whatever, because it's turning into a real project... and googlecode doesn't let me start more stuff.

2007-10-15 09:23

Maybe I should write an office suite.

Really. I already have a functioning slideshow program, a spreadsheet and I could write a word processor in a week (for some values of "word", "processor", "write", "week" and "a".)

Of course it would be a very awful office suite, but at least it would be small. I think I can put all that in 1MB including icons.

I could make stupidsheet pretty good, and tobogan is actually useful (if rough).

2007-10-11 08:30

rst2pdf again

I did a little (very little) more work on rst2pdf [1]

Better:

  • Headers
  • Footers
  • Footnotes (as endnotes, real footnotes are too much work because you have to reflow the text)
  • External links (http, email)
  • Some styling improvements (meaning: the output is not so painful in the eyes)
  • Paper size support
  • Real separators

Then there are some things you just get because it's done using reportlab:

  • TrueType font embedding (check the example below, and look at the monospaced font)
  • No hyphenation (although there is a project on the web that claims to have done it, I should check it out)

Still broken:

  • No way to put things like page numbers or section names in headers/footers
  • The footnotes are not linked to their contents and viceversa
  • In fact, no internal links work, including title references
  • Tables are pretty broken

And here is the usual version of the rst demo showing improvements.

[1] My tool to convert Rstructured Text to PDF

2007-10-06 11:26

Done with rst2pdf for now

It works much better than it did last night.

The main missing/broken things are:

  • Tables
  • Links
  • Footnotes/citations
  • Headers/Footers
  • References
  • Table HEaders/Spanning cells
  • Lists that don't start at 1

The rest seems to be in working order and producing decent output already. It can process the ReST demo and it doesn't look bad: check it out

I say, good for half a day of hacking, and will now stop, because it's a weekend and I have a family :-)

But that doesn't mean you can't try it for yourself. Just run it thus:

python rst2pdf.py myrstfile.txt

And you will get (hopefully) a myrstfile.txt.pdf

Let me know how it works, and if it doesn't and it's not related to one of the things I mentioned above as broken, send me a test file!

2007-10-05 22:26

Generating PDFs from Restructured text

This has always been possible, going via LaTeX.

However, LaTeX being what it is, you either need to learn it, or you end up with rather plain-looking documents.

While that's ok for a manual, I want to use Restructured Text for everything involving documents.

So, I looked for another solution. Sadly, I could not make the existing rlpdf writer work, sooooo I decided to write my own tool.

Since I intensely dislike the Visitor pattern involved in writing a regular docutils writer, I adapted my old rst2rst.py and ended with rst2pdf.py which just traverses the tree recursively and writes the PDF using ReportLab.

And it took me about 3 hours to make it work:

  • For a limited subset of RST (no footnotes, no links, no decoration)
  • For some subset of tables (no col/row spanning)
  • With limited "styling" (it's mostly there, but I need to write a lot of ReportLab styles.

How well does it work... rather well.

Here's a generated PDF of The RestructuredText Primer

Ignore aesthetics, and consider function, it's pretty good.

Contents © 2000-2018 Roberto Alsina