PHP Serialize String and JSON Object

I’m not really understand difference between PHP serialize string and JSON object.

I notice PHP when stored data inside database is in PHP serialize string format. Serialize string is only available in PHP, hence it is not interoperable with NodeJS.

Hence, I did simple comparison for better understanding in order to make my NodeJS can read and write PHP data and vice versa.

PHP Array Conversion to PHP Serialize String and JSON Object

//convert PHP array to serialize string and JSON object
$array = array( '1' => 'elem 1', '2'=> 'elem 2', '3'=>' elem 3');


$serialized = serialize($array);
print_r($serialized);
//expected output - serialize string: a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}


$json = json_encode($array);
print_r($json);
//expected output - JSON object: {"1":"elem 1","2":"elem 2","3":" elem 3"}

//convert back to PHP array

$unserialized = unserialize($serialized);
print_r($unserialized);
//expected output - unserialized: Array ( [1] => elem 1 [2] => elem 2 [3] => elem 3 )

$decoded1 = json_decode($json);
print_r($decoded1);
//expected output - decoded into PHP object: stdClass Object ( [1] => elem 1 [2] => elem 2 [3] => elem 3 )


$decoded2 = json_decode($json, true);
print_r($decoded2);
//expected output - decoded into PHP array: Array ( [1] => elem 1 [2] => elem 2 [3] => elem 3 )

PHP Object Conversion to PHP Serialize String and JSON Object

$object = new stdClass();
$object->name = 'Here we go';
$object->message = 'Hello world';


$serialized = serialize($object);
print_r($serialized);
//expected output - serialize string: O:8:"stdClass":2:{s:4:"name";s:10:"Here we go";s:7:"message";s:11:"Hello world";}
 

$json = json_encode($object);
print_r($json);
//expected output - json object: {"name":"Here we go","message":"Hello world"}

$unserialized = unserialize($serialized);
print_r($unserialized);
//expected output - unserialized: stdClass Object ( [name] => Here we go [message] => Hello world )

$decoded = json_decode($json);
print_r($decoded);
//expected output - decoded JSON: stdClass Object ( [name] => Here we go [message] => Hello world )

$decoded2 = json_decode($json, true);
print_r($decoded2);
//expected output - decoded JSON: Array ( [name] => Here we go [message] => Hello world )

PHP Array of Object Conversion to PHP Serialize String and JSON Object

$object1 = new stdClass();
$object1->color = 'blue';
$object1->type = 'suv';

$object2 = new stdClass();
$object2->color = 'white';
$object2->type = 'mpv';

$arrObjects = array($object1, $object2);


$serialized = serialize($arrObjects);
print_r($serialized);
//expected output - serialize: a:2:{i:0;O:8:"stdClass":2:{s:5:"color";s:4:"blue";s:4:"type";s:3:"suv";}i:1;O:8:"stdClass":2:{s:5:"color";s:5:"white";s:4:"type";s:3:"mpv";}}


$json = json_encode($arrObjects);
print_r($json);
//expected output - JSON: [{"color":"blue","type":"suv"},{"color":"white","type":"mpv"}]
 

$unserialized = unserialize($serialized);
print_r($unserialized);
//expected output - unserialize: Array ( [0] => stdClass Object ( [color] => blue [type] => suv ) [1] => stdClass Object ( [color] => white [type] => mpv ) )


$decoded = json_decode($json);
print_r($decoded);
//expected output - decoded: Array ( [0] => stdClass Object ( [color] => blue [type] => suv ) [1] => stdClass Object ( [color] => white [type] => mpv ) )


$decoded2 = json_decode($json, true);
print_r($decoded2);
//expected output - decoded with true: Array ( [0] => Array ( [color] => blue [type] => suv ) [1] => Array ( [color] => white [type] => mpv ) )

Web Scraping – How To Get Hidden Data API that is Embedded in Google Map

I would like to get KFC Malaysia outlets that are located on top of Google Map. I tried using a scraper tool but it always gives me empty result.

So I have to find the hidden outlets API to retrieve it. I’m using Google Chrome to find the hidden data API.

Steps

1) Go to https://kfc.com.my/find-a-kfc/

2) Click on the outlets to view its details information.

kfc outlets location
kfc outlets location

3) Right click on the outlet’s information box and click Inspect.

kfc outlets inspect
kfc outlets inspect

 

4) You will see new window at bottom or right panel of your Chrome browser. Then click Network tab. The tab will be empty

kfc inspect network blank
kfc inspect network blank

5) Refresh your browser and you will see, it is populated with files and their types.

6) Sort by type and look for “fetch” type

identify data api by looking for fetch type
identify data api by looking for fetch type

7) Click on the file link and new window will appear. Click on “Response” tab.

Find until you see JSON format with outlet information. In KFC case, I found the file name is store?xxxxxxxx (xx denotes numbers)

kfc outlets api response
kfc outlets api response

8) You can also click “Preview” tab to see prettified JSON format.

kfc outlets api preview
kfc outlets api preview

9) After found the file that provides the outlets data, right click on the file and Copy -> Copy link address

get the outlets api by copying link address
get the outlets api by copying link address

10) Paste the link to a new browser tab and you can see the link

  • In KFC case it is, https://kfc.com.my/api/v2/store?1588173941864
  • You will see the response as below
kfc hidden outlets api response
kfc hidden outlets api response

11) Write a code that read the API and parse the JSON data

  • I’m using NodeJS and save it as CSV file.
import rp from 'request-promise';
const createCsvWriter = require('csv-writer').createObjectCsvWriter;

(async function() {
const records = await rp("https://kfc.com.my/api/v2/store?1588173941864");
const rows = JSON.parse(records);
const csvWriter = createCsvWriter({
    path: '/path-to-save/kfc.csv',
    header: [
        {id: 'id', title: 'ID'},
        {id: 'name', title: 'Name'},
        {id: 'address', title: 'Address'},
        {id: 'phone', title: 'Phone'},
        {id: 'open24h', title: 'Open 24 Hr'},
        {id: 'hasbreakfast', title: 'Has Breakfast'},
        {id: 'hasdrivethru', title: 'Has Drive Thru'},
        {id: 'delivery', title: 'Delivery'},
        {id: 'selfcollect', title: 'Self Collect'},
        {id: 'haswifi', title: 'Has Wifi'},
        {id: 'weekdayopen', title: 'Weekday Open'},
        {id: 'weekdayclose', title: 'Weekday Close'},
        {id: 'weekendopen', title: 'Weekend Open'},
        {id: 'weekendclose', title: 'Weekend Close'},
        {id: 'latitude', title: 'Latitude'},
        {id: 'longitude', title: 'Longitude'}
    ]
});

  await csvWriter.writeRecords(rows);
}());

11) Sample CSV Output

kfc sample csv output
kfc sample csv output
  • From the CSV, KFC Malaysia has 712 outlets as of 29/04/2020.

QGIS How To Create Hexagon Grid Based on Selangor State Boundary

GIS hexagon grid can be created using QGIS. In this case I’m using QGIS version 2.18.15.

First of all, you must have a boundary layer. I’m using Selangor parliamentary boundary.

QGIS Selangor Parliamentary Boundary
QGIS Selangor Parliamentary Boundary

Steps to Create Hexagon Grid

1) Enable the Processing Toolbox

View -> Panel -> Toolbox

QGIS Enable Toolbox
QGIS Enable Toolbox

2) From the Processing Toolbox, select Create Grid

QGIS Processing Toolbox
QGIS Processing Toolbox

3) After setting the configuration as follows, click run:

  • Grid type: Hexagon
  • Grid extent:  Select canvas and choose Selangor boundary or your boundary layer.
  • QGIS Use Extent Selangor Parliamentary
    QGIS Use Extent Selangor Parliamentary
  • Horizontal / Vertical spacing: 0.025 (means 0.025km)
  • Grid CRS: EPSG 4326 (or popularly known as WGS 84 where Google Map use this CRS)
QGIS Hexagon Grid Processing
QGIS Hexagon Grid Processing

4) After click Run, a hexagon grid layer will appear as follows:

QGIS Hexagon Grid Layer
QGIS Hexagon Grid Layer

5) Select Vector -> Research Tools -> Select by Location

QGIS Select By Location
QGIS Select By Location

6) Input the Configuratoin for Select by Location as follows, then click Run:

  • Layer to select: Your Hexagon Grid Layer
  • Additional layer (intersection layer): Your boundary layer in my case Selangor parliamentary
  • Geometric predicate: choose intersects, contains, touches, overlaps
QGIS Select By Location Configuration
QGIS Select By Location Configuration

7)Then click Select Features using an expression -> Invert Feature Selection

QGIS Invert Feature Selection
QGIS Invert Feature Selection

8)After inversion, your hexagon grid would look like below:

QGIS After inversion
QGIS After inversion

9) Click Toggle Editing (pencil icon) then Delete (trash icon)

QGIS Toggle Editing & Trash
QGIS Toggle Editing & Trash

10) Final output would look like this

QGIS Hexagon Grid
QGIS Hexagon Grid

How To Reduce Al Rajhi Housing Loan Principal

If you have extra money and want to reduce your housing loan principal with Al Rajhi bank, below are the steps.

Steps to Reduce Housing Loan Principal

  1. Send an official letter to Al Rajhi,
    • state the amount to reduce principal
    • state your saving account number with Al Rajhi
    • state your housing loan account number
    • authorize Al Rajhi to deduct the amount from your saving account with Al Rajhi
    • sign the letter
  2. Ensure the amount is in your Al Rajhi bank account
  3. Email the soft copy letter to customersupport@alrajhibank.com.my
  4. Ensure Al Rajhi provide you with acknowledgement
  • There is no minimum amount to reduce the principal
  • It takes 7 working days to process
Notes

This information is verified as of 31st March 2020, when I made a call to Al Rajhi call centre. Better to double confirm with Al Rajhi regarding your housing loan.

To take or No Loan Moratorium due to Covid 19

Due to Covid 19, Malaysian government decided to give loan moratorium for 6 months starting April till September 2020.

The moratorium applied to all banks under Bank Negara Malaysia and for individuals and SME who have housing loan, car loans or business loans. The moratorium will accrue all profit/interest from the loan.

At same time all commercial banks decided not to compound the interest accrued during this 6 months.

The moratorium is to ease financial burden to all affected Malaysians.

Let say we decided to take the moratorium. I would like to analyze for housing loan only.

So what we shall do the additional fund from the 6 months moratorium?
1) Use it if you really need it
2) Save it for emergency fund
3) Use it, to reduce your loan principal

Use The Saving from 6 Months Moratorium to Reduce Your Loan Principal

I would like to simulate what is the best way to reduce your principal. Options available as follows:
1) Use the accumulated fund to pay the principal by the end of moratorium
2) Use the monthly installment to reduce principal on monthly basis

Assumptions:

Loan Amount: RM100,000
Tenure: 30 years
Interest: 5% per annum
Monthly Installment: RM536.82

If no moratorium, the principal should be RM99,272 based on the amortization table.

housing loan amoritization for RM100k loan
housing loan amoritization for RM100k loan

1) Use the Accumulated Fund to Pay Principal by The End of Moratorium

NoMonthPrincipal (RM)Profit / Interest (RM)
1April 2020100,000 416.67
2May 2020100,000 416.67
3June 2020100,000 416.67
4July 2020100,000 416.67
5August 2020100,000 416.67
6September 2020100,000 416.67

After 6 months:-
The accrued profit / interest: RM2,500
The accumulated fund saved from the monthly payment is: RM3,220.92

2) Use the Monthly Installment to Pay Principal On Monthly Basis

NoMonthPrincipal (RM)Profit / Interest (RM)
1April 2020 100,000.00 416.67
2May 2020 99,463.18 414.43
3June 2020 98,926.36 412.19
4July 2020 98,389.54 409.96
5August 2020 97,852.72 407.72
6September 2020 97,315.90 405.48

After 6 months:-
The accrued profit / interest: RM2,466.45
The accumulated fund saved from the monthly payment is: 0

Which Option Is Better?

PrincipalAmount after 6 Months (RM)Comparison vs Do Nothing
Do nothing - principal amount based on normal amortization99,272100.00%
Use the accumulated fund to pay the principal by the end of moratorium 99,279100.01%
Use the monthly installment to reduce principal on monthly basis 99,246 99.97%

There is not much difference in term of principal reduction.

Option (2) Use the monthly installment to pay principal on Monthly Basis is marginally better where it can reduce principal by 0.03%

How It Is Calculated?

Use the accumulated fund to pay the principal by the end of moratorium:

RM99,279 = RM100,000 (principal) + RM2,500 (accumulated interest) – RM3,220.92 (accumulated fund during 6 months moratorium)

Use the monthly installment to reduce principal on monthly basis:

RM99,246  = RM97,315.90 (principal on month 6) – RM536.82 (assuming reduce principal before starts interest charging from month 6 installment) + RM2,466.45 (accumulated interest)

How To Pay Outstanding Purchases At Maybank Stocks Online Trading Platform

Recently, I bought shares using Maybank Stocks Online Trading Platform. After purchasing the shares, I didn’t know how to pay for my purchases.

When I googled, I coudn’t find any useful help or information on how to make payment of my outstanding purchases. At the end, I had to make a call to Maybank call centre and get help.

According to Maybank, I must contact my stocks dealer to settle the payment via Maybank2u and my stock dealer informed me step by step on how to do it.

Before follow my steps, better call your dealer first. If you don’t know or remember your dealer phone number, you can contact Maybank help line (03 2297 8888) and they will provide you the dealer name and contact.

Steps to make payment on Outstanding Purchases

  1. Login to Maybank2u
  2. Select Pay & Transfer
  3. Select New Payment
  4. Select Maybank Investment Bank Berhad
  5. Enter your trading account number in “Trading Acct. No.”
  6. Enter your “Bill Reference No.”. Fill in:-
    • TRUST  – you will be transferring your money in Maybank Investment Bank account. (your trust account will be tagged with your trading account)
maybank2u payment to maybank investment bank
maybank2u payment to maybank investment bank
  1. Inform your dealer and share the receipt.

Remember to check that your Outstanding Purchase is cleared after the payment.

 

List of Malaysian Banks Giving Loan Moratorium Due to Covid 19

Due to Covid 19, lots of Malaysian and businesses are facing financial hardships. Fortunately we have our banking sector who is pro active in giving loan moratorium.

Loan moratorium is delay in paying your loan installments. In Malaysia, banks are giving 6 months loan moratorium.

List of Malaysian Banks That Give Loan Moratorium

list of malaysian banks offers loan moratorium due to covid 19

Where To Apply Loan Moratorium

**Latest update, your loans are automatically entitled for moratorium but you can opt out.

Below are the links that I found where you can apply online for loan moratorium.

CIMB Bank

Maybank

 

 

 

Dividend Yields Comparison Between Malaysian Banks

BanksDividend Yield (%)PEROE (%)
Affin Bank3.236.315.23
Ambank6.336.138.47
BIMB4.657.846.23
CIMB8.118.736.23
Hong Leong Bank3.7610.849.64
Maybank7.2310.8010.05
Public Bank4.7710.7812.64
RHB Bank9.638.383.95
Average5.968.737.81

Analysis

  1. CIMB has the highest dividend yield but low ROE and whether the dividend yield is sustainable in the long run.
  2. Maybank has 7.23% dividend yield which is commendable with ROE of 10% but with higher than average PE.
  3. Ambank has 6.33% dividend yield with PE of 6.13 which is below average which is good and above average ROE.
  4. Public Bank has highest ROE of 12.64 means it is very efficiency in using its capital vs other banks but it has very low dividend yield.

Conclusion

Based on the numbers, without evaluating its long term business, I would buy Ambank it has 6.33% dividend and take only 6 years to recover the capital.

However on safe side, it is better to buy Maybank shares as it is innovative in digital area for example first to introduce online banking and digital payment which I think is the new disruption in banking sector.

Notes

Total dividend amount declared for financial year ended 2018-12-31

  • Bank Islam
  • Affin Bank
  • CIMB
  • RHB Bank
  • Maybank

Total dividend amount declared for financial year ended 2019-03-31.

  • Ambank

Total dividend amount declared for financial year ended 2019-06-30.

  • Hong Leong Bank

source: MalaysiaStock.biz

Kangaroo Math Categories

I sent my kids to join Kangaroo Math competition every year. Kangaroo Math questions are more problem solving rather than testing your kids Math aptitude.

I want my children to see how Math is used to solve daily and simple problems.

Kangaroo Math have 6 categories.

Pre EcolierEcolierBenjaminCadetJuniorStudent
Public:
Year 1 & 2

International
Year 1 & 2
Public:
Year 3 & 4

International:
Year 3 & 4
Public:
Year 5 & 6

International:
Year 5 & 6
Public:
Form 1 & 2

International:
Year 7 & 8
Public:
Form 3 & 4

International:
Year 9 & 10
Public:
Form 5 & 6

International:
Year 11 & 12

Good Kangaroo Sample Questions

Vista Residence Homestay Genting Highland Review – My 4 Days 3 Nights Stay

Again we went to Genting Highlands for our short relaxing vacation together with my parents. My parents for quite some time didn’t go to Genting Highlands.

This time we stayed at Vista Residence near to Petron petrol station and Starbucks.

The condo looks luxurious from outside. Even the unit itself feel luxurious. Internet YES was provided at the unit I stayed but it was quite slow. I think generally in Genting Permai, the internet it not that good.

Bedrooms

I stayed in 3 bedrooms unit with 2 queen beds and one single bed. It is suitable for guests of 4 adults and 3 kids. The bedrooms doesn’t provide night lamps so it was really dark hard to go to the toilet in the night. So I had to switch on the toilet light and opened a bit the toilet door.

The third bedroom the aircond remote was not working.

The floor is parquet so your feet are not cold due to the coolness of Genting Highlands weather.

Living Room & Veranda

The ceiling fan at the living room was a bit dusty.

It didn’t have shoes rack, so when 7 guests in the unit, the floor looked messy due to the shoes.

It had big veranda but it was a bit dirty because got few cigarettes buds drop from unit above me and the view is not that nice as it was looking towards the highway. You could hear the noise of the highway if you opened the sliding door at the veranda so at the end you can’t get the cool breeze going into the unit.

Bathrooms

For the bathroom, it is not that clean especially on the toilet bowl and the water pressure was quite low for my liking. Beside glass to put your toothbrushes were not provided.

No bidet provided some more!

Anyway the host was responsive when we wanted additional soap because the soap were a little bit only when we checked in.

I went to the gym every morning to have my light exercise. I like the gym because easy to go from the unit.

Swimming Pool

It has lap swimming pool and kids swimming pool with jacuzzi.

The swimming pool was not heated though. It was really cold. But my kids went to the swimming pool anyway.

Parking

Parking was hard to find at first because host just give the parking number. Hard to find it.

When it is raining, you will get wet just to touch the access card to open the parking barrier.

Recommendation

In short, I won’t stay again at Vista Residence due to amenities at the unit is not well thought and water pressure is low.

Besides the swimming pool is not heated.

 

Location


The Condominium

vista residence genting highland condominium
vista residence genting highland condominium
vista residence genting highland condominium
vista residence genting highland condominium
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting highland lobby
vista residence genting mailbox room
vista residence genting mailbox room
vista residence genting lift
vista residence genting lift

Entrance To Parking

vista residence genting highland parking entrance
vista residence genting highland parking entrance
vista residence genting parking
vista residence genting parking

The Facilities

vista residence genting swimming pool
vista residence genting swimming pool
vista residence genting swimming pool
vista residence genting swimming pool
vista residence genting jacuzzi
vista residence genting jacuzzi
vista residence genting sauna
vista residence genting sauna
vista residence genting gym
vista residence genting gym
vista residence genting toilet and changing room
vista residence genting toilet and changing room
vista residence toilet and changing room
vista residence toilet and changing room
vista residence genting sky deck
vista residence genting sky deck
vista residence genting sky deck
vista residence genting sky deck
vista residence koi fish pond
vista residence koi fish pond
vista residence genting barbecue area
vista residence genting barbecue area
vista residence genting playground
vista residence genting playground
vista residence genting common facilities
vista residence genting common facilities
vista residence common facilities at night
vista residence common facilities at night

The Room

vista residence corridor
vista residence corridor
vista residence genting room entrance
vista residence genting room entrance
vista residence genting living room
vista residence genting living room
vista residence master bedroom
vista residence master bedroom
vista residence kitchen
vista residence kitchen
vista residence genting wardrobe
vista residence genting wardrobe
vista residence kitchen
vista residence kitchen
vista residence genting electric kitchen hob
vista residence genting electric kitchen hob
vista residence genting oven
vista residence genting oven
vista residence genting master bathroom
vista residence genting master bathroom
vista residence genting master bathroom
vista residence genting master bathroom
vista residence genting second bathroom
vista residence genting second bathroom
vista residence no toilet bidet
vista residence no toilet bidet
vista residence parquet floor
vista residence parquet floor
vista residence genting rubbish bin
vista residence genting rubbish bin