Clean up disk space taken by Docker

Show disk space used by docker images, containers and volumes.

1
2
3
4
5
6
7
$ docker system df

TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              5                   5                   1.722GB             784.5MB (45%)
Containers          5                   0                   78.12MB             78.12MB (100%)
Local Volumes       4                   4                   231.5MB             0B (0%)
Build Cache         0                   0                   0B                  0B

The docker prune command may be used with some docker objects like images, containers and volumes to free unused disk space.

Free space used by containers.

1
docker container prune

Free space used by volumes.

1
docker volume prune

In addition, you can use the docker system prune command to clean up multiple types of objects at once.

1
docker system prune -af

Start Android Emulator From Terminal

tip
Sometimes running the emulator from Android Studio doesn’t work and hangs with black screen. It can be started from terminal to avoid the problem.

By default the emulator is installed in ~/Library/Android/sdk/tools. To list all available Android Virtual Devices (AVD), use the following command:

1
2
3
4
5
6
./emulator -list-avds

Nexus_5X_API_28_x86
Nexus_S_API_15
Pixel_2_XL_API_28
Pixel_API_27

Run the following command to start the emulator from terminal:

1
./emulator -avd Nexus_S_API_15 -gpu host

Check out the docs for more emulator commands and flags.

Android 7+ Trace Files Location on Nexus 5X

The location where android trace files are stored on Nexus 5X with Android 7.0 is

1
/sdcard/Android/data/com.domain.myapp/files/filename.trace

After using the os.Debug class to generate trace files for an app

1
2
Debug.startMethodTracing("mytracefile");
Debug.stopMethodTracing();

the file can be pulled from the stored location like

1
adb pull /sdcard/Android/data/com.domain.myapp/files/mytracefile.trace

Useful Android ADB Commands

Show all events happening in the phone. The command is very useful for debugging transitions between activities, background, Home button, launcher icon start, notification icon start, etc.

1
adb logcat -b events

Show current tasks and activities running on your connected device:

1
adb shell dumpsys activity

Android ListView Optimizations

These tips are gathered from articles and Google IO videos. The items are not ordered by importance.

1. Reuse convertView

Always reuse convertView. This can improve the performance of ListView scrolling up to 50-60% percent, especially when ListView items are complex.

2. Use the Holder pattern if possible.

3. Remove realtime computation of the scrollbar thumb size

1
android:smoothScrollbar="false"

Android Timing Logger

The TimingLogger is useful to measure precisely the execution time of code blocks (or even just one line of code).

The Android docs show how it can be used. Below is a simple example:

1
2
3
4
5
6
7
8
9
TimingLogger timings = new TimingLogger("MYTAG", "MethodA");
// do some work A ...
timings.addSplit("work A");
// do some work B ...
timings.addSplit("work B);
// do some work C ...
timings.addSplit("work C");

timings.dumpToLog(); 
warning
The TimingLogger will not output anything unless it is manually enabled.

The following command enables the TimingLogger output for MYTAG

1
adb shell setprop log.tag.MYTAG VERBOSE

After the TimingLogger is enabled and the application has started generating logs, we can view them with the adb command:

1
adb logcat -v time MYTAG:W *:S

MySQL Stored Procedures

Stored Procedure Example 1

  • check for valid input parameter
  • declare handler for db error (1062 => duplicate key)
  • insert data
  • return status
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
DROP PROCEDURE IF EXISTS test_proc;

DELIMITER $$
CREATE PROCEDURE test_proc (
        IN p_test_id INT,
        IN p_test_string VARCHAR(255)
    )
BEGIN
  main: BEGIN

    # declare handler when duplicate key db error is thrown
    DECLARE EXIT HANDLER FOR 1062 BEGIN
        SELECT 1 AS status_code, 'Duplicate entry for input key values' AS status_message;
    END;

    # check if input parameter is NULL
    IF p_test_id IS NULL OR p_test_id < 1 THEN
        SELECT 2 AS status_code, 'Missing or invalid p_test_id parameter' AS status_message;
        LEAVE main;
    END IF;

    INSERT INTO test_table
    SET test_id = p_test_id,
        test_string = p_test_string;    

    SELECT 0 AS status_code, 'OK' AS status_message;
  END main;
END; 
$$
DELIMITER ;

# CALL test_proc(10, 'test string parameter');

MySQL stored procedure OUT parameter

I had to use a MySQL stored procedure written by another team, so here I don’t question the design of the procedure in any way.

My task is to call the procedure and get the OUT parameters after the execution has completed. The call is made with PHP PDO.