domenica 5 novembre 2017

UBUNTU - Reduce PDF file size with pdf2gs and gs2pdf

First convert pdf to ghostscript:
pdf2ps file1.pdf file2.ps
then reconvert ghostscript to pdf:
ps2pdf file2.ps file3.pdf
file3.pdf is smaller about 50% than file1.pdf bye

UBUNTU - Batch convert SVG files to PDF and join them in a single PDF

I extracted SVG pictures from a site that allow me only to see the files and not to download it with Chrome browser and this extension:

https://chrome.google.com/webstore/detail/export-svg-with-style/dkjdcaddoplepioppogpckelchefhddi?utm_source=chrome-app-launcher-info-dialog

The result is a bunch of SVG files numbered progressively (e.g saved0.svg,saved1.svg....,saved45.svg).
I renamed the first 10 files saved0.svg to saved9.svg to saved00.svg..saved09.svg to avoid problems when merging all pages together. I moved all in a folder and applied this little bash script:



paste it in new file give it execution permission ( chmod 755 filename)
 I dropped the script in the same folder but you can put in /usr/bin to have it always ready ..
The script simply check all files on the folder, verify if they are svg files and attempt comversion to pdf.
The result should be a bunch of pdf files numbered progressively (e.g saved0.pdf,saved1.pdf....,saved45.pdf).


Now with pdftk we can join all single pdf pages lying in the folder in one single file (You need an ordered sequence of files to do it).

pdftk *.pdf cat output FILE.pdf

That's all

mercoledì 22 marzo 2017

BUSYBOX - SSHing to a W-Gate Router

I had to ssh ing to this box running a a stripped version of BusyBox witha really tiny ssh server support with Dropbear that wasn't accepting connection from a regular ssh client on Ubuntu.
After succesfully trying connecting with the dbclient (the dropbear client that acts more or less as a ssh client) , dbclient that is available in ubuntu official software I have noticed that thas box need a specific kind of MAC (Message Authentication Code) algorithm to connect.



Using this option ( -o MACs=hmac-sha1 ) the ssh client connected succesfully letting me make the tunnel that I wanted:


ssh -o MACs=hmac-sha1 -vvvl user ip


mercoledì 15 marzo 2017

UBUNTU - pdftk to join 2 pdf, one wiht odd pages and one with even pages

I have 2 files resulting from my network scanner yet in pdf format.
One file has all even pages with correct order ( Pari.pdf ).
The other has all odd pages but with inverted order (Dispari_invertite.pdf)
The document will start with an even page and then I have to shuffle page one by one from every source file.

This is the (impressive for me) one command solution:




pdftk A=Pari.pdf B=Dispari_invertite.pdf shuffle A Bend-1 output collated.pdf


I assume that you have been entered in the working folder before. The "Bend-1" option reverse the order of B file; so if you need to join 2 ordered odd and even files will use "B" instead. Collated.pdf is the output file of course. For me its an impressive one line command that make me love linux terminal to make things quicker and better than installing a lot of dedicated software. Bye

mercoledì 11 maggio 2016

OPENWRT - Using Sanguinololu as USB to serial adapter USB2TTL

I had to connect to the serial interface of a router with OpenWRT, the router is Pirelli AGPF .
My old cable (a CA42 Nokia Cable) was broken, so I tryed with a crappy usb 2 serial adapter with ch340 chip with no luck.

I remeber I have a spare Sanguinololu board that I buyed to replace my old one on my 3D Printer. I have seen is possible to use an Arduino Uno to act as usb to serial interface, so I thinked the Sanguinololu could do the same.

Ok, let me explain...

IMPORTANT : To enable the serial socket we need to short the reset pin to the ground in some way, I used an old jumper to keep the board resetted.

Under the USB female port of the Sanguinololu there is a socket labelled USB2TTL , in my case nothing is soldered to it.
We will use Tx , Rx and Ground on USB2TTL socket.

Could be a good idea to test the socket firing up your favourite program (hyperterminal, putty, minicom ecc) shorting Tx with Rx and check if typing something there is a return on the console.

If you want you can solder some male pins to Rx  , Tx and GND but I found a less invasive solution.
Looking the ATMEGA pinout http://reprap.org/wiki/Sanguinololu#Pin_Assignments

I found these pins on ATMEGA socket that are connected to the corrispective pins under the USB port:
  •  ftdi Tx on pin 14
  •  ftdi Rx on pin 15 
  •  GND on pin 31
So I removed the ATMEGA chip and inserted 3 needles on that and used alligator clips to connect to my router Rx , Tx and GND.

Aggiungi didascalia

This solution seems intresting because is fully reversible without soldering nothing on Sanguinololu board.

Maybe could work in other similar platform where there is an arduino-like board.

By the way .. ther router was successfully recovered.




martedì 22 settembre 2015

UBUNTU - DU (Disk usage)

Per vedere le dimensioni di tutti i file e le cartelle al livello 1  ( non entra nelle sottocartelle)

To show dimension of each file and folder at level 1 (not entering inside subfolders)


du -h -d 1 -t 1G


-h stands for "human readable" (show M for megabytes, G for gigabytes and so on)
-d deep of the folder search
-t threshold size (file bigger than 1 GB)