Monday, October 31, 2022

How To Get Maybank2u DuitNow QR Code

How To Get Maybank2u DuitNow QR Code


Use the "receive" tab to display DuitNow QR

What is a DuitNow QR code?

The easiest way is to ask the payee transfer money to DuitNow (mobile number). You can generate the DuitNow QR for the payee to scan. The DuitNow QR code is normally is red color. In Maybank app, you can specified the amount to be received.

DuitNow is Malaysia nation wide money transfer network, it normally use the mobile phone number as the account ID to receive payment. The DuitNow network can use MyKad IC, passport as account ID as well. Before you can receive payment from DuitNow, you need to active and link the DuitNow to one of you bank account.

Maybank MAE

At the home screen, click the center icon at the bottom.

It shows the camera display. On top, there are 2 tabs, scan and receive. Click on the receive tab to display to the QR code to receive payment.

Maybank2u app (to be obsolete)

At the home screen, click the center icon at the bottom.

It has 3 tabs on top of the display, scan, receive and pay. Click on the receive tab to display to the QR code to receive payment.

Monday, September 26, 2022

Washington Post Mobile App Does It Right

Washington Post mobile app does it right

Amazon reminds me, my Washington Post free subscription is going to end. Finally I opened the mobile app.

A lot of the traditional newspapers or magazines get it wrong. They put the PDF version of the newspaper (or magazine) and put it online as an online version. Washington Post is a hybrid version website and traditional version. You have a choice to display the printout layout, but once you click on the news, it will show the online version.

The PDF version is not good for mobile/desktop use, because the viewing devices may have different sizes, but the PDF format is fixed, the paragraph never wraps around according to the device. Washington Post app allows you to choose what type of news to be displayed like headlines, editor pick.

Wow! I think the Washington Post does it right.

Wednesday, September 14, 2022

iOS 16 Battery Percentage Display

iOS 16 Battery Percentage Display

iOS 16 is available for download and update. One of the changes that people are paying attention is the battery percentage displayed in the battery status bar. Anything special about this?

I just don't understand.

Tuesday, September 13, 2022

Google To Cancel Next Pixelbook

Google abandone the chromebook hardware, but hopefully they don't abandon the Chrome OS.

The chromeOS is a good idea and good implementation. It is a Chrome browser running on Linux, it also has Android framework, so it can run Android apk app. It also has a Debian-like Linux which runs in a VM container.

Only Linux users will appreciate chromeOS.

Thursday, August 04, 2022

Object Oriented Concept For Programmer 2022

Object Oriented Concept For Programmer

This is for beginners.

I try to explain object oriented programming is different ways, especially for beginners.

There are 4 things in OOP: Abstraction, Inheritance, Encapsulation and Polymorphism.

Example: Shape (abstraction)

Shape has area, this is abstract. You don't how's the shape looks like (circle? triangle?), and you are not sure about the size of the shape.

Shape().area # let's say this is how you define the Shape() object.

Example: Circle (Inheritance)

Circle is a shape, so circle has area. Why? Circle inherit the area properties from Shape.

Circle() is Shape()

Example: Circle (Encapsulation)

You don't allow anyone to change the area of a circle. The area of a circle can only be change by the radius. I use the private keyword to protect the Circle().area.

private Circle().area
Circle().area= pi * radius * radius
Circle().get_area()= area

Direct access of area outside of the object invoke an error:
print Circle().area ==> error
print Circle().get_area() ==> 20.5

Example: Square and rectangle (Polymorphism)

Square and rectangle are similar. Square is another form of rectangle, or you can say that rectangle is another form of square.

Square() is Shape()
Square().get_area(height)= height * height # formula for square
Square().get_area(height,width)= height * width # formula for rectangle

You can have 2 functions with the same name for Square() object, this is polymorphism.

print Square().get_area(5)
print Square().get_area(5,4) # this is for rectangle

Note: In C programming language, there are 2 commands for string copy 1. strcpy(t,s) 2. strncpy(t,s,n). In OOP, you can merge these 2 commands into 1 with the same name, but differentiate by number of parameters.

Thursday, May 12, 2022

Using Java For Object Oriented Programming For Beginners

Using Java For Object Oriented Programming For Beginners

I find it easier to use Java programming language to write object oriented program, compare to Python and C++.

