PHP7 Callable Examples

A callable as class property

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
class Processor
{
private $postHook;

public function __construct(callable $postHook)
{
$this->postHook = $postHook;
}

public function process()
{
// some statements here
($this->postHook)($param1, $param2, $param3);
}
}

class Client
{
public function main()
{
$processor = new Processor($this->postProcess());
$processor->process();
}

private function postProcess()
{
return function ($arg1, $arg2, $arg3) {
// some statements
};
}
}

Read More

Setup postgres in Ubuntu server

To install PostgreSQL in Ubuntu (tested in 20.04)

1
2
3
4
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt update
apt -y install postgresql

Read More

Shell script - remove lines contain some words

A sample file demo.txt contains the following content

1
2
3
4
5
6
7
8
9
10
1 Linux Operating System
2 Unix Operating System
3 RHEL
4 Red Hat
5 Fedora
6 Arch Linux
7 CentOS
8 Debian
9 Ubuntu
10 openSUSE

Read More

Enable AWS SES in Laravel web app

I believe most of AWS users will use Amazon Simple Email Service (SES)
for system email sending.

Before you can use in production, by default it’s in sandbox mode, which
you are required to pre-configure a few email addresses to receive email.

Read More

AWS EC2 instance used up CPU 100% - Malware kdevtmpfsi

I was wondering what’s wrong with my server (host Laravel web app),
it’s fine after reboot the instance, but after a while it become very
slow, and CPU 100%

Read More

Real world practice on Docker in Laravel web app

I heard about Docker few years ago, but wasn’t know about best practice how to use that.
I’ve tried Laradock, it’s way too many stuff in the config, should I use 1 docker for multiple
projects? Or better single project?

Read More

Laravel Unit Test Mail Send

Case 1: Mail send without Mailable class

Sometime we don’t use mailable class, instead we want to send directly with send method.

Read More

Thinkpad - Set battery charging threshold in Linux

With kernel 4.17 above, we can set the threshold directly

1
2
$ echo 85 > /sys/class/power_supply/BAT0/charge_start_threshold
$ echo 95 > /sys/class/power_supply/BAT0/charge_stop_threshold

Read More

Activate Windows 10 in VirtualBox

I’m using Windows 10 in VirtualBox for testing purpose, where my main OS is formatted to Ubuntu.

I noticed I can activate the Windows 10 with the key sealed in hardware,
get the key with the follwing command

Read More

Web development testing in Android Virtual Device

Some time, we will need to test web development in mobile devices.
Previously, I used to test in iOS simulator, the virtual host will just work.

Read More