Android – how to develop directly on a phone

There are severe problem with using the Android Emulator on a netbook / mini-laptop.

It is much better to use your phone. That’s it: you develop on Eclipse and run and debug the program directly on your phone.

In order to do this you need 3 steps:

  • set up Eclipse to be able to develop for Android (basically install the ADT plugin) as explained here: http://developer.android.com/sdk/eclipse-adt.html#installing
  • link the mobile and your development workstation with the USB cable that comes with the phone
  • enable logging on your Android device to be able to debug:
    • echo 1 > /sys/kernel/logger/log_main/enable // ** ’1′ is enable log_main
    • echo 2 >/sys/kernel/logger/log_main/priority // ** ’2′ is the log level

Now, you can install your application on the device by doing:
/home/dan/android-sdk-linux_x86/tools/adb install -r /home/dan/MyAppForAndroid/bin/MyAppForAndroid.apk

You can uninstall the application by doing:

/home/dan/android-sdk-linux_x86/tools/adb uninstall com.myapp.android.app

You can check the log on the device:

/home/dan/android-sdk-linux_x86/tools/adb logcat

You can check the log on the device, restricting to the messages from your application:

/home/dan/android-sdk-linux_x86/tools/adb logcat | grep ‘MyApp’

You can reset the log:

/home/dan/android-sdk-linux_x86/tools/adb logcat -c

In your application you can add an entry to the log:

Log.e(“MYAPP”, “message to log”);

If you want to log the whole backtrace of an exception:

try {
// code buggy code
} catch (Exception e)
Log.e(“MYAPP”, “exception”, e);
}
Posted in Android | Leave a comment

Android drawable default icons – they are free to use

http://androiddrawableexplorer.appspot.com/

Posted in Android | Leave a comment

Android how to read and write files

http://huuah.com/android-writing-and-reading-files/

Posted in Android | Leave a comment

Uncompress on the fly when copying a file from a remove location with scp

Don’t use scp, do it with ssh:

ssh backups@server "cat /home/backups/backup_2010-09-27.tar.gz"| tar zxvf -

You can probably use something similar also for:
Compress on the fly when copying a file from a remove location with scp

Posted in Linux Command Line | Tagged , | Leave a comment

Setting up an encrypted volume on an external hard drive on CentOS

Make sure the version of your kernel is 2.6.16 or later with support for device mappers.
Please replace XXXXX with the device Linux allocates the driver to (i.e.: /dev/sdc1). Use the dmesg command to find that out.

Preparing the volume
_ su
_ yum install lvm2 cryptsetup-luks
_ umount XXXXX
_ filling the HD with random stuff
/sbin/badblocks -c 10240 -s -w -t random -v XXXXX
_ /sbin/cryptsetup luksFormat –verbose –verify-passphrase XXXXX
_ opening the encrypted device and assign it to a virtual /dev/mapper/backup device:
/sbin/cryptsetup luksOpen XXXXX backup
_ creating a filesystem on the encrypted device:
/sbin/mkfs.ext3 -j -m 1 -O dir_index,filetype,sparse_super /dev/mapper/backup
_ creating a mount point for future use
mkdir /mnt/backup
_ closing the volume
/sbin/cryptsetup luksClose /dev/mapper/backup
_ probably you want to be able to open the device without typing a password. For that go to the “Using cryptsetup without typing a password” paragraph

Opening and mounting the volume:
_ su
_ /sbin/cryptsetup luksOpen XXXXX backup
_ mount /dev/mapper/backup /mnt/backup

Closing the volume:
_ umount /mnt/backup
_ /sbin/cryptsetup luksClose /dev/mapper/backup

Using cryptsetup without typing a password:
Set up:
_ Creating an binary file with the hash of a key:
hashalot -n 32 ripemd160 > volume_key
_ /sbin/cryptsetup luksAddKey XXXXX myvol
From then on you can open the volume this way, without typing a password:
_ /sbin/cryptsetup luksOpen -d volume_key XXXXX backup

Posted in Redhat / CentOS, System Administration | Leave a comment

Linux bash – tar tricks

Change directory:
tar xzvf /var/backups/dbserver/dbserver-backup*.tar.gz -C /var/backups/dbserver

Specifing the destination file:
tar --create -zvPh -f /tmp/backup.tar.gz /usr/local/bin /usr/local /etc/var/spool/cron /var/svn /home/*/.ssh /home/*/.bash*

Posted in Linux Command Line | Tagged | Leave a comment

Implement Selenium tests

Installing Selenium 1.0 and write tests with PHP
_ The documentation is very good: http://seleniumhq.org/docs/
_ Donwload Selenium RC from here: http://seleniumhq.org/download/
_ When you extract it, there will be a directory with the server and a
number of directories
with the clients, depending on the language you intend to use
_ The server will make the browser(s) available to the tests (so it must
have a graphical Desktop environment and the browser installed)
_ The tests will be launched on the client
_ Obviously client and server can sit on the same machine
_ To run the server:
java -jar selenium-server-1.0.3/selenium-server.jar
_ On the client you need to have PHPUnit installed in order to run the tests
_ In the directory selenium-php-client-driver-1.0.1 you have extracted,
create a new test file myTest.php , like this one:

< ?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
	public static $browsers = array(
			array('name' => 'Firefox on Linux',
			'browser' => '*firefox',
			// 'browser' => '*firefox /usr/bin/firefox',
			'host' => 'localhost',
			'port' => 4444,
			'timeout' => 30000,
			),
			array('name' => 'Chrome on Linux',
			'browser' => '*chrome /home/daniele/chrome/chrome-wrapper',
			'host' => 'localhost',
			'port' => 4444,
			'timeout' => 30000,
			)
		);
		protected function setUp()
		{
			$this->setBrowserUrl("http://www.mysite.com";);
		}

		public function testMyTestCase()
		{
			$this->open("/");
			$this->click("link=contactus");
			$this->waitForPageToLoad("30000");
			try {
				$this->assertTrue($this->isTextPresent("Hello"));
			} catch (PHPUnit_Framework_AssertionFailedError $e) {
				array_push($this->verificationErrors, $e->toString());
			}
		}
}
?>

_ to run the tests:
phpunit myTest.php

Posted in PHP, Web Development | Leave a comment

Using a downloaded package without IDE in Java

http://stackoverflow.com/questions/4093021/java-using-a-downloaded-package-without-ide

Posted in Java | Leave a comment

CSS selectors optimisation

From the last chapter of “Even faster websites”.
CSS selectors are matched right to left (!).
That means the rightmost selector should be as less broad as possible: you
should avoid * and tags as rightmost selectors.
The quickest selectors to be matched are:
_ id selectors (i.e.: #title)
_ tag selectors (i.e.: a)
_ class selectors (i.e.: .title)
Obviously id selectors are very easy to match.
Selectors like these are not easy to match but not too bad:
_ div > a
_ div + a
because you restrict the DOM the browser needs to analyse for each a tag.
This instead is quite heavy to match
_ div p a
because the browser needs to checks all the ascendants for all the a tags
It is not easy to know how much that impacts performance.
Anyway perfomances are impacted not only when loading the page at start but
also when creating or changing elements in the page with Javascript (the
browser needs to go through all the CSS rules for the new piece of HTML
code)
Posted in HTML / CSS | Leave a comment

Ubuntu Linux on Acer Aspire AO751h

Don’t use the Ubuntu Netbook Remix but the Desktop version.

To fix the monitor resolution:

https://wiki.ubuntu.com/HardwareSupportComponentsVideoCardsPoulsbo/

Wi-fi should work out of the box

Posted in Debian / Ubuntu / Kubuntu | Leave a comment