C++ is powerful, but I find it complicated. There are advantages using C++. GNU GCC compiler support C++, you don’t have to install another bloated Java C compiler and Java runtime.

Python is easy to learn and use, but the object oriented feature is limited.

I am using the classic example, get the area of a shape, circle and rectangle.


Python
$ edit shape.py
from math import pi
class shape:
    ''' class shape '''
    def __init__(self):
        pass

    def get_area(self):
        return 0

class rectangle(shape):
    def get_area(self,height,width=0):
      return height*width

class circle(shape):
    def get_area(self,radius):
        return pi*radius**2

print(rectangle().get_area(5,4))
print(circle().get_area(5))
Java
abstract class Shape {
	abstract int getArea();
}

class Rectangle extends Shape {
// implement nothing here, will generate error
}
$ javac Rectangle.java
==> error

In Python, if you don't implement rectangle().get_area(), there is no error. The rectangle().get_area() will always return 0 as stated in shape().get_area(). In Java, the compiler error tell you to implement getArea() in subclass.


$ edit Rectangle.java
class Rectangle extends Shape {
	int getArea() { return 0; }

	int getArea(int height, int width) {
		return height*width;
	}
}
  

Polymorphism

Square is a polymorphism of rectangle. They looks the same, the different is square has the same height and width.

Python
$ edit shape.py # add in the code
...
class rectangle(shape):
    def get_area(self,height,width=0):
        if width==0:
            return height*height
        return height*width

sq= rectangle()
print(rectange().get_area(5,4))
print(sq.get_area(4))
...
  

I use a if statement to determine the diffrent code for rectangle and square. The code will look messy if the implementation for rectangle and square are complicated. In java, you can split into 2 methods, like this:


Java
$ edit Rectangle.java

class Rectangle extends Shape {
	int getArea() { return 0; }

	int getArea(int height, int width) {
		return height*width;
	}

	int getArea(int height) {  // this is for square
		return height*height;		
	}
}
  

Polymorphism 2: Waterworld

Let's says the mutant has lungs and gills to breath above water and under water.


$ edit waterworld.py
class air:
	def __init__(self):
		pass

class water:
	def __init__(self):
		pass

class mutant:
	def __init__(self):
		pass
	def breath(self,media):
		if type(media)==air:
			print('use lungs')
		elif type(media)==water:
			print('use gills')
		else:
			print('can not breath')

mariner=mutant();
for m in (air(),water()):
	mariner.breath(m)
  
Java

How do you implement in Java? Tips: create Java object Air and Water. Create 2 methos in Mutant object: 1. breate(Air) 2. breate(Water).

Thursday, April 28, 2022

Print Transaction History Receipt RHB Maybank2u 2022

Print Transaction History Receipt RHB Maybank2u 2022

Re-print the receipt from online banking is an important function. As a prove to the receipiant party a transaction has been done. You can reprint it in RHB and Maybank2u, through the old website and not the new website (yet).

Maybank2u classic

Switch to the classic website.


Maybank2u classic (old) > Account & Banking > Account Details > M2U history > [ Reprint ]

Those transactions done by mobile app, can be reprint as well.

RHB Now

Note : If your transactions are done with the mobile app or the new website, the transaction receipt can not be re-printed again. Only transactions done with RHB Now web version can be re-printed again.

RHB Now > RHB Now Transaction Records (above/besides the email button) > choose date range and type of transaction.

    Account number :[   ]
    From: [    ] dd/mm/yyyy
    To:   [    ] dd/mm/yyyy
    ---- down here has a long list of selection ----
    (I only show some of it)
    JomPay
    [ ] Favourite Biller
    [ ] Open Payment
    
    [Submit]

Conclusion

Maybank2u is easier, and more powerful.

Thursday, April 21, 2022

How To Deregister Fire HD Tablet

How To Deregister Amazon Fire HD Tablet

If you want to give away your Amazon Fire HD tablet to the others (as a gift or selling it), make sure it is deregister with you user account. This apply to other Alexa devices as well.

There are a few ways to deregister:

From the device (Fire HD)

Fire OS > Settings > My Account > [DEREGISTER]

Refer to the picture above.

From the web (need Amazon login)

For me this is easiest and powerful. Not just for deregister, but other configuration and setting as well. Remember this website https://amazon.com/mycd/:

Devices tab > (choose Fire Tablet) > (choose table or device name) > [Deregister]

You can change your device name from here as well.

From Alexa mobile app

Alexa app > Devices tab (lower right) > Echo & ALEXA > setting icon (top right) > Registered To [Deregister]

Note: This doesn't works for my Fire TV stick, and Fire HD tablet. It works for Echo Show, Echo Dot, and some other 3rd party devices.

Wednesday, April 13, 2022

Time Net Speed Monitor on Fire HD 8

Time Net Speed Monitor on Fire HD 8

Notice the speed meter on the top left corner?

Time Net Speed Monitor is an app to show network speed on the display. I want this app because I need to monitor the network speed while streaming video.

This app need "Display over other apps" permission. Some system (Fire OS/Android), doesn't allow the permission to be set, it can be fixed by ADB (Android Debug Bridge).

I try it on Fire HD 8 2020, Fire OS 7.x. Note: The OS version can be found on Settings > Device Options > System updates.

Install on Fire HD 8

Time Net Speed Monitor can be downloaded from Amazon. When you installer, it will ask user to enable "Display over other apps" permission.

Set "Display over other apps" permission

Fire OS > Apps and Notifications > Time NetSpeed Monitor > Advanced: Display over other apps [allow]

Set "Display over other apps" permission through ADB

The permission may be described as "Display over other apps", or "Drawing over other apps".

I was not able to set the permission in Amazon Fire TV Stick. So I use the ADB method. If you don't know how to adb to a Fire OS (or Android), please check how to ADB before continue.

$ adb shell appops set visnkmr.apps.timenetspeed SYSTEM_ALERT_WINDOW allow
OR
adb$ appops set visnkmr.apps.timenetspeed SYSTEM_ALERT_WINDOW allow

To turn off
adb$ appops set visnkmr.apps.timenetspeed SYSTEM_ALERT_WINDOW deny

Wednesday, March 23, 2022

Software Automated Testing and Framework 2

Software Automated Testing and Framework 2

Python and bourne shell script

Follow up with the previous tutorial (a href="http://fuyichin.blogspot.com/2022/03/software-automated-testing-and-framework.html">here), testing framework for Java (JUnit) and C (cmocka). This tutorial continue with Python and bourne shell script.

Python

$ edit calculator.py

#!/usr/local/bin/python3
def plus(a,b):
	return a+b
  
$ edit calculator_test.py
import unittest
import calculator

class CalculatorTest(unittest.TestCase):
	def test_plus(self):
		self.assertEqual(51,calculator.plus(20,30))

if __name__ == '__main__':
	unittest.main()
  

Run the test case:
$ python3 calculator_test.py

  F
