How to build the Golang Bitcoin Node for Windows 10 (btcd)

The latest btcd release build is from 2015. There is a nice description how to build it for Linux/Mac, but for Windows it’s suggested to download the latest binaries, which are 626 commits behind master as of February 2018. Fortunately, with Golang we can easily build binaries for Windows, and we can follow the steps of the Linux build process. The only issue I faced was a problem in the Glide dependency manager and that’s how this little post was born.

Update Go version on Linux

1. Download the latest (or desired) Go version

1
wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz

2. Remove old installation

1
sudo rm -rf /usr/local/go

3. Extract archive into /usr/local/go

1
sudo tar -C /usr/local -xzf go-archive-filename.tar.gz

4. Test if everything is OK

1
go version

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