Monday, November 28, 2011

How to eject an usb storage device like kindle from command line

If you are working with a kindle, trying to convert some books into kindle format, it's frequent to plug and unplug the device to check if the file is rendered correctly.
Doing this with the graphical interface is of course annoying.
Luckily you can easily use the command line (and maybe automate the conversion and copy with a command line application).
First of all you have to find the name of your device using
sudo fdisk -l
You will see an output like this one
Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c83e7
Device Boot      Start         End      Blocks   Id  System
/dev/sda2               1       29179   234374145    5  Extended 
Partition table entries are not in disk order
Disk /dev/sdb: 3282 MB, 3282272256 bytes
4 heads, 16 sectors/track, 100167 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      100167     3205336    b  W95 FAT32
Of course the device is sdb1: now you can eject typing
sudo eject /dev/sdb
 to "uneject" a trick is to use the command
sudo eject -t /dev/sdb
which sends a tray close cdrom command, that actually reconnects the kindle. 

Monday, November 14, 2011

How to bypass the hp smart pin

Some Hp laptops have a strange connector, with 3 poles:
  • pwr
  • gnd
  • smart pin
Of course the smart pin is so smart that without it the computer won't turn on.
If you want to bypass it you can simply add a resistor between voltage and the smart pin.
430k will be good.

NOTE: Without the resistor, connecting the smart pin to pwr directly, the computer will turn on but it will be extremely slow

How to create an ebook from a website

If you want to put a webpage on your kindle the best idea is to convert that page into an ebook.
You can do this simply by saving the page and converting it with Calibre.
What if the document is divided into different pages?
With calibre is very simple:
  • Download all the pages
  • Download also the first page with the links to the chapters
  • edit the first page so that the links are local (remove leave only chapterX.html)
  • Open calibre and import the first page
  • Convert it to mobi or whatever format you like
The book will be complete with all chapters

Monday, October 24, 2011

Batch resize images to be uploaded to picasa web album

Probably you know that images smaller than 2048px on the biggest dimension does not count for the occupied space on picasaweb if you are a member of google plus (if you are no I think the limit is 800px).
Accordingly, if you want to resize some photos you can use imagemagick
mogrify -resize '2048x2048' img.jpg
with this command imagemagick will resize the image to fit the 2048x2048 square: we will obtain the longer dimension to be 2048 and the shorter a number smaller than 2048 to mantain the aspect ratio.

Sunday, July 17, 2011

Drupal - Using uploaded files without manually changing file permissions

Short fix, followed by longer explanation:

Go to /admin/settings/file-system , set Download Method to "Private - files are transferred by Drupal", save the settings, and see if you are now able to access the uploaded files.

The longer explanation:

Depending on the setup of the web server, uploaded files will be saved with permissions 644, or 600, or maybe something else. Permissions 644 allow ALL server users to read the files, permissions 600 allow only the user that saved the files to read them.
The thing is - the user that "owns" the files (the one that saves them to disk) is a special one, used only by the web server program to do its work. It's not the account you use to administrate the web site - to login to cpanel or FTP. Because of this, sometimes even when you FTP to the site as admin, you cannot remove the uploaded files.
In my case, the files are saved with permissions 600, AND the user that owns them is not the same user Apache uses. So, the web server program cannot read them. I'm assuming my web hosting company uses different users for PHP processes and Apache processes, and the uploaded files are owned by the PHP user. For me, the simplest solution was to use PHP to read the files back to the user, by setting the download method to "Private - files are transferred by Drupal" in the admin page "/admin/settings/file-system".
Hope this helps.

Tuesday, July 12, 2011

Android update for lg gw620

I confirm that the update is available.
I've got some trouble for the update but now seems to work.
During the update i went through some problems:

  • windows alerted me that the software was not responding. i closed and restarted the update
  • after the update (at 99%) the mobile reboots. The first time it told me "linux kernel panic" (i was like omg!) but then the update software told me wat to do ("i lost the connection with te mobile, please remove the battery and restart the phone, then click restore")
Finally i have froyo on my phone

