Software Tips

  • Here are the steps to debug your Android app from WiFi connection instead of WiFi:

    - connect the device to the PC by USB cable

    - adb tcpip 5555

    - disconnect the device

    - adb connect <IP address of your device>:5555

  • I was getting "no space left on device error" when I tried to restart my php5-fpm process. The server was a Ubuntu Linux on Amazon AWS (small instance). df command said I had plenty of space, so there must be another problem:

  • I needed to disable InnoDB support on my tiny server to save memory. To achieve this, I first had to convert the storage engine of all tables in all databases.

    echo "show databases;" | mysql -uroot -p[your password] | grep -v "Database" | grep -v "information_schema" | grep -v "test" | grep -v "mysql" | grep -v "performance_schema" > mysql-dbs.txt

  • Create an EBS volume of prefered size. It must be in the same availability zone with your existing instance.

    Attach the volume to the instance

    Check the volume device id
        fdisk -l

    Partition the volume, in my case the device id was /dev/xvdf
        mkfs.ext3 /dev/xvdf

    Create mount point the new volume
        mkdir -p /media/disk1

    Mount it
        mount /dev/xvdf /media/disk1

    Create fstab entry for automatic mounting at boot time
        nano /etc/fstab

  • By default, MySQL treats all fields as case-insensitive. Here is how to change this behavior for some fields in a table or for a specific SELECT query:

    for table fields:
    If you set the field collation as utf8_binary instead of utf8_general_ci (or similar), that field will be case sensitive.

    for select queries:
    SELECT * FROM table_name WHERE BINARY field LIKE '%keyword%'

  • Installation of APC for PHP on Ubuntu is as simple as typing two lines of shell commands:

    sudo apt-get install php-apc
    sudo /etc/init.d/apache2 restart

    Update 2019: As of PHP 7.x, PHP has an internal accelerator OpCache that is a better choice than APC.

  • Here are some quick steps for creating swap partition on Amazon AWS Micro Instance:

    dd if=/dev/zero of=/swapfile bs=1M count=1024

    mkswap /swapfile

    swapon /swapfile

    add the following to /etc/fstab to enable the swap on boot:

    /swapfile swap swap defaults 0 0


  • I had problems with displaying UTF-8 characters in my exported CSV files. Unlike LibreOffice Calc and Google Docs, this happened on only MS Excel. Here is a small hack:

    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . strlen($str) ."; ");
    header("Content-Disposition: attachment; filename=\"ourfilename.csv\"; ");
    header("Content-Type: application/");
    echo "\xEF\xBB\xBF"; // UTF-8 BOM
    echo $str;

  • Create root password for MySQL:
    mysqladmin -u root password NEWPASSWORD

    Update root password for MySQL:
    mysqladmin -u root -p'oldpassword' password NEWPASSWORD

  • If you would like to take periodic backups of your MySQL database, you can do it easily with cron:

    open crontab file:
    nano /etc/crontab

    add the following line at the end of file:
    */15 * * * *       root    /usr/bin/mysqldump -u<mysql_user> -p<mysql_password> <database_name> > <directory-to-save>-<file-prefix>`/bin/date +\%Y\%m\%d-\%H\%m`.sql
    (the above line orders cron to get your backup every 15 minutes)