Monday, May 24, 2021

Withholding tax by country of major markets

Withholding tax by country of major financial markets

Australia30%
Canada25%
China (Mainland Incorporated)10%
China (Offsohore Incorporated)0%
Hong Kong0%
Japan20.42%
Singpaore0%
Singapore REITs10%
U.K.0%
U.K. REITs20%
U.S.30%

Source: https://www.spglobal.com/spdji/en/documents/additional-material/withholding-tax-index-values.pdf

Sunday, May 23, 2021

Most stock pickers loses to the index? Just buy the index. Does this advice work in Hong Kong?

If you invest in the Hong Kong stock market, Tracker Fund (2800) is one of the bigger and better-known funds. Does just buy the index work?

source: charts created from https://www.tradingview.com/

If you invested in 2800 10 years ago (2011-05-16 to 2021-05-17), in the course of this 10 years, you are looking at about 23% capital appreciation. Assuming inflation at 2% p.a., it barely tracks inflation of ~22%. The good news is there is a dividend, and you would have collected 8.01 HKD per share, and this doesn't look too bad.

source: http://www.aastocks.com/en/stocks/analysis/company-fundamental/dividend-history?symbol=02800

Let's look at trading view says when we click the "adj" - adjust data for dividends, and we are looking at about 70% return.

source: charts created from https://www.tradingview.com/

However, if you look at VTI and DIA in US, you can see 2800 really lacks behind:
  • VTI rose 210.92% for the same period
  • DIA rose 173.96% for the same period
source: charts created from https://www.tradingview.com/

Although, past performance is not indicative of future results, given this observation, should we bother with investing in the Tracker fund (2800)? Or any Hong Kong index fund / ETFs at all?

Wednesday, May 19, 2021

Is Kotlin still a good choice for JVM based backend today?

It has been while since I start a new JVM project. I needed to build something quick and dirty, e.g., within a day or two, so I went with something I was most familiar with, Spring Boot, to get the project up and running.

It has been a while, but Kotlin has been the crazy a few years back and I had used it a few times with my previous employer. It is now a choice among the JVM languages. I have been away from the JVM space for more than a year (and boy, do I miss it), so it was either Java or Kotlin for me. I went with Kotlin just to keep it interesting.

I went with the Spring Initializr, picked my poison and got my project up in no time. It is a simple Web-MVC application, with one simple page with a form, some REST API call out to other services, and read only to database. Picking Gradle for build and Kotlin for language, the project generated a Kotlin base build file build.gradle.kts. This is new to me, but the script is still very readable, so no extra learning curve here.

Last time I used Spring Boot with Kotlin, I recalled there are little things here and there that we need to "tweak" to get Spring Boot feature to work properly with Kotlin. These "tweaks" feel like some inherent mismatch between Spring Boot and Kotlin. For my new recent project, it appears all these “mismatch” still exist.

For example, to use Kotlin data class as @ConfigurationProperties object, we need to add this @ConstructorBinding annotation to the class and add “kapt” plugin to the project. This feels like some sort of workaround for some incompatibility between Kotlin data class and how Spring Boot @ConfigurationProperties works.

Next adding spring-data-jpa support with Kotlin, we need to add another slew of plugins “plugin.allopen”, “plugin.noarg”, “plugin.jpa”, and some custom extra gradle configuration:

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.Embeddable")
    annotation("javax.persistence.MappedSuperclass")
}

These little problems are often the reason why many “experienced” developers still refuse to adopt higher order frameworks such as Spring Boot and Ruby and Rails, and prefer to keep rolling their own, copy-and-pasting from past projects, because when the magic works, it is awesome, but if it doesn’t, trying to find the problem on your own is like trying to find a needle in a haystack. This is the size of the ecosystem matters, and the good old Spring Boot and its "Google-able-bility" is still top notch.

The target deployment environment is Kubernetes and I had experience using Docker and Dockerfile to build image, but Spring Boot simplified this for me and all I need is run gradlew bootBuildImage. With a little bit more work to setup the Gitlab pipeline to use kustomize and kubectl to push to EKS, the application was up in a day.

This got me thinking: Is Kotlin still a good choice for JVM based backend today?

With Java 17 LTS fast approaching, and many awesome language features added since the last LTS, such as java records in Java 16, it appears the language level gap between Kotlin and Java has shrunk. So, does it still justify using Kotlin, knowing that all these little incompatibility between the language and other frameworks? I think I found my answer in a comment by rzwitserloot in r/java.