======================================================================
FAIL: test_plus (__main__.CalculatorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/hooichee/workspace/test_maven/python/calculator_test.py", line 6, in test_plus
    self.assertEqual(51,calculator.plus(20,30))
AssertionError: 51 != 50
  

Change the result and run the test case again.

Ran 1 test in 0.000s
OK

Bourne shell script

I am using Shunit2, can be downloaded from https://github.com/kward/shunit2. There are many other testing framework are available, I just use this as an example.

$ edit calculator.sh

#!/bin/sh
plus() {
	echo `expr $1 + $2`
}
$ edit calculator_test.sh
#!/bin/sh
source calculator.sh

testPlus() {
  assertEquals 100 `plus 99 1`
  assertEquals 'Test plus' 50 `plus 20 30`
}

# Load and run shUnit2.
#. ../shunit2
. /usr/local/bin/shunit2

Run test:

$ sh calculator_test.sh 
testPlus

Ran 1 test.

OK

Saturday, March 19, 2022

Software Automated Testing and Framework

Software automated testing and framework

The idea of software automated testing is always there, just how to implement it.

Java has a JUnit testing framework, which looks ok. Other programming languages have their own testing framework, which looks similar.

This is a sample of the output of JUnit:

Tests run: 20, Failures: 0, Errors: 0, Skipped: 0

JUnit 4

JUnit has different versions like version 3, 4, and 5. I am using version 4 as an example here, because it looks simple.

JUnit follow some naming convention and style. The testing program always end with Test, the test case function starts with test. eg. CalculatorTest.testPlus().

If you use maven, JUnit is integrated into the system, just $ mvn test; will do the job. I am using the command line and manual way to shows to create and run the test case.

Let's say this is the program you want to test:

class Calculator {
    int plus(int a, int b) {
        return a+b;
    }
}
    

This is your JUnit test case:

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CalculatorTest
{
    @Test
    public void testPlus() {
        Calculator cal= new Calculator();
        assertEquals(50, cal.plus(20,30) );
    }
}
Note: JUnit 4 looks simple, need Java 1.5 or above to compile.

$ javac -classpath junit-4.11.jar:. CalculatorTest.java 
⇒ CalculatorTest.class  Calculator.class
$ java -classpath junit-4.11.jar:. CalculatorTest 
⇒ Error: Main method not found in class CalculatorTest
$ java -classpath junit-4.11.jar:. org.junit.runner.JUnitCore CalculatorTest
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
  
$ java -classpath junit-4.11.jar:hamcrest-core-1.3.jar:. org.junit.runner.JUnitCore CalculatorTest
Time: 0.01
OK (1 test)

The JUnit 4 software can be downloaded from https://github.com/junit-team/junit4/wiki/Download-and-Install

Cmocka for C programm

There is a google testing framework which is more powerful. I choose cmocka, because it is small and simple.

To install:
Debian: $ sudo apt-get install cmocka
macOS: $ brew install cmocka

$ edit calculator.c

int plus(int a, int b)
{
	return a+b;
}

$ edit calculator.h

int plus(int, int);
  

$ edit calculator_test.c

#include 
#include 
#include 
#include "cmocka.h"
#include 
#include 
#include "calculator.h"

static void test_plus(void **state) {
    (void) state; /* unused */
    
    assert_int_equal(50,plus(20,30));
    assert_int_equal(8,plus(5,3));
}

int main(void)
{
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(test_plus),
    };

    return cmocka_run_group_tests(tests, NULL, NULL);
}

To compile and test:
$ cc -c calculator.c
==> calculator.o
$ cc -c `pkg-config --cflags cmocka` calculator_test.c
$ cc -o calculator_test calculator_test.o calculator.o `pkg-config --libs cmocka`

If you don't have pkg-config:
$ cc -c calculator_test.c
$ cc -o calculator_test calculator_test.o calculator.o -lcmocka

==> calculator_test*

Run test case:

./calculator_test 
[==========] Running 1 test(s).
[ RUN      ] test_plus
[       OK ] test_plus
[==========] 1 test(s) run.
[  PASSED  ] 1 test(s).

If integrate with automake. Use libgrowl as an example:
$ git clone https://github.com/fuyichin/libgrowl
$ make check

======================================
Testsuite summary for libgrowl 0.1.0
======================================
# TOTAL: 6
# PASS:  6
# SKIP:  0
# XFAIL: 0
# FAIL:  0
Note: As the time of writing this now, the automake of libgrowl is not integrated into the main branch yet. Can try with the branch autogen.

Other programming like Python and Bourne shell has their own testing framework as well.

Thursday, February 17, 2022

MiTV 4K Enable Debug Mode

MiTV 4K Enable Debug Mode

Settings > About > Build version, click 7 times.
Note: The build version normally is the last info.

{ } Developer option will appear.

{ } Developer option > [x] Developer option 啓用開發者選項 [x] USB debugging USB 調試

A dialog box appear, allow the permission.

Now you can use the ADB:
$ adb connect

The ip address can be found on the network info.

Tuesday, February 08, 2022

Android Grant Drawing Over Other Apps

Android Grant "Drawing over other apps"

Application like SpeedMeter, Assistive Touch may report error or issue about "Drawing over other apps"

You need ADB to grant "Drawing over other apps"


1. find out the package name of the app:
$ adb shell pm list packages

For examples:
com.tuanfadbg.assistivetouchscreenrecorder
visnkmr.apps.timenetspeed

2. grant access
$ adb appops set visnkmr.apps.timenetspeed SYSTEM_ALERT_WINDOW allow

Now you should be able to enable the SpeedMeter or the Assistive Touch apps.

Saturday, January 15, 2022

Tutorial Git branch by examples

Git branch by examples

Git branch sound confusing. This is a jumpstart version, I try to make it as easy as possible

Working with Git branch is easy. Git branch is light-weight. When working with new feature or bug fix, just create a new branch.

Use 'git branch' and 'git checkout':

  Git branch to create branch and show branches:
  format: git branch branch_name
  
  Git checkout to switch between branch:
  format git checkout [-b] branch_name
  

*Important*: Changes before commit exist in the directory (and all branches), after committed the changes will not appear in other branches. The changes after commit will be isolated from other branches. (Will be explained later by example)

Scenario

While working on feature_x, a hotfix needs to be done and released without the feature_x. Should commit feature_x before working on hotfix.

Steps:
1. create branch feature_x and hotfix (from master)
make changes and commit each branch
2. switch between the branches and observe changes are isolated
Note: feature_x started first but not merged yet. Hotfix release first.

      +-- hotfix (add 'hot fix' in README.md file)
  master
      +-- feature_x (add 'feature x' in featurex file)

Git branch and git checkout

In the working directory

$ git branch  # or git branch [--list|-l]
* master  # only 1 main branch
($ git branch -a, shows remote repository branch as well)
$ echo 'Hello, world' > README.txt
  

Create branch feature_x

Create branch:
$ git branch feature_x
$ git branch
feature_x  # feature_x branch was created
* master   # still at master branch
$ git checkout feature_x
$ git branch
* feature_x  # switch to feature_x
master
  

Note: Use 'git checkout -b featurex' to create and switch to branch feature_x.

The new changes are just in the file featurex.

(feature_x)$ echo 'feature x' >> featurex  # make some changes
(feature_x)$ git add featurex
(feature_x)$ git commit -m 'feature x'

(feature_x)$ git log --oneline
be85a75 (HEAD -> feature_x) feature x
9462eec (master) Initial commit

$ git checkou master; git log --oneline
Switched to branch 'master'
9462eec (HEAD -> master) Initial commit# no feature_x committed in the master branch.

The feature_x is not merged into master branch yet. Suddently there is an adhoc bug fix:

(master)$ git checkout -b hotfix
(hotfix)$ ls
README.md  # there is no featurex in this branch
(hotfix)$ echo 'hot fix' > README.md
(hotfix)$ git commit -am 'hot fix'
[hotfix 8cbc155] hot fix
 1 file changed, 1 insertion(+), 1 deletion(-)

(hotfix)$ git branch
  feature_x
* hotfix
  master
(hotfix) git checkout master
(master) cat README.md
==>Hello, world  # changes in hotfix not in master branch, it was isolated.
(master)$ git log --oneline
9462eec (HEAD -> master) Initial commit  # and the commit in other branch is not merge yet.

Merge and delete branch

(master)$ git log --oneline --branches
8cbc155 (hotfix) hot fix
be85a75 (feature_x) feature x
9462eec (HEAD -> master) Initial commit

(master)$ git log --oneline --branches --graph 
* 8cbc155 (hotfix) hot fix
| * be85a75 (feature_x) feature x
|/  
* 9462eec (HEAD -> master) Initial commit

There are 2 branches, merge hotfix just move the HEAD pointer to hotfix, later merge featurex branch, system need a new commit after merging changes in featurex.

(master)$ git merge hotfix
Updating 9462eec..8cbc155
Fast-forward
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(master)$ git branch -d hotfix  # it is safe to use -d

Note: It is save to use -d, if the branch is not merged, it can not be deleted. Use -D to delete branch that is not merged.

(master)$ git log --oneline --branches
8cbc155 (HEAD -> master, hotfix) hot fix
be85a75 (feature_x) feature x
9462eec Initial commit

You can try to merge feater_x, it needs a new commit, because it need to merge then changes into master+hotfix.

Wednesday, January 05, 2022

Fibonacci One Line Code with Python

Fibonacci One Line Code with Python



This is using recursive and shorthand if to implement fibonacci. Fibonacci is a sequence, the value of the sequence is the sum of the previous 2 numbers in the sequence: eg. 1, 1, 2, 3, 5, 8, 13, 21, ...

The normal Python function:

  def fibonacci(n):
	return 1 if n<=1 else fibonacci(n-1) + fibonacci(n-2)
  

To output:

    for n in range(8):
        print(fibonacci(n))
  

Ok, with the function define, that's 2 lines of code.