Some notes on the update:

  • after the download (about 150MB), during the install at 4% the mobile reboots in recovery mode (don't panic!)
  • restarting the install does not seem to be a problem
  • after the install (long time to turn on the first time) it restores prefs, contacts and so on.. (but please backup all the data anyway)
Related posts:

Monday, July 11, 2011

How to connect lg gw620 to windows for software updates

Recently lg announced an official android update to froyo for gw620!
you can read the news from their blog (in italian)

so it's important to know how to update your software
NOTE: from their post is clear that the update is available only by explicit request through email

So install the lg software from, from the setting menu of your mobile disable usb debug (menu -> settings -> application -> enable usb debug), install the drivers from the software selecting the model, connect your phone and it's done.

actually i'm waiting for the response from lg to get the official update.. i hope to update this post shortly!

Wednesday, July 6, 2011

How to add a wpa 2 enterprise network on android 1.5

Get root console access (look for that in this blog) and edit the /data/misc/wifi/wpa_supplicant.conf adding the network.
Wpa supplicant is standard unix so you can easily find informations on how to set up the network.
here is an example that worked for me (actually i have to test it on the mobile but i'm sure the wpa_supplicant works)

    ssid="yourssid (network's name)"
    ca_cert="/sdcard/cert/ca.pem file (the file of the CA)"
    private_key="/sdcard/cert/cert.p12 (the cert file)"
    private_key_passwd="password of the cert"

this sets the network for access with a certificate which is on the sd card in the cert folder

NOTE: i have tested this trick on my enterprise network and it did not work. After a few try the network manager crashed and the phone was not turning on (seems like lagging on the boot). I solved simply moving outside the range of the wifi network and disabling wifi on the phone. I hope to solve this problem quickly

Monday, July 4, 2011

How to root lg gw620

Original article:

rooting your LG Eve GW620 Now! (all credit to Zacpod)
Now onto the actual root. All this is taken from Zacpod’s excellent post found here: I’ll be copying it almost verbatim, and I hope he doesn’t mind
  1. Download the Superuser Whitelist ( and unzip it somewhere safe such as c:\SDK\tools\
  2. On the GW620 dial "3845#*620#" to get in to the secret menu
  3. Tap "Module Test" then tap "Stability Test" then tap "Enable Root Permission"
  4. Open a Command Prompt on Windows by pressing Windows Key + R, then type "cmd" in the empty field. Note, you should also run this with Administrator rights. Linux users can use Terminal.
Navigate to your installed Android SDK (ie: "cd c:\SDK\tools\").
  1. Type "adb shell"
  2. You should get a #. If you get a $ then something didn’t work. Shutdown the phone and PC and try again. If you get a # then all is well. Type "exit" to return to your PCs command prompt.
  3. Type "adb remount" to remount the GW620′s file system as read-write so we can make changes.
  4. Type "adb shell cat /system/xbin/su > /system/xbin/su.original" [Note: This step may give you a "could not find path" error. Just continue on with step 5 and the root will still work.] 
    1. NOTE: this step is very important: it backs up the original file which will be overwritten. You can try (it worked for me) to type "adb shell" getting the # root shell and then the command"cat /system/xbin/su > /system/xbin/su.original"
  5. Type "adb push bin/su /system/xbin/su"
  6. Type "adb push bin/su /system/bin/su"
  7. Type "adb shell chmod 4755 /system/xbin/su"
  8. Type "adb shell chmod 4755 /system/bin/su"
  9. Type "adb install bin/Superuser.apk"
Caution: I’m not the author, and any time you root your LG Eve GW620, you run the risk of bricking your phone. I will not be liable. However, if you need some help, go here.

Saturday, July 2, 2011

How to discover system info in terminal

Here some useful commands to discover hardware and software infos

  • cat /etc/*-release -> os version
  • uname -a -> os and kernel info
  • lscpu -> cpu info
  • cat /proc/cpuinfo -> cpu info
  • cat /proc/meminfo -> ram/mem info

Thursday, June 9, 2011

install zend framework for local testing on ubuntu

first of all you have to install apache, php, mysql

sudo apt-get install php5 mysql-server apache2
its useful to add mod rewrite
sudo a2enmod
then choose rewrite

now download and install zend framework

follow the tutorial to create the first project.
some hints:
- add alias for zf (maybe in .bashrc)
alias zf='/opt/zend/share/ZendFramework/bin/'
- after creating the project (zf create project projectName) add a symlink (or copy) the zend library folder

cd library; ln -s path/to/ZendFramework/library/Zend .

cd library; cp -r path/to/ZendFramework/library/Zend .

add the virtual host in /etc/apache2/httpd.conf

this allows to have more virtual servers automatically selected by the url

Friday, May 27, 2011

install flash on ubuntu, firefox 64bit

To "install" flash for 64bit you have to download the right version of the flash player (64bit linux, very easy)
then you have to locate the firefox's plugins folder. mine was in /usr/lib/firefox-4.0.1/plugins and extract here the .so library you just downloaded.

to extract the file in the command line you can use
tar -xf filename
where x means extract and f means filename

Monday, May 9, 2011

Converting numbers to hex in ubuntu terminal

I found out that to insert characters by ascii number one way is to type ctrl+shift+u and then the hex number of the char

To find the hex you can use in terminal

printf "%x\n" 34

to find the code of a char or special char that you have on the keyboard type for example

printf "%x\n" "'{'"

Wednesday, April 20, 2011

Backup under ubuntu

In a previous post i introduced a backup software with up to 5gb of free space (

Now i would like to talk about some programs to backup folders locally or via ssh:
RSYNC provides a very powerful incremental backup solution (unison is a gui for rsync)
RDIFF-BACKUP instead is very similaro to rsync but has an interesting feature: it saves incrementally different versions of your backup so that you can restore the backup files of a certain date. It works more or less like a version control system (svn) but it does not use a databse, it just creates a folder in the backup. pybackpack is a nice gui for that.

you can install all these programs by running in terminal
sudo apt-get install [name]

for example
sudo apt-get install rdiff-backup

Sunday, March 6, 2011

How to give name to a remote host in ubuntu

If you often use ssh, scp and programs that require a host and the host is an ip address you would appreciate this post.

You can give a local name to a ip address adding a record in the /etc/hosts file
sudo gedit /etc/hosts
add a line suck as [tab to separate address from name] hostwhoseipidontremember

now if you used to type ssh now you can type ssh hostwhoseipidontremember with the same results

Wednesday, February 23, 2011

How to make a pc connect to hamachi lan without login

This post contains the solutions for two main problems:
1. You have Fastweb as a provider so you can not access your computer from outside the fw network
2. You can't leave your pc turned on (but there is no one able to turn it on if they have to do "strange operations" such as.. a login under linux!)

1. The solution to the point 1 is very simple: install logmein hamachi.
Hamachi is a free software available for windows and linux that allows you to easily create a network up to 16 workstations.
You can download the linux version from the labs.

After that create a free account and a new network from your control panel on the logmein site. Take note of the network id.

Open a terminal and type
sudo hamachi attach-net yourLoginName

now return to the site and approve the request of the client (optionally you can set a identification name for the pc you are using with sudo hamachi set-nick nickname)

now with sudo hamachi you can see your status as logged in and with sudo hamachi list you can see the network.

if you make this operation on another pc you will see the two pcs with sudo hamachi list with a new ip address specified.

You can use that ip to connect for example with ssh!

2. Now if you could have a pc always turned on... but you can't.. well the best solution I found is to make the hamachi connection start before login. So you only need someone to turn on the pc to connect without anyone insert your password locally..

this is very simple to achieve.. you only need to remove networkmanager and install the more competitive wicd..
sudo apt-get remove network-manager -purge
sudo apt-get install wicd
use wicd to configure your lan/wlan.. it automatically starts before login..
hamachi autostarts before login.. that's it..

if it doesn't works try adding in /etc/rc2.d

/etc/rc2.d/S11logmein-hamachi start

Tuesday, February 15, 2011

Math operations with decimals in ubuntu shell

The shell usually doesn't support operations with floating point numbers, but only with integers.

If you need to do something like 3.5*2 you will have to use a tool like bc:

echo "3.5*2" | bc

you can decide the number of decimals to use
echo "scale=2; 3.5135131*2" | bc

but there is a little bug: scale doesn't work with multiplications!!!
A little workaround is
echo "scale=2; 3.5135131*2/1" | bc

You will obtain the expected answer

Monday, February 7, 2011

How to refresh a just uploaded favicon

After uploading a new favicon for our site, Firefox will display the cached image for a while.
If you want to see immediately the new favicon visit the file in firefox (something like and reload the page (maybe with ctrl+f5)

Wednesday, January 26, 2011

How to create ebooks for kindle

Actually it's not so easy to understand how to format correctly a document to be viewed in a kindle, and I am also trying to find a good way to do that.
This is a nice way I found:

A good format to be converted into mobi (kindle ebook format) is html or rtf.
To create a good book in html you can use Lyx with the elyxer extension to export in html:
sudo apt-get install lyx
sudo apt-get install elyxer

After that you will be able to File>Export>HTML

Once you have an html file I suggest to use a software like Calibre to organize, convert and put on your kindle your ebooks.

- I noticed (in the book I converted) that html head section generates some errors in the visualization so I left only the body

Friday, January 21, 2011

How to recover deleted files under Windows

I suggest to try Recuva by Piriform. It's free and it allows to recover all the deleted files found.