Friday, 10 July 2020

BigDecimal to double money: xx.xx

BigDecimal to double: 

    return getTotal().setScale(2, NumberFormat.getCurrencyInstance().getRoundingMode()).doubleValue();

return getTotal().setScale(2, RoundingMode.HALF_UP).doubleValue();

BigDecimal to string like:  £100.12


Thursday, 9 July 2020

test gRPC via Evans on EC2

I am trying to install below program into ec2 and test gRPC:

As below link shows, I need to install git first:

Install git onto ec2:

sudo yum update -y

sudo yum install git -y
git clone
cd evans
git checkout v0.6.11
make build
tar -xzf go1.13.3.linux-amd64.tar.gz
mv go /usr/local

export GOROOT=/usr/local/go
export GOPATH=$HOME/hadoop/evans
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

tar -xvf evans_linux_amd64.tar.gz
./evans --tls --host -r 


 |  ____|

 | |__    __   __   __ _   _ __    ___

 |  __|   \ \ / /  / _. | | '_ \  / __|

 | |____   \ V /  | (_| | | | | | \__ \

 |______|   \_/    \__,_| |_| |_| |___/

 more expressive universal gRPC client> show service




| Infrabin | Delay    | DelayRequest   | Response     |  

|          | Root     | Empty          | Response     |

+----------+----------+----------------+--------------+> service Infrabin> call Root


  "hostname": "xxx",

  "kubernetes": {

    "podName": "",

    "namespace": "",

    "podIp": "",

    "nodeName": "xxxx"


  "liveness": "",

  "delay": 0,

  "error": "",

  "headers": {



  "env": {



}> exit

Good Bye :)

Then, I got it.

Then finally I downloaded the binary version of Evans:

but still not able to compile.

Then, I got go.

Then install golang by:

However, I found I need golang to runmake build

Then, i can checkout the code of Evans:

Sunday, 5 July 2020


create (:Pig{name: "平", age:20})
create (:Pig{name: "倩", age:20})

MATCH (n:Pig{name:"平"}) MATCH (m:Pig{name:"倩"}) create(a)-[r: 爱人]->(b)

Or, all in one line:

create (:Pig{name: "平", age:20})-[:好朋友]->(:Pig{name: "倩", age:20})

Match (b:Pig{name: "平"}) set b.age = 30

Friday, 3 July 2020

Guice programmatically get the injected instance.

this is useful in test if your guice injection is singlton and you want to get the same instance  as your program is using:

YouClass instance1 = InjectorLookup.getInjector(app.getApplication()).get().getInstance(YouClass.class);

Friday, 19 June 2020

aws, create subnet for vpc and what should i use for CIDR

If you are making subnet for a vpc, you need to know existing subnet under this vpc,  and what IP range they are using. You cannot overlap with them.

the reason for creating subnet is to create an internal network within the VPC. vpc is a private network, things inside are using internal IPs.  We actrually can add things to vpc directly,  but AWS just want to make it more complex (i guess the reasons are : 1. avoid waisting ip address and ip conflict, also add some level of network control e.g. ipwhitelisting). AWS allows you to create multi subnet for VPC, things in a subnet can connect to each other and they have the same network settings, e.g. if a service in a subnet can connect to Kafka (just an example), then when you create a new service, it is a good choice to put this service into the same subnet.

In some companies, admin may not want you to create new subnet, then you have to reuse other subnet. you can go to aws console to find out this and also know how many Ip address are not used, and estimate how many IP address you will need and chose the right subnet.

if you can create subnet. you need to make sure which CIDR you will need to use. CIDR is used to tell the system an IP range you want. technically, you use CIDR to say what is the IP range for the subnet.

(CIDR is a quick way to tell an IP range, usually you tell people an IP in this way: - means 89 IPs. CIDR want to know starting IP and length. e.g. 89, but to make the computation more efficient, it doesn't accept a number like 89, it use binary bites.  and it only accept 2 ** x  which is 2 power of somthing. which means you cannot make a range for 3 IPs, you can only make a range with 4 IPs.     another issue is that CIDR doesn't accept x, x is the number in above calculation. CIDR uses:    e.g.  if you need a range for 8 IPs, then x=3 the CIDR is

e.g. if you already have 2 subnets:

that means:
 the first one reserved 16 IP address from  to
 the second one reserved 16 IP address from  to

if you want to create a new subnet you need to make sure not overlap with them  if you need 256 IP address, then

you need to work out log2(256)  which is 8
then 32 -8 = 24 
so your CIDR is :

Thursday, 18 June 2020

Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 55

Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 55

if you are using spark,

that means your jdk and spark version doesn't match, try lower java version.

Thursday, 26 March 2020

How to share files between Mac and Deepin

I am a deepin user, I also have a mac.

Now I am going to show you how to share files between deepin and Mac.

It is very simple.

You can use Deepin as a windows pc. just right click the folder you want to share, and click share. (just share within your local network e.g. home wifi, or office wifi)

Then you can access the folder from your Mac

then you can drag and drop files like you used to do in windows.

If you want to have some control.  e.g.  don't allow anonymous access.

then you can :

Then you need to setup a password for the access.

Here is the tricky part:

The username is your login username for deepin system. but you cannot use the same password, you have to create a new one here:

You have to  go into the folder and then find the burger button on the top the find out the menu to set password.

then you can use the usernane and password to access from your mac