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)