Thursday, December 20, 2012

How to print multiple pages per sheet (even strange values)

I was using psnup to generate ps/pdf files with multiple pages per sheet...

but one day I needed to arrange 24 pages per sheet (it was a thumbnail document, one small image per page...) and I did not manage to make it work with psnup..

this solved my problem:
pdfjam --suffix nup --noautoscale true --nup '4x6' inputfile.pdf


Tuesday, December 18, 2012

How to make an A5 sized booklet with A4 paper

Actually it is very easy to make an A4 sized booklet, and you can find this option even in some printer's settings..

With A4 sized booklet I mean printing the pages with A5 size, landscape, on A4 sheet so that if you take the printed papers and you fold in half you obtain a sort of book.

Actually it is a little bit harder to make a booklet with A5 paper.. and the main reason is that I do not have A5 paper..
Another reason is that in my opinion it is easier to print on A4 sheets without trouble (i.e. without feeding and paper alignment problems)

So here what I did:

  • take your pdf and convert to postscript: pdftops in.pdf
  • make a standard booklet ordered document: psbook
  • (here is the tricky part) insert two blank pages every two pages (this is explained later)
  • print to a new file, 4 pages per page (i did this because with evince i could not print double sided, but with other programs it added extra margins)
  • print this last document two sided, with the printer.. (eventually to save some paper you can print the first half pages (two sided), then turn the sheets and print the remaining pages on the other half of the sheets)
  • cut the pages and place them in the correct order

It sounds tricky but it is the simplest solution I found...

As you probably understood I inserted the blank pages to print only on the top half of each sheet.. this is necessary since I did not find a software able to order the pages for this kind of booklet.

To insert the blank pages I used two scripts:

if [ $# -ne 3 ]
  echo "Usage example: ./pdfInsertBlankPageAt 5 src.pdf res.pdf"
  exit $E_BADARGS
  pdftk A=$2 B=blank.pdf cat A1-$(($1-1)) B1 A$1-end output $3

require "optparse"
options = {:default => "args"}
ARGV.options do |opts|
opts.banner = "Usage:  #{File.basename($PROGRAM_NAME)} [OPTIONS] OTHER_ARGS"
opts.separator ""
opts.separator "Specific Options:"
opts.on( "-p pages", "--pages", Integer,
        "Num of pages" ) do |opt|
options[:pages] = opt
opts.separator "Common Options:"
opts.on( "-h", "--help",
        "Show this message." ) do
puts opts
puts opts
pdf = ARGV[0].chomp
range = (3..options[:pages]).step(2)
range.reverse_each do |pagenum|
%x{./pdfibpa #{pagenum} #{pdf} tmp#{pdf}}
%x{./pdfibpa #{pagenum} tmp#{pdf} #{pdf}}

The first script is a shell script which inserts a page at a specified position. I named it pdfibpa.. I generated a blank page (blank.pdf) to do the trick..

The second script is a ruby script which adds two blank pages every two pages...

Maybe in the future I will build a simpler solution and publish a gem..

Sunday, September 2, 2012

How to make a screencast video with ubuntu

Sometimes I needed to make some screencast videos, for example when I do magic with Sublime Text 2 sometimes I want to record it ;)

I found that xvidcap works very well

Paper Reference Manager

Some time ago I started using mendeley, to organize some papers but I got soon disappointed..
The user interface of the client software is quite unusable..

First of all the tag management is not effective, since to add a tag is a pain: click, write, click in another place to remove focus (otherwise you can not do anything.. not even switching workspace) without any keyboard shortcut!
Also searching for tags is frustrating.. you can not save searches and if you search for tag 'read' you will also find papers with tag 'toread'..
Another bad point is the sort order: spaces are ignored so 'a zebra' comes after 'an elephant', since z>n but if you make a list of titles everywhere else, the sorting keeps spaces into account.. hence you will have mismatching lists..

A good feature of mendeley desktop, for which I kept mendeley for some time, is the internal editor, that allows for highlights and notes..


Zotero have shortcuts, save advanced searches, notes, tag management and if you open pdfs with okular you can even highlight or add notes into pdf..

I'll try zotero for a while, syncing pdfs with dropbox...

Thursday, August 23, 2012

Ruby helps in gaming

Recently I found the game Clockwords: prelude ( in which you have to write words to shoot letters and kill spiders.

Well after some levels the game become boring so I decided to find another solution... thanks to the xsendkeycode command and a simple ruby script...

first of all install xsendkeycode by typing
sudo apt-get install lineakd
then copy and paste this code into a file, make it executable and run it.
#!/usr/bin/env ruby
words = [
keycodes = {
'q' => 24,
'w' => 25,
'e' => 26,
'r' => 27,
't' => 28,
'y' => 29,
'u' => 30,
'i' => 31,
'o' => 32,
'p' => 33,
'a' => 38,
's' => 39,
'd' => 40,
'f' => 41,
'g' => 42,
'h' => 43,
'j' => 44,
'k' => 45,
'l' => 46,
'z' => 52,
'x' => 53,
'c' => 54,
'v' => 55,
'b' => 56,
'n' => 57,
'm' => 58
sleep 2
words.each do |word|
  word.each_char do |letter|
    `xsendkeycode #{keycodes[letter]} 1`
     sleep 0.2
     `xsendkeycode #{keycodes[letter]} 0`
  `xsendkeycode 36 1`
  sleep 0.2
  `xsendkeycode 36 0`

note that you need to quickly switch to the game windows and focus the game area with a click.
You also need to interrupt the script (ctrl+c) when the match is finished..

Long words are not the best.. I lost at level 9.. maybe short words with lots of letters contained in the boiler are the best.

Thursday, July 19, 2012

Ruby serialport and the missing byte

While developing a project @iralab about an Arm Cortex board which should control a DC motor, I found a very strange behaviour: sometimes I received from the serial port only 89/90 bytes.. other times 3/4 and so on..

So I googled something like 'ruby serialport missing byte' and I found a lot of useful hints such as

Unluckily none of these worked...

After some debug i found that only some chars were not sent/received.. 0xa0 to 0xbf..

And then I realized what I was doing wrong! I used the getc method to read from serial!
Switching to getbyte completely fixed the problem.

Here some reference:

Hope it helps

Friday, May 18, 2012

How to change the keyboard's layout and make this persistent in ubuntu

I recently decided to switch to the USA keyboard layout which seems to be more comfortable for programmers.
I found very disappointing that after reboot the layout rolled back to Italian even if that layout had been deleted.

The solution is very simple: just pay attention at the login screen and choose the keyboard layout you want from the lower bar!

FYI it is useful to set from the keyboard preferences the compose key (I chose the right alt) to make letters with accents:

  • compose_key + ` + letter = à ẁ è ì ò ù..
  • compose_key + ' + letter = á ẃ é í ó ú..
  • compose_key + - + letter = āūīōē..
  • compose_key + , + letter = ąȩįųģ..
  • compose_key + . + letter = ȧėıȯḣġḟḋṡ...
  • compose_key + ; + letter = ąęųįǫ
  • for others you can look here:

Friday, April 27, 2012

Pirelli DP-L10 disassembly

This is how the phone looks like (actually the screen should not be broken but in my case I had a broken one to disassemble :P)

First of all you have to remove the lid on the back, pressing the opening button.
Then you need to remove the camera cover, passing a credit card on the two sides. Note that on the right part, looking at the picture above there are two blocks while on the left there is only one.

Then you can remove the four torks screws (you can use a flat screwdriver).
With the same credit card, or gently with the screwdriver, unlock the two sides as in the picture below.

After that you can separate the top cover.

From the top cover you can remove the keyboard. From the board you have to remove by pulling (there is only some glue to keep it) the keyboard counterpart. In this way you will reveal two other screws.

The board is now attached to the cover only through the speaker. you can remove it (again only some glue) and disconnect from the board pulling (remember, the red wire towards the middle). 

From the top cover you can remove the other speaker.
Now to remove the camera housing, pull gently the two blocks on the sides

Disconnect the two links (red wire towards the top) and the camera is free.

Now remove the metal screen cover, paying attention to the two little blocks on the top sides. just lever a little bit with the screwdriver. 

After that you can disconnect the screen. If you want you can lever up the metal covers to reveal other components.

Now we will look into the camera and the screen.
For the camera remove the speaker and lever in the hole thus revealed.   

The camera is inside!

For the screen it's easier if you remove the shiny paper on the back

and then press to remove the plastic housing

That's it! Follow the instructions backwards to mount it again

Friday, March 23, 2012

How to change Gnome-Terminal (tab) title from the command line

With lot of terminals opened it is quite hard to choose the right one..
Also with terminal tabs (ctrl+shift+t) would be useful to have a per tab title.

To do so you have to comment a line into your ~/.bashrc and in particular where it says
# If this is an xterm set the title to user@host:dir
comment with a '#' the line

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

after that you can install xtitle
sudo apt-get install xtitle
and then use
xtitle newtitle 
or do it manually with
echo -en "\033]2;newtitle\007"


Friday, February 17, 2012

Paymo and the Pomodoro tecnique

Yesterday I read an article on an old issue of PragPub (by the way, you need to check this out) about the Pomodoro tecnique. I found it (the Pomodoro) very interesting because simple but effective so I decided to try it myself.
Since I have been using Paymo for personal time tracking, I tried to use it also for the Pomodoro tecnique but it didn't fit so much. If only the timer could automatically stop at 25 minutes, maybe with an alert..
Hey, I can do that! Google chrome supports userscripts (greasemonkey for firefox stuff)!!
So I wrote a simple script that adds a new button in the paymo timer, near the "Start" one: now you can "Start a Pomodoro" and after 25 minutes the timer stops with an alert about the end of the Pomodoro.
Here some useful links:

Sunday, January 8, 2012

How to install italian spellchecker dictionary for lyx

Lyx uses hunspell to spellcheck, so you have to install hunspell italian dictionary.
To do this download the zip file from in the dictionaries section. Inside the zip file you will find the files it_IT.aff and it_IT.dic: copy that files into /usr/share/hunspell/

if not activate checkspelling in lyx (choose enchant as spellchecker engine in tools->preferences->language settings->spellchecker)
it is also useful to check "spellcheck continuously" which means that every word is checked as soon as it's written.

that's all

Saturday, January 7, 2012

Ubuntu theme changed autonomously

Sometimes happens...
Today i started my notebook and i found that the theme was changed.. i didnt like it and i wanted to bring it back.
I found that was a gnome-settings-daemon problem. To solve you have to restart that daemon loggin in again or in the command line:

  • kill the daemon if active:
ps aux | grep gnome-settings-daemon
the first number from the left is the process id.. then
sudo kill pid
where pid is the process id found before
otherwise just use 
sudo killall gnome-settings-daemon

  • start the daemon