Wednesday, December 9, 2020

An app to show bus ETA to the nearest stop quickly

I take the bus to work daily. At least before COVID-19 hit. I could never understand why would any reputable company would put so many ads on their official bus app. Are they so desperate for that little extra revenue?

Terrible UX from CityBus NWFB. An anoying splash screen, then a full page ad, before the app loads.

I just want open the app, and see the ETA of the bus for the stop nearest to me! Luckily CityBus NWFB publish their ETA via API, so I wrote Hong Kong Buses to do just that.

Saturday, October 17, 2020

What is C# equivalent for: Dependency Injection / Inversion of Control for a developer with Java background

I recently joined a company that is a C#/.NET shop. I have been working primarilyc in the JVM ecosystem for backend through most of my professional work, so this is quite a big of change.

The language different is minor, but re-learning the ecosystem is quite another story.

Let us start with Dependency Injection / Inversion of Control Container. There are quite a bit few to choose from:

From my few conversation with developers coming from the .NET ecosystem, the default answer is always to go with the "official" Microsoft provided solution. So that is what I did. 

Perhaps the documentation is written for people completely new to programming. For those with a Java background and are familiar with the concept of DI and IoC, here is my take of a quick start guide.

Use Host from the Microsoft.Extensions.Hosting namespace and build your IHost

IHost host = Host.CreativeDefaultBuilder()
    .ConfigureServices(
    ( _, services ) => 
        services.AddSingleton<MyInterface, MyImplementationClass>()
            .AddSingleton<NextInterface, NextImplementationClass>()
            // ... ...
);

For thosse coming from the Spring world, this is approximately equivalent to:

@Configuration
public class MyConfig {
    @Bean
    public MyInterface myClass() {
        return new MyImplementationClass();
    }
}

Or Guice if you come from Guice:

Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
        bind(MyInterface.class).toInstance(new MyImplementationClass());
    }
});


Spring Boot take this a step further with its @ComponentScan and @Component magic. Does .NET have something similar? I do not know, if you do, please drop me a comment!

Tuesday, June 9, 2020

Typing chinese puntuations

倉頡
ZXAD-->。
ZXAC-->、
ZXAB-->,
ZXCD-->「
ZXCE-->」

Windows 10

組合鍵 產生符號 說明
Ctrl + , (逗號) 逗號
Ctrl + . (點) 句號
Ctrl + ; (分號) 分號
Ctrl + ' (單引號) 頓號
Ctrl + / (斜線[右上左下) 刪節號
Ctrl + - (減號) 破折號
Ctrl + [ (左中括號) 左粗中括號
Ctrl + ] (右中括號) 右粗中括號
組合鍵 產生符號 說明
Ctrl + Shift + , (逗號) 左書名號(書名)
Ctrl + Shift + . (點) 右書名號(書名)
Ctrl + Shift + ; (分號) 冒號
Ctrl + Shift + ‘ (單引號) 雙引號
Ctrl + Shift + [ (左中括號) 左大括號
Ctrl + Shift + ] (右中括號) 右大括號
Ctrl + Shift + 1 (上方數字鍵) 驚嘆號
Ctrl + Shift + / (斜線[右上左下) 問號
Ctrl + Shift + 9 (開引號) 開引號
Ctrl + Shift + 0 (閂引號) 閂引號 「註一」


註一:要先把 Advance Key Settings - Between input langauges - Change Key Sequence - Switch Keyboard Layout 的 Key sequence 改為 Not Assigned.


(謝謝 mobile 1 的獨覺禪Source: https://www.mobile01.com/topicdetail.php?f=300&t=4837494)

Saturday, April 27, 2019

Face tracking web application

Continuing the theme of exploring various technology, it is time to see how far the browser has come.

A web application which tracks user faces through the device video capture source. On mobile phone, user can choose which camera to capture the video from. Since mobile phone have limited computational power, the resolution of the video capture is lower to ensure a smooth experience.


Try out the face tracking web app. Please note the application is rather large ~ 9 MB, and may require a few minutes to download on a slow connection. You will also need a a modern browser such as Google Chrome. Available for desktop and mobile devices

Don't worry, all processing are done on the client side, i.e. no video or imagery are send to anyone.