Posts

[Easy to understand] What are Service, Service Container and Service Provider in PHP Laravel?

Imagine you are running a restaurant. Let's break down the concepts of Service, Service Container, and Service Provider using this restaurant analogy: Service: In our restaurant analogy, a service is like a specific task or job that needs to be done. For example, a "Waiter Service" would involve taking orders, serving food, and delivering the bill to the customers. Each service has a specific responsibility. Service Container: The service container is like the restaurant itself. It holds all the services (tasks) that need to be performed. Just like how a restaurant has different sections (kitchen, dining area, bar), the service container in Laravel holds different services that can be accessed when needed. When a customer (controller) needs a specific service (task), they ask the restaurant (service container) to provide it. Service Provider: The service provider is like the manager of the restaurant. They are responsible for setting up the restaurant, organizing the serv

[Easy to understand] What is Kafka Consumer, Consumer Group, Topic & Partition?

Kafka: Kafka is a distributed streaming platform that allows you to publish and subscribe to streams of records, similar to a message queue or enterprise messaging system. Consume: Consuming in Kafka means reading data from a topic. Consumers read messages from topics and process them. Consumer Group: A consumer group is a set of consumers that cooperate to consume data from Kafka brokers. Each message within a topic is delivered to one consumer instance within each subscribing consumer group. This allows you to scale processing by adding more consumers to a group. Topic: A topic is a category/feed name to which records are sent by producers. Topics in Kafka are always multi-subscriber; that is, a topic can have zero, one, or many consumers that subscribe to the data written to it. Partition: Topics in Kafka are divided into partitions. Each partition is an ordered, immutable sequence of records that are continually appended to. Each message within a partition is assigned a unique offs

[Easy to understand] Apache Kafka Listener and Advertised Listener

A plain, simple, even novice can understand explanation on what is Apache Kafka LISTENER and ADVERTISED_LISTENER. Imagine you are hosting a big party where people need to communicate with each other. In the world of Apache Kafka, the "Listener" is like the door or entrance to your party. It's where your guests (data producers and consumers) come in to interact with Kafka. Now, let's talk about the "Advertised Listener." This is like the address you give to your guests so they know how to find your party. Just like you might share your home address with friends to visit you, in Kafka, the Advertised Listener is the address that other services or clients use to connect to Kafka. In simpler terms, the Listener is where the communication happens within the Kafka system, while the Advertised Listener is the address that is shared with external services to connect to Kafka. For example, let's say your Kafka server has an internal IP address of 192.168.1.100 b

How to use aws-lambda-python docker image with example in VSCode for local development

Image
Docker image: https://hub.docker.com/r/amazon/aws-lambda-python This docker image lacks working example on how to use. If you just want to test your lambda with this image locally, please read on. Let's assume the following: Your script is called `my_python.py` The function in this file that you want to execute is called `lambda_handler` Here is the docker command (I'm using windows): docker run --rm \ -p 9000:8080 \ --mount type=bind,src=/c/projects/my_lovely_proj,target=/var/task \ amazon/aws-lambda-python \ my_python.lambda_handler Brief explanation on above: --rm : Remove the container after terminating the script (i.e. Ctrl + C in command line).  So you don't need to run `docker stop <container_id>` and `docker rm <container_id>` -p 9000:8080: map the port of local machine 9000 to container port 8080.  This is super important and will be explained later. --mount: Mount the dir to /var/task in container.  All lambda script will be executed in this /var/task

Add WordPress Admin User via Database 2024 (and onwards)

If you are trying to add a user (probably admin), not using UI but via database directly.  Here is what you did. Refer to the following article to add a user to DB https://hk.godaddy.com/en/help/create-an-admin-user-in-the-wordpress-database-27023 (Recommended) https://help.one.com/hc/en-us/articles/17467509114385-How-to-add-an-Admin-User-to-the-WordPress-database https://wpengine.com/support/add-admin-user-phpmyadmin/ They are all talking about same steps, so just pick one and follow.  In case if you don't understand first article, read the next one and so on. Remember, if you are updating existing DB to use new prefix, you need to manually (or via SQL) update all table name to use your prefix. For example, if original prefix is 'wp_', and you want to change it to "my_lovely_", you need to update all table names, like "wp_posts" > "my_lovely_posts". Here is the missing steps:  Thanks to my colleagues, you also need to update {prefix}_optio

Nginx HTTP2 directive old vs new test result

 The nginx "http2" directive appended after "listen" is deprecated since 1.25.1. Let's see if Nginx will start under old and new version if we put this directive incorrectly Nginx after v1.25.1 server {     listen 80 http2;  # Work, but will issue deprecated warning during start     http2 on; ... } Nginx before v1.25.1 server {     listen 80 http2;       http2 on; # Not work, issue error: unknown directive http2 ... } Conclusion: - Appending http2 in Nginx latest version is OK, even if the the correct directive is `http2 on;` - Do not use standalone `http2 on;` on unsupported Nginx version, it will fail to start. Hope it helps someone.

艾勒里日本大阪,京都,奈良遊記 - 202310

這是想花一點點時間記錄下這次日本之行的想法. 這個標題與我在FB的相簿相同,我就不相信會有人用我FB相簿的標題搜尋這篇文章,我想肆無忌憚地想說什麼就什麼。 先說一些我來之前的想法: 這次會來日本全是巧合。 是因為公司年度晚會被抽到去日本大阪,才會有機會去的。 其實我當下想,是不是能賣出去? 但是,想我做了40多年人以來,好像還沒有機會自己一個人去這麼遠的地方,就想試試。 失敗了也無妨,而且到執筆之時,還不算什麼失敗的。 而且,我妹也能自由行了,做哥哥的怎麼也不能落後。連我妹也做到的事,做哥哥的都做不了那很蠢。 所以再三想過後,還是決定去。因為我覺得,或者有機會在想法上和思考上突破。 雖然很老土,但我還是相信,「讀萬卷書,行萬里路」這句話。 但我仍不想去 旅行規劃: 我在3月左右抽到,但從5月規劃到10月出發前夕,我只有一個念頭: 「好X煩」 沒錯,從一開始規劃路線,到參考不同的Youtube影片,到看Google Map到火滾,都覺得好煩。 主要原因是:日本的鐵路路線「太複雜」。 但後來我想想,為什麼會覺得複雜,那是因為我一開始就想把握整個日本鐵路圖。 因為想要消化/吸收和了解的資料太多,腦袋轉不過來,才會覺得超麻煩。 但反過來想,用以往的方法:倒過來規劃,並只思考特定路線,排除所有與此路線無關的資料,那會簡單得多。 這是經過大概2-3個月在資料/影片堆中挣扎得出的結論。 感悟:試試從目標著手,反過來思考就好。以前我用此方法在IT行業處理過很多問題,在旅行上也可以。 但我仍然不想去。所以只能提醒自己,這是賺取經驗值,不會讓人家看不起的經驗。 我契妹說去旅行是放鬆的,如果讓自己很緊張那不如不去。 但若要放鬆,那為什麼要花錢去旅行,我不喜歡享受,放鬆的話我更喜歡宅在家。或者不花錢去看看某些地方也可以。 我一直覺得,為了放鬆而去花錢旅行不會是我喜歡/想做的事。 當然,若是為了擴闊眼界,倒沒所謂。 但我,沒旅行這個興趣。 這裏要多謝我的好契妹。 酒店和大概的行程是她提供,我再選擇的。 這次她幫了我不少。她也知道我不想去。但仍很支持我。所以想在這裏多謝她這位超級聰明無敵美麗可愛的好契妹。 嗯,也是別人家的老婆,和3位孩子的媽媽 10月中,出發

Cannot connect to MySQL from PHP(Permission Denied), even if commandline or other programs works

If your PHP code (e.g. adminer) cannot connect to your MySQL database (Error: Permission Denied), yet you can connect successfully via other program, like HeidiSQL or even command line, this is for you. Reference:  https://serverfault.com/a/667930/253676 It said even if you have SELinux disabled, Apache server still cannot connect to MySQL Noted what I wrote: Apache cannot connect to MySQL So you need to run (either one, not both): Permanent: `setsebool -P httpd_can_network_connect_db on` Temporary: `setsebool httpd_can_network_connect_db=1` Then you tried again, you should be fine.