Thursday, November 25, 2010

Factorial and pub toilets

What on earth could they be doing together in the title?


On identi.ca / Twitter / irc there are many ways to tell a new user.


Retelling old jokes or resending tired comparisons:

...is just one way of spotting a new user.


Python programming techniques comparison - factorial:

from math import factorial
print factorial(6)

is a concise and modern way of obtaining factorial of 6 in Python.

There is a funny comparison of different approaches, that has made the rounds several times, and here is one version at c0demasters.wordpress.com

I could link to many forums that have posted the same things in 2009, 2007, 2004 and so on.

The point is that whilst it was funny for myself, because it was new to me, it is not very new to the Python community.


And the pub toilets?

Ah in a pub I used to frequent up in Preston, the toilets where located at the end of the bar and a bit difficult to see if you did not know. Slight inconvenience if you were new to the pub, however it did hold one advantage for the pub manageress ... the new drinkers in the pub almost always introduced themselves to her, in asking the way to the toilets.


About math versus cmath or c_math:

If you were doing a large factorial, then you could instead use Cython to give you a less interpreted runtime version of factorial.

If you are wondering about import c_math in the comparison I mentioned, then you might need to read the articles and links which follow. Perhaps you are looking for Cython or a Complex number library for Python.


Links and further reading:

Tuesday, November 23, 2010

Dickens - he does tell a good story - "Great Expectations"

I reproduce a short extract from the end of Chapter 7 of Great Expectations

With that, she pounced upon me, like an eagle on a lamb, and my face was squeezed into wooden bowls in sinks, and my head was put under taps of water-butts, and I was soaped, and kneaded, and towelled, and thumped, and harrowed, and rasped, until I really was quite beside myself.

(I may here remark that I suppose myself to be better acquainted than any living authority, with the ridgy effect of a wedding-ring, passing unsympathetically over the human countenance.)

Chapter 17 and a future solution for the damaged:

Because I am re-reading this novel, I am about a third the way through as I write this, and have no recollection of how it ends.

Around Chapter 17, the main character Pip has been damaged. His brief contact with the residents of Manor House (Satis), have left him dissatisfied with his lot. Furthermore his first experience of boyhood romance, has been with a subject who has been tutored in scorn and damage.

"Eternal Sunshine of the Spotless Mind" [ 2004 ] is an interesting movie and suggests a future solution to 'damaging experiences that the individual cannot get past'. In Pip's case, the availability of such a treatment, and the combination of the two stories would be an interesting mix of fiction.

Summary: He was damaged, he was fixed, the end.

I am not advocating the treatment suggested in the Michel Gondry film, but merely musing on how the story of Great Expectations, will look, if the treatment that Winslet and Carrey undertake, ever did become generally available.

New technological treatments have upsides and downsides, and in the 1990 film "Total Recall", a more sinister application of that technology is used.

I leave you with an extract from the Total Recall page on Wikipedia:
The film [ Total Recall ] explores the question of reality versus delusion, a recurrent topic in Philip K. Dick’s works. The plot calls for the lead character and the audience to question whether the character’s experience is real or being fed directly to his mind.
And now back to my book, to see how Pip gets on with his adult life.

Sunday, November 7, 2010

djvu2pdf - well manually that is...

As with most conversions from format A to format B, the best results are often obtained by using format A viewer, and 'Export'

djvu -> ps -> pdf

Well if you really want you can go that way, but be warned that .ps files rarely use image compression and other modern techniques, so expect a large intermediate file!

I use postscript and do like the format for short documents (say less than 10 pages).

For longer documents and full books, then .djvu is a great format in itself, and now that djview4 is available in Debian, there is no real pressing need to convert.

If however you are determined to convert then here are your options:
  1. djvups to get a .ps file, and then postscript view export/print
  2. ddjvu -format=tiff  to get a tiff, and then convert that again
  3. djview4 'File' -> 'Export As'
  4. djvu2pdf script by Christoph Sieghart
Option 3 is what worked well for me.

If djview4 was not easy to install using apt-get, then I would probably have taken a closer look at option 4, however having tried the Export feature of djview4, I am happy with the result.


'Export As' option of djview4:

Allows you to set a dpi for the output and 300 dpi was quite readable.
( The original .djvu was good quality so I could afford to be a bit lossy )


There is also an option to adjust the .jpeg compression, but I left it unchanged at 75%.



Best results are often obtained by using format A viewer, and 'Export':

What I meant by this is best illustrated by describing the alternative...

Less preferred alternative:
Having done the conversion to .ps, implicitly* or explicitly, open the file using 'Document Viewer' / Evince / Okular and try exporting.

The above may work, but for me, seems to be a less reliable way of attacking the problem.

Yes, Yes, cups has a pdf output helper

Yes, Yes, Okular has 'Print to file' option

However my experience was that viewing in a native .djvu reader (not Evince or Okular), and Exporting produced the most reliable result.


*ps/pdf viewer software will often open a .djvu file, but in the background, what really happened was probably a quick 'on the fly' conversion.

Tuesday, November 2, 2010

LibreOffice / OpenOffice - Where did my 'Formatting' toolbar go?

The toolbars in LibreOffice / OpenOffice are unlocked by default.

Whilst this is great for usability, it makes it easy to lose a toolbar also.

So you go into your application Writer and here is what you see:

When you would normally have above the "1 2 3 4 5" ruler something that mentioned Fonts and Font sizes???

...and here is what you are missing:


In most cases it is just a case of ticking the checkbox in View -> Toolbars -> Formatting
and hopefully it reappears.

But what if View -> Toolbars -> Formatting is already checked?



Well as toolbars are unlocked by default, it is all too easy to drag them off somewhere by mistake.
Maybe the family were around and little Bernard clicked on the Word Processor icon and had a little play around. Or perhaps you had your finger pressed on the mouse and somebody talked to you from the side.
It is easily done.

In my case, the toolbar had been moved to the right of the main toolbar and was not easy to see at first glance. But having located it, then it is just a case of dragging it back to where it should be (below the main "File | Edit | View" toolbar.

The little grabber  is marked as 5 horizontal lines on top of each other, and if you hover over it then you should see a four pointed symbol, which indicates that you are about to perform a move.


So you have used the grabber (shown above) and pulled the toolbar back to where you usually like to see it.


Locking toolbars - a must really:

I have used OpenOffice for many years, and have never felt the need to move toolbars about. However, I know some folks like to move them to be down the sides or whatever their preference is.

So for me personally, unlocked toolbars are a waste.

Unless you feel the need to move things about then I would recommend for each of the toolbars, that you 'Lock Toolbar position' as shown here:


To the right of each toolbar there should be a little icon which has an arrow at the base and is clickable.
When you click it then the drop down menu (shown above) should appear, and you should 'Lock Toolbar Position'

Having the toolbars locked, means you can leave the computer on, and little Bernard at the controls, and your toolbars will still be there when you check later :)


Ubuntu and LibreOffice / OpenOffice:

Ubuntu have their own desktop 'look and feel', which gets tweaked slightly with each release.
The default themes are pretty usable by my reckoning, however when the application themes are touched up to bring them into line with the desktop themes, then sometimes there is an oversight.

What I found when I used an Ubuntu Lucid machine recently, was that OpenOffice had been touched up to bring it into line with the desktop theme, and in the process the little grabber was either hard to see or missing.

To reiterate: If you are using Ubuntu and cannot find the little grabber (shown below)...

...then just grab a bit of greyspace where the grabber should be, and you should be able to move that way.

Whilst this is not ideal, it is the price you pay for using a Linux Distribution which puts a high priority on Desktop themes and consistent look and feel.

I prefer Debian, where the defaults do not involve tinkering with the Application look and feel, (although I am free to switch on a different application theme (say crystal) from within Writer